目录机构
project/
---head 头文件
---srcs c文件 (支持多层目录)
---bin obj
---makefile
---exe 执行文件
1 srcs=$(shell find ./ -name "*.c"|sed 's/\S\+\///g')
2 paths=$(shell find ./ -name "*.c")
3 dirs=$(shell find ./srcs-type d)
4 bjs=$(patsubst %.c,$(bin)/%.o,$(srcs))
5 head=./head
6 target=all
7 bin=./mybin
8
9 define tmp
10 $(bin)/$(1):$(2)
11 cc -c -g $(2) -o $(bin)/$(1) -I $(head)
12 endef
13
14 all:$(objs)
15 cc $(objs) -o $(target)
16 $(foreach path,$(paths),$(eval $(call tmp,$(patsubst %.c,%.o,$(notdir $(path ))) ,$(path))))
17
18 .PHONY:clean print
19 clean:
20 rm $(bin)/*.o;
21 rm $(target)
22 print:
23 @echo $(objs)
24 @echo $(paths)
25 @echo $(out)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25897606/viewspace-747872/
,如需转载,请注明出处,否则将追究法律责任。