首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Makefile:扩展"$<“在”优化“makefile中不起作用

Makefile:扩展"$<“在”优化“makefile中不起作用
EN

Server Fault用户
提问于 2022-08-03 10:51:34
回答 1查看 27关注 0票数 0

我有这样一个目录结构:

代码语言:javascript
复制
./
|
|- values-1/
|  |- thing0.yaml
|
|- values-2/
|  |- thing1.yaml
|
|- dachart-1/
|  |- thing0.yaml   (this should be generated by make
|                    from values-1/thing0.yaml)
|- dachart-2/
|  |- thing1.yaml   (this should be generated by make
                     from values-2/thing1.yaml)

“构建规则”基本上是相同的,但大约30行长。

这个非常简单的Makefile说明了什么是有效的:

代码语言:javascript
复制
# WORKING makefile, but with two redundant build rules

.SOURCES:

SHELL=bash

src1_files := $(wildcard values-1/*.yaml)
src2_files := $(wildcard values-2/*.yaml)
dst1_files := $(patsubst values-%,dachart-%,$(src1_files))
dst2_files := $(patsubst values-%,dachart-%,$(src2_files))

all: $(dst2_files) $(dst1_files)

dachart-1/%.yaml: values-1/%.yaml
    # SIMPLIFIED EXAMPLES
    @echo "source $<"
    @echo "target $@"

dachart-2/%.yaml: values-2/%.yaml
    @echo "source $<"
    @echo "target $@"

But由于构建规则确实很长,而且完全相同,所以我希望为所有文件定义一个 <#>build规则定义。

经过一番周旋之后,我想出了一个Makefile,它似乎能做我想做的事情(而且不会出错),唉,$<扩展不再起作用了(参见下面的输出)。

代码语言:javascript
复制
# NON-working makefile, but kinda what I want (only one build rule)

dachart-1/%.yaml: $(src1_files)
dachart-2/%.yaml: $(src2_files)

%.yaml:
    @echo "source $<"
    @echo "target $@"

产出如下:

代码语言:javascript
复制
# working makefile
source values-1/thing0.yaml
target dachart-1/thing0.yaml

# alternate makefile
source
target dachart-1/thing0.yaml

<#>问题:在我的非工作Makefile的意义上,是否只有一条构建规则?

EN

回答 1

Server Fault用户

发布于 2022-08-03 13:15:48

好吧,令人惊讶的是这起作用:

代码语言:javascript
复制
.SOURCES:

SHELL=bash

src1_files := $(wildcard values-0.1/*.yaml)
src2_files := $(wildcard values-2.0/*.yaml)
dst1_files := $(patsubst values-%,dachart-%,$(src1_files))
dst2_files := $(patsubst values-%,dachart-%,$(src2_files))

all: $(dst2_files) $(dst1_files)

fresh: clean all
.PHONY: fresh

dachart-0.1/%.yaml: THING=one
dachart-0.1/%.yaml: $(src1_files)

dachart-2.0/%.yaml: THING=two
dachart-2.0/%.yaml: $(src2_files)


dachart-*/%.yaml: values-*/%.yaml
    @echo THING=${THING}
    @echo "source $<"
    @echo "target $@"
票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1107270

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档