我有这样一个目录结构:
./
|
|- 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说明了什么是有效的:
# 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,它似乎能做我想做的事情(而且不会出错),唉,$<扩展不再起作用了(参见下面的输出)。
# 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 $@"产出如下:
# working makefile
source values-1/thing0.yaml
target dachart-1/thing0.yaml
# alternate makefile
source
target dachart-1/thing0.yaml<#>问题:在我的非工作Makefile的意义上,是否只有一条构建规则?
发布于 2022-08-03 13:15:48
好吧,令人惊讶的是这起作用:
.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 $@"https://serverfault.com/questions/1107270
复制相似问题