Makefile中的模板定义,带有来自循环的动态变量

问题描述 投票:0回答:1

您能否以某种方式在循环内替换用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描述:=这是史诗级应用,正在执行史诗级事物#清单格式...

variables dynamic makefile
1个回答
0
投票

所以首先,在bash中,当您执行a=$b b=c echo $a时,它将输出$b而不是c-它不会在变量内扩展变量。

© www.soinside.com 2019 - 2024. All rights reserved.