首页 > 代码库 > Makefile

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 -C$@
11 
12 install: $(INSTALL_SUB_DIR)
13 
14 $(INSTALL_SUB_DIR):$(SUB_DIR)
15     @cd $(basename $@) ; $(MAKE) install
16 
17 clean: $(CLEAN_SUB_DIR)
18 
19 $(CLEAN_SUB_DIR):
20     @cd $(basename $@) ; $(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)/$@
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