GNU制作通配符扩展的目标和先决条件顺序的显式列表 [英] GNU Make wildcard-expanded explicit lists of targets and prerequisites order

查看:88
本文介绍了GNU制作通配符扩展的目标和先决条件顺序的显式列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的任务.

有两个目录- in out .

初始状态

$ tree .
.
├── in
│   ├── 1
│   ├── 2
│   └── 3
├── Makefile
└── out
    ├── 1
    ├── 2
    └── 3

其中1、2、3是空文件.

where 1, 2, 3 are empty files.

现在

$ touch in/*

目标是在目录 in 中打印文件名,该文件名比目录 out 中的对应文件新,例如: in/2 -> 出/2 .

Goal is to print file name in directory in that is newer than corresponded file in directory out, for ex.: in/2 -> out/2.

Makefile是

out/* : in/*
    @ echo $?

运行

$ make -rd

...
 Prerequisite 'in/3' is newer than target 'out/3'.
 Prerequisite 'in/2' is newer than target 'out/3'.
 Prerequisite 'in/1' is newer than target 'out/3'.
...

订单未保留.

有人可以修复它吗?

推荐答案

您的makefile不能满足您的期望.它将扩展为:

Your makefile doesn't do what you're hoping. It will expand to:

out/1 out/2 out/3 : in/1 in/2 in/3
        @ echo $?

这与说每个in文件是其特定out文件的先决条件不同.以上与写作相同:

This is NOT the same thing as saying that each in file is a prerequisite of its specific out file. The above is identical to writing:

out/1 : in/1 in/2 in/3
        @ echo $?
out/2 : in/1 in/2 in/3
        @ echo $?
out/3 : in/1 in/2 in/3
        @ echo $?

,也就是说,每个out文件都取决于 ALL in个文件.这就是为什么获得输出的原因.

which is to say, each out file depends on ALL the in files. That's why you get the output you do.

还请注意,make仅构建它在Makefile中找到的第一个目标(当然还有该目标的所有先决条件),这就是为什么您看不到其他out文件的任何信息的原因.您需要一个依赖于所有out文件的第一个目标,例如all.

Also note make only builds the first target it finds in the makefile (and all prerequisites of that target of course), which is why you don't see any info for the other out files. You need a first target such as all that depends on all the out files.

您需要使用三个明确的规则:

You need to either use three explicit rules:

.PHONY: all
all: out/1 out/2 out/3

out/1 : in/1
        @ echo $?
out/2 : in/2
        @ echo $?
out/3 : in/3
        @ echo $?

(需要预先知道哪些文件),或者使用模式规则:

(which requires knowing up-front which files), or else using a pattern rule:

.PHONY: all
all: out/*

out/% : in/%
        @ echo $?

这篇关于GNU制作通配符扩展的目标和先决条件顺序的显式列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆