Makefile实例

来源:互联网 发布:lightroom mac版下载 编辑:程序博客网 时间:2024/05/22 01:39
cat Makefile # Automatically generated by /home/exapp/zengzhihao/amlogic/buildroot-openlinux-20170814/buildroot/support/scripts/mkmakefile: don't edit#lastword既可作为变量也可作为函数,作为变量调用时需要传入1="xxx yyy"lastword = $(word $(words $(1)),$(1))#$(call fun,$(pa1))  调用fun函数传入pa1参数及调用lastword函数,返回$(words Makefile out/Makefile)      $(word 2, Makefile out/Makefile)#返回out/Makefile#makedir := outmakedir := $(dir $(call lastword,$(MAKEFILE_LIST)))MAKEARGS := -C /home/exapp/zengzhihao/amlogic/buildroot-openlinux-20170814/buildroot#$(if $(patsubst /%,,$(makedir)),$(CURDIR)/)没有符合/%返回原值,则不为空返回$(CURDIR)/MAKEARGS += O=$(if $(patsubst /%,,$(makedir)),$(CURDIR)/)$(patsubst %/,%,$(makedir))#--no-print-directory是:不要再屏幕上打印"Entering directory.."MAKEFLAGS += --no-print-directory.PHONY: _all $(MAKECMDGOALS)#MAKECMDGOALS命令行参数出执行命令make外带入的其它参数如make  are you则MAKECMDGOALS=(are you)all:= $(filter-out Makefile,$(MAKECMDGOALS))#Makefile output/mesongxl_p241_kernel49//Makefile_all:echo $(call lastword,$(MAKEFILE_LIST))echo $(CURDIR)echo $(makedir)echo $(patsubst /%,,$(makedir))echo $(if $(patsubst /%,,$(makedir)),$(CURDIR)/)umask 0022 && $(MAKE) $(MAKEARGS) $(all)Makefile:;#@关闭会显#@ echo 33不会显示echo 33#@: echo ad>good.ccc区别@ echo ad>good.ccc#@:关闭回显以及输出,@仅仅关闭回显$(all): _all@:%/: _all@:
如果编写一个规则,并不产生目标文件,则其命令在每次make 该目标时都执行。例如:
  clean:
  rm *.o temp
因为"rm"命令并不产生"clean"文件,则每次执行"makeclean"的时候,该命令都会执行。如果目录中出现了"clean"文件,则规则失效了:没有依赖文件,文件"clean"始终是最新的,命令永远不会执行;为避免这个问题,可使用".PHONY"指明该目标。如:
  .PHONY : clean
  这样执行"make clean"会无视"clean"文件存在与否。
原创粉丝点击