标签:makefile
【版权声明:转载请保留出处:blog.csdn.net/gentleliu。Mail:shallnew at 163 dot com】SRC_FILES = $(wildcard src/*.c)返回src目录下所有.c文件列表。
SRC_OBJ = $(patsubst %.c, %.o, $(SRC_FILES))将SRC_FILES中所有.c文件替换为.o返回给变量SRC_OBJ。
$(objects:.c=.o) $(patsubst %.c,%.o,$( src_files))4. 过滤函数—filter。
# make make[1]: Entering directory `/home/Myprojects/example_make/version-3.1/src/ipc' make[1]: Leaving directory `/home/Myprojects/example_make/version-3.1/src/ipc' make[1]: Entering directory `/home/Myprojects/example_make/version-3.1/src/tools' make[1]: Leaving directory `/home/Myprojects/example_make/version-3.1/src/tools' make[1]: Entering directory `/home/Myprojects/example_make/version-3.1/src/main' make[1]: Leaving directory `/home/Myprojects/example_make/version-3.1/src/main' #发现只有进入目录和退出目录的显示,这样很难知道目前编译过程。其实我们可以在规则命令处加入一行类似打印:
$(OBJDIR) : >---@echo " MKDIR $(notdir $@)..." >---@mkdir -p $@ ifneq ($(SRC_BIN),) $(BINDIR)/$(SRC_BIN) : $(SRC_OBJ) >---@echo " LINK $(notdir $@)..." >---@$(CC) -o $@ $^ $(LDFLAGS) endif ifneq ($(SRC_LIB),) $(LIBDIR)/$(SRC_LIB) : $(SRC_OBJ) >---@echo " ARCHIVE $(notdir $@)..." >---@$(AR) rcs $@ $^ >---@echo " COPY $@ to $(SRC_BASE)/libs" >---@cp $@ $(SRC_BASE)/libs endif $(SRC_OBJ) : $(OBJDIR)/%.o : %.c >---@echo " COMPILE $(notdir $<)..." >---@$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
# make make[1]: Entering directory `/home/Myprojects/example_make/version-3.1/src/ipc' COMPILE ipc.c... ARCHIVE libipc.a... COPY ../../build/unix_dbg/lib/libipc.a to ../../libs make[1]: Leaving directory `/home/Myprojects/example_make/version-3.1/src/ipc' make[1]: Entering directory `/home/Myprojects/example_make/version-3.1/src/tools' COMPILE base64.c... COMPILE md5.c... COMPILE tools.c... ARCHIVE libtools.a... COPY ../../build/unix_dbg/lib/libtools.a to ../../libs make[1]: Leaving directory `/home/Myprojects/example_make/version-3.1/src/tools' make[1]: Entering directory `/home/Myprojects/example_make/version-3.1/src/main' COMPILE main.c... LINK target_bin... make[1]: Leaving directory `/home/Myprojects/example_make/version-3.1/src/main' #
$(BUILDDIR): >---@echo " Create directory $@ ..." >---mkdir -p $(BUILDDIR)/bin $(BUILDDIR)/lib $(MODULES): >---@$(MAKE) -C $(DIR)/$@ MODULE=$@ --no-print-directory main:tools ipc clean : >---@for subdir in $(MODULES); >---do $(MAKE) -C $(DIR)/$$subdir MODULE=$$subdir $@ --no-print-directory; >---done 编译输出: # make COMPILE ipc.c... ARCHIVE libipc.a... COPY ../../build/unix_dbg/lib/libipc.a to ../../libs COMPILE base64.c... COMPILE md5.c... COMPILE tools.c... ARCHIVE libtools.a... COPY ../../build/unix_dbg/lib/libtools.a to ../../libs COMPILE main.c... LINK target_bin... # make clean rm -f ../../build/unix_dbg/obj/ipc/ipc.o ../../build/unix_dbg/lib/libipc.a rm -f ../../build/unix_dbg/obj/main/main.o ../../build/unix_dbg/bin/target_bin rm -f ../../build/unix_dbg/obj/tools/base64.o ../../build/unix_dbg/obj/tools/md5.o ../../build/unix_dbg/obj/tools/tools.o ../../build/unix_dbg/lib/libtools.a #
这样看上去输出清爽多了。其实我们也可以使用make -s 来全面禁止命令的显示。
从头开始写项目Makefile(十):make内嵌函数及make命令显示,布布扣,bubuko.com
从头开始写项目Makefile(十):make内嵌函数及make命令显示
标签:makefile
原文地址:http://blog.csdn.net/shallnet/article/details/38314473