【发布时间】:2015-12-20 22:24:05
【问题描述】:
我有以下 Makefile:
a.d:
gcc -m32 -MM -o $@ a.c
sed 's!a.o!$@ a.o!' --in-place $@
a.o:
gcc -c -m32 -o $@ a.c
all: a.d a.o
-include a.d
a.d的内容是:
a.d a.o: a.c a.h
我有两个问题。 1、运行“make all”后如果我运行:
touch a.h
make a.d
我看到了:
gcc -m32 -MM -o a.d a.c
sed 's!a.o!a.d a.o!' --in-place a.d
make: 'a.d' is up to date.
a.d 规则明显运行,为什么我看到“make: 'a.d' is up to date.”?
2,在我运行“make all”之后:
touch a.h
make a.o
我看到了:
gcc -m32 -MM -o a.d a.c
sed 's!a.o!a.d a.o!' --in-place a.d
gcc -c -m32 -o a.o a.c
为什么它还运行广告规则?没有任何依赖关系。
我真正不明白的是当我将“-include a.d”替换为make文件中a.d的内容时,例如:
#-include a.d
a.d a.o: a.c a.h
我没有看到任何问题。 include 语句不应该使包含文件直接包含在同一个 make 文件中吗?
这就是我的 a.h 的样子:
#define FOO 0
这是交流电:
#include <stdio.h>
#include "a.h"
void foo(void)
{
printf("foo %d", FOO);
}
我使用的是 Cygwin 64 位。这是 make -v 的输出:
$ make -v
GNU Make 4.1
Built for x86_64-unknown-cygwin
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
【问题讨论】:
-
FWIW,当我在 GNU Make 3.81 下运行时,都没有出现问题。
-
@Beta 我刚刚还在 VM 中的 32 位 Ubuntu 中进行了测试,但我仍然看到了问题,GNU Make 3.81。您确定将 -include ... 语句留在了 make 文件中吗?
-
@Beta 我在其中一个编辑中打错了字。我纠正了它。你现在就会看到问题了。
标签: include makefile dependencies gnu-make