您能否以某种方式在循环内替换用Makefile define
定义的变量?
VERSION ?= v1.0.0
CPUARCHS := amd64 arm arm64
DESCRIPTION := This is epic application doing epic things
# Manifest format for X
export define TEMPLATE_FORMAT1
Version: $(VERSION)
Arch: $$$$arch
$(DESCRIPTION)
endef
# Some other manifest format for Y
export define TEMPLATE_FORMAT2
pkgver=$(VERSION)
cpuarch=$$$$arch
descr=$(DESCRIPTION)
endef
format1:
@for arch in $(CPUARCHS); do \
echo "$$TEMPLATE_FORMAT1"; \
done
format2:
@for arch in $(CPUARCHS); do \
echo "$$TEMPLATE_FORMAT2"; \
done
genformats: format1 format2
@echo Done.
这导致:
% make format1
Version: v1.0.0
Arch: $$arch
This is epic application doing epic things
Version: v1.0.0
Arch: $$arch
This is epic application doing epic things
Version: v1.0.0
Arch: $$arch
This is epic application doing epic things
您可以将$$arch
替换为循环中使用的那个吗?当然,现实世界中的变量将比简单的$$arch
多得多,因此是否有“轻松的”解决方案(即,对于每个不同的模板格式目标,都没有成千上万的sed
或其他命令)?] >
您能以某种方式替换用Makefile在循环内定义的变量吗?版本?= v1.0.0 CPUARCHS:= amd64 arm arm64描述:=这是史诗级应用,正在执行史诗级事物#清单格式...
所以首先,在bash中,当您执行a=$b b=c echo $a
时,它将输出$b
而不是c
-它不会在变量内扩展变量。