ILD

Makefile internal流程的两个例子
作者:Yuan Jianpeng 邮箱:yuanjp89@163.com
发布时间:2021-3-22 站点:Inside Linux Development


看第一个Makefile:

1
2
3
4
5
6
7
8
9
10
11
12
$ cat Makefile
define a
all:
        ifeq (1,1)
        echo emm
endif
endef
 
$(eval $(a))
 
$ make
Makefile:8: *** extraneous 'endif'.  Stop.


可以看到ifeq(1,1)被当成rule了,Makefile没有做任何的处理。导致多余的endif。注意Make对所有的TAB开头的行都当做rule处理。不会当成Makefile的语法Parse。但是define内部的被当成define的内容。注意:endef也不能以TAB开头。否则提示:

Makefile:1: *** missing 'endef', unterminated 'define'.  Stop.



第二个Makefile:

1
2
3
4
5
6
7
8
9
$ cat Makefile
 
all: a b;
 
a:
        echo a > b
 
$ make
echo a > b


执行Make的时候,b文件不存在,但是没有报错,因为执行a目标产生了b文件。所以

    make: *** No rule to make target 'b', needed by 'all'.  Stop.

做这种检查的时机是很晚的,其它target会被得到执行。




Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.