加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ExampleMakefile 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
havesnag 提交于 2015-06-29 20:04 . 示例makefile文件
CC = gcc
CXX = g++
#
COMPILE_DEF = -g -Wall -std=c++11 -fPIC
CXXFLAGS = $(if $(COMPILE_OPT), $(COMPILE_OPT), $(COMPILE_DEF)) -I./include
LIBS = -levent -levent_pthreads
#
MKDIR = mkdir
#
TARGET = test
DIR_OBJ = obj
#
DIR_SRC = . src example
Suffix = c cc cpp
#
SRCS = $(foreach d, $(DIR_SRC), $(foreach s, $(Suffix), $(wildcard $(d)/*.$(s))))
OBJS = $(foreach s, $(SRCS), $(DIR_OBJ)/$(basename $(s)).o)
DEPS = $(foreach s, $(SRCS), $(DIR_OBJ)/$(basename $(s)).d)
all:$(DIR_OBJ) $(TARGET)
$(DIR_OBJ):
$(MKDIR) -p $(addprefix $(DIR_OBJ)/,$(DIR_SRC))
-include $(DEPS)
$(DIR_OBJ)/%.d:%.*
@$(MKDIR) -p $(dir $@);
@-rm -f $@;
@if [ $(suffix $<) = .c ]; then TEMP_CXX=$(CC); else TEMP_CXX=$(CXX); fi; \
echo "$$TEMP_CXX -MM $(CXXFLAGS) $< > $@"; $$TEMP_CXX -MM $(CXXFLAGS) $< > $@;
@sed -i 's,\($(basename $(notdir $@))\.o\),$(dir $@)\1 ,g' $@
$(DIR_OBJ)/%.o: %.*
@if [ $(suffix $<) = .c ]; then TEMP_CXX=$(CC); else TEMP_CXX=$(CXX); fi; \
echo "$$TEMP_CXX -c $(CXXFLAGS) $< -o $@"; $$TEMP_CXX -c $(CXXFLAGS) $< -o $@;
$(TARGET):$(OBJS)
$(CXX) -o $@ $(CXXFLAGS) $^ $(LIBS)
clean:
-rm -rf $(OBJS) $(TARGET) $(DIR_OBJ)
distclean:
-rm -f $(DEPS)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化