Skip to content

Commit

Permalink
update Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt committed Nov 9, 2024
1 parent 368d529 commit 46539fc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.10)
project(rime-deploy C)

# 设置 C 标准
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

# 添加源文件
file(GLOB SOURCES "src/*.c")

# 创建可执行文件
add_executable(rime-deploy ${SOURCES})

# 添加头文件目录
target_include_directories(rime-deploy PRIVATE src)

# 设置输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

# 根据平台添加特定的链接库
if(WIN32)
target_link_libraries(rime-deploy PRIVATE ws2_32)
elseif(UNIX)
target_link_libraries(rime-deploy PRIVATE m)
endif()
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,23 @@ OBJS := $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
TARGET := rime-deploy$(EXE_EXT)

# 默认目标
.PHONY: all clean
.PHONY: all clean dirs

all: dirs $(TARGET)
all: $(TARGET)

dirs:
@$(MKDIR) $(BUILD_DIR)
@$(MKDIR) $(OBJ_DIR)
@$(MKDIR) $(BIN_DIR)
# 创建目录(使用 -p 并忽略错误)
$(BUILD_DIR) $(OBJ_DIR) $(BIN_DIR):
-$(MKDIR) "$@"

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
# 编译规则
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@

# 链接规则
$(TARGET): $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) -o $@

# 清理规则
clean:
$(RM) $(BUILD_DIR)
$(RM) $(TARGET)

0 comments on commit 46539fc

Please sign in to comment.