Make

2021-09-18  本文已影响0人  wjundong

make 目标

顶层 Makefile 作为入口, 来调用其他 makefile, 顶层 makefile 一般有很多选项, 这些选项是直接定义在顶层 makefile 的目标, 比如

Makefile

build:
    @echo 'This is build'

help:
    @echo  'This is help'

clean:
    @echo 'This is clean'

执行:

$ make
This is build
$ make help
This is help
$ make clean
This is clean

通过shell调用其他 makefile 的目标

Makefile

help:
    @echo  'This is help from makefile1'
    @$(MAKE) -f ./Makefile2

Makefile2

help:
    @echo  'This is help from makefile2'

执行:

$ make help
This is help from makefile1
This is help from makefile2

定义哪些目标为伪目标 PHONY

对于刚才的例子, 如果在顶层目录下创建 helo 空文件, 执行:

$ make help
make: “help”已是最新

help 目标下的指令根本没有执行, 因为make 把help 当成一个正常的目标文件, 当文件路径下有该文件且比其依赖更新, 则不会执行任何生成操作。

对于那些不需要生成目标文件的目标,可使用PHONY来标明该目标是伪目标:

.PHONY: help

help:
    @echo  'This is help from makefile1'
上一篇下一篇

猜你喜欢

热点阅读