我有以下 Makefile:
all: generate print # <-- doesn't work
date:
date > date.txt
ls:
ls -la > ls.txt
generate: ls date
print: *.txt
cat $^
clean:
rm *.txt
目标date和ls分别生成一个文件,目标print将它们打印出来。
如何编写目标全部,以便它首先生成文件,然后然后打印它?
最佳答案
只需添加管道符号:
all: | generate print
来自make manual :
Order-only prerequisites can be specified by placing a pipe symbol (
|
) in the prerequisites list: any prerequisites to the left of the pipe symbol are normal; any prerequisites to the right are order-only:targets : normal-prerequisites | order-only-prerequisites
关于Makefile顺序执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22630996/