2023-03-22 02:46:14 +00:00
|
|
|
# 定义源文件列表
|
|
|
|
SOURCES := $(wildcard *.c) $(wildcard *.cpp) $(wildcard CCAnr/*.cpp)
|
2023-02-11 21:52:59 +08:00
|
|
|
|
2023-03-22 02:46:14 +00:00
|
|
|
# 将源文件列表转换为目标文件列表
|
|
|
|
OBJECTS := $(addprefix build/,$(SOURCES:%=%.o))
|
|
|
|
|
|
|
|
# 声明编译器和编译选项
|
|
|
|
CC := gcc
|
|
|
|
CXX := g++
|
|
|
|
CFLAGS := -O3 -g -Wall -Wextra -MMD -MP -flto
|
|
|
|
CXXFLAGS := -O3 -g -Wall -Wextra -MMD -MP -flto
|
|
|
|
|
|
|
|
# 默认目标,编译所有目标文件
|
|
|
|
atpg: $(OBJECTS)
|
|
|
|
$(CXX) $(CXXFLAGS) $^ -o $@
|
|
|
|
|
|
|
|
# 生成目标文件的规则
|
|
|
|
build/%.o: % | build
|
|
|
|
$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
|
|
|
|
build/%.o: %.cpp | build
|
|
|
|
$(CXX) $(CXXFLAGS) -c $< -o $@
|
|
|
|
|
|
|
|
# 包含依赖文件
|
|
|
|
-include $(OBJECTS:.o=.d)
|
|
|
|
|
|
|
|
# 如果需要,则递归创建源文件的目录结构
|
|
|
|
build:
|
|
|
|
mkdir -p $(sort $(dir $(OBJECTS)))
|
|
|
|
|
|
|
|
# 清除所有目标文件和build目录
|
|
|
|
clean:
|
|
|
|
rm -rf build $(OBJECTS)
|
|
|
|
|
|
|
|
.PHONY: clean all
|