Commit 64268e11 authored by xiezhi's avatar xiezhi

fix makefile

parent e5bd1ad2
...@@ -49,11 +49,7 @@ run: install ...@@ -49,11 +49,7 @@ run: install
# 停止命令 # 停止命令
.PHONY: stop .PHONY: stop
stop: kill stop:
# 强制杀死所有相关C进程
.PHONY: kill
kill:
@echo "正在查找并杀死所有相关的C进程..." @echo "正在查找并杀死所有相关的C进程..."
@PIDS=$$(ps aux | grep -E "hello_world|$(APP_NAME)" | grep -v grep | awk '{print $$2}'); \ @PIDS=$$(ps aux | grep -E "hello_world|$(APP_NAME)" | grep -v grep | awk '{print $$2}'); \
if [ -n "$$PIDS" ]; then \ if [ -n "$$PIDS" ]; then \
...@@ -68,75 +64,4 @@ kill: ...@@ -68,75 +64,4 @@ kill:
echo "未找到相关的C进程"; \ echo "未找到相关的C进程"; \
fi fi
@rm -f $(PID_FILE) @rm -f $(PID_FILE)
@echo "✅ 强制停止操作完成" @echo "✅ 停止操作完成"
# 重启命令
.PHONY: restart
restart: stop run
# 查看状态
.PHONY: status
status:
@if [ -f "$(PID_FILE)" ]; then \
PID=$$(cat $(PID_FILE)); \
if ps -p $$PID > /dev/null 2>&1; then \
echo "✅ 服务器正在运行,PID: $$PID"; \
echo "端口: $(APP_PORT)"; \
echo "日志: $(LOG_FILE)"; \
else \
echo "❌ 服务器未运行(PID文件存在但进程不存在)"; \
rm -f $(PID_FILE); \
fi; \
else \
echo "❌ 服务器未运行"; \
fi
# 开发模式运行
.PHONY: dev
dev:
@echo "开发模式运行C程序..."
@APP_PORT_1=$(APP_PORT) $(BINARY_FILE)
# 调试模式编译
.PHONY: debug
debug:
@echo "调试模式编译C程序..."
@mkdir -p $(BUILD_DIR)
@$(CC) $(CFLAGS) -g -DDEBUG -o $(BINARY_FILE) hello_world.c $(LDFLAGS)
@echo "✅ 调试版本编译完成"
# 清理编译文件
.PHONY: clean
clean:
@echo "清理编译文件..."
rm -rf $(BUILD_DIR)
@echo "清理完成!"
# 显示帮助信息
.PHONY: help
help:
@echo "C 12.2.0 HTTP 服务器项目"
@echo ""
@echo "可用命令:"
@echo " make install - 安装依赖并编译项目"
@echo " make run - 启动HTTP服务器(后台运行)"
@echo " make stop - 停止HTTP服务器(优雅停止)"
@echo " make kill - 强制杀死所有相关C进程"
@echo " make restart - 重启HTTP服务器"
@echo " make status - 查看服务器状态"
@echo " make dev - 开发模式运行"
@echo " make debug - 调试模式编译"
@echo " make clean - 清理编译文件"
@echo " make help - 显示此帮助信息"
@echo ""
@echo "示例:"
@echo " make run # 启动服务器"
@echo " make status # 查看状态"
@echo " make stop # 优雅停止服务器"
@echo " make kill # 强制停止所有相关进程"
@echo " make restart # 重启服务器"
@echo " make dev # 开发模式运行"
@echo " make debug # 编译调试版本"
@echo ""
@echo "环境变量:"
@echo " APP_PORT_1 - 服务器端口(默认: 8000)"
...@@ -52,26 +52,8 @@ make install ...@@ -52,26 +52,8 @@ make install
# 启动服务器(后台运行) # 启动服务器(后台运行)
make run make run
# 开发模式运行
make dev
# 调试模式编译
make debug
# 查看服务器状态
make status
# 停止服务器 # 停止服务器
make stop make stop
# 重启服务器
make restart
# 清理编译文件
make clean
# 查看帮助
make help
``` ```
### 3. 直接使用 GCC 命令 ### 3. 直接使用 GCC 命令
...@@ -167,11 +149,8 @@ if (env_port != NULL) { ...@@ -167,11 +149,8 @@ if (env_port != NULL) {
### 查看日志 ### 查看日志
```bash ```bash
# 使用 Makefile 查看日志 # 查看日志
tail -f .logs/app.log tail -f .logs/app.log
# 查看服务器状态
make status
``` ```
### 健康检查 ### 健康检查
...@@ -219,8 +198,8 @@ make stop ...@@ -219,8 +198,8 @@ make stop
2. **编译错误** 2. **编译错误**
```bash ```bash
# 清理并重新编译 # 重新编译
make clean rm -rf build
make install make install
``` ```
...@@ -234,13 +213,10 @@ docker build --no-cache -t test . ...@@ -234,13 +213,10 @@ docker build --no-cache -t test .
```bash ```bash
# 调试模式编译 # 调试模式编译
make debug gcc -Wall -Wextra -std=c11 -g -DDEBUG -o build/hello_world hello_world.c -pthread
# 开发模式运行(显示详细日志)
make dev
# 直接运行 C 程序 # 直接运行 C 程序
./hello_world ./build/hello_world
``` ```
## 📝 API 文档 ## 📝 API 文档
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment