Makefile顺序执行

标签 makefile gnu

我有以下 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

目标datels分别生成一个文件,目标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/

相关文章:

c++ - 将 Makefile 项目转换为 Cmake

postgresql - 在 OpenSuse 13.2 上为 PostgreSQL 9.4.1 构建 PL/Java

c++ - put_time() 忽略时区偏移量的转换说明符 'z'

c++ - Mac OS X Lion 上的 GNU GCC 4.6(.1) 编译器

c++ - 在 C 或 C++ 中使用 GNU 正则表达式函数

c++ - 不处于 Debug模式时正常启动测试

makefile - GNU make 相当于 BSD make 的 $(var :Q)?

c - 使 : "The system cannot find the path specified" only when compiling with makefile?

c++ - 代码编译,但没有控制台输出

c++ - malloc_info() 是如何工作的?