ITPub博客

首页 > Linux操作系统 > Linux操作系统 > makefile 多目录 C 配置

makefile 多目录 C 配置

原创 Linux操作系统 作者:ForTechnology 时间:2012-10-30 09:34:26 0 删除 编辑
目录机构
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/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Vim 寄存器
请登录后发表评论 登录
全部评论

注册时间:2011-07-21

  • 博文量
    220
  • 访问量
    705410