Makefile
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Makefile相关的知识,希望对你有一定的参考价值。
外层目录下makefile
1 SUB_DIR = 2 INSTALL_SUB_DIR = $(addsuffix .install, $(SUB_DIR)) 3 CLEAN_SUB_DIR = $(addsuffix .clean, $(SUB_DIR)) 4 5 .PHONY: $(SUB_DIR) $(INSTALL_SUB_DIR) $(CLEAN_SUB_DIR) 6 7 all:$(SUB_DIR) 8 9 $(SUB_DIR): 10 @make -[email protected] 11 12 install: $(INSTALL_SUB_DIR) 13 14 $(INSTALL_SUB_DIR):$(SUB_DIR) 15 @cd $(basename [email protected]) ; $(MAKE) install 16 17 clean: $(CLEAN_SUB_DIR) 18 19 $(CLEAN_SUB_DIR): 20 @cd $(basename [email protected]) ; $(MAKE) clean
里层目录下makefile
1 INCLUDE_DIR = include 2 SRC_DIR = src 3 BIN_DIR = bin 4 BUILD_DIR = build 5 6 vpath %.c src 7 vpath %.h include 8 vpath %.o build 9 10 CC = gcc 11 CFLAGS = -g -Wall -fmessage-length=0 12 INCLUDE += -I$(INCLUDE_DIR) 13 LIBS += -l -L 14 15 OBJS += 16 TARGET += 17 18 .PHONY:clean 19 20 all: $(TARGET) 21 22 $(TARGET):$(OBJS) 23 $(CC) -o $(BIN_DIR)/$(TARGET) $(CFLAGS) $(addprefix $(BUILD_DIR)/,$(OBJS)) $(INCLUDE) $(LIBS) 24 25 $(OBJS):%.o:%.c 26 $(CC) -c $(CFLAGS) $(INCLUDE) $< -o $(BUILD_DIR)/[email protected] 27 28 #install拷贝二进制文件并修改权限,cp拷贝普通文件 29 install: 30 @install $(BIN_DIR)/$(TARGET) / 31 @cp $(BIN_DIR)/*.cfg / 32 33 clean: 34 rm -rf $(BUILD_DIR)/* $(BIN_DIR)/$(TARGET)
以上是关于Makefile的主要内容,如果未能解决你的问题,请参考以下文章
使用带有 NMake 样式 Makefile 的 clang-cl 无法回显