Makefile 如何让make交错包含文件并按照文件中指定的顺序重建包含的文件?

Makefile 如何让make交错包含文件并按照文件中指定的顺序重建包含的文件?,makefile,gnu-make,Makefile,Gnu Make,我有以下Makefilefoo: all: output bar: echo 'ALL = there' > "$@" -include bar MORE := $(ALL) baz: foo bar echo MORE=$(MORE) echo 'SOME = there' > "$@" -include baz output: baz echo SOME=$(SOME) 当我运行rm-f bar baz

我有以下Makefile
foo

all: output

bar:
        echo 'ALL = there' > "$@"

-include bar

MORE := $(ALL)

baz: foo bar
        echo MORE=$(MORE)
        echo 'SOME = there' > "$@"

-include baz

output: baz
        echo SOME=$(SOME)
当我运行
rm-f bar baz时;make-f foo
,我明白了

echo 'ALL = there' > "bar"
echo MORE=
MORE=
echo 'SOME = there' > "baz"
echo SOME=there
SOME=there
我希望得到

echo 'ALL = there' > "bar"
echo MORE=there
MORE=there
echo 'SOME = there' > "baz"
echo SOME=there
SOME=there
我该如何解决这个问题?也就是说,在执行生成
baz
的目标时,如何使其在重新生成后包含
bar

运行
make-v

GNU Make 4.0
Built for x86_64-pc-cygwin
Copyright (C) 1988-2013 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.
GNU Make 4.0
专为x86_64-pc-cygwin构建
版权所有(C)1988年至2013年自由软件基金会。
许可证GPLv3+:GNU GPL版本3或更高版本
这是自由软件:您可以自由更改和重新发布它。
在法律允许的范围内,不存在任何担保。
将“-include baz”放在条内:

bar:
    @echo making $@
    @echo 'ALL = there' > "$@"
    @echo "-include baz" >> $@

Make总是读取整个makefile,然后尝试构建它找到的所有makefile,然后(如果有)重新启动。但是,它将递归地执行此操作,直到没有生成文件被重建为止。您不能更改此算法。请参阅@Beta的答案:这样做是正确的(除非您想使用递归生成文件)。