GNU简化扩展变量和自动变量

时间:2013-08-15 22:47:05

标签: makefile go cross-compiling gnu-make

对于Go项目,我有一个相当简单的makefile,我希望能够运行类似于:     make release-all

为了构建几个不同平台的版本(例如windows,linux,darwin)。

我的make文件目前看起来像这样:

GOOSES = darwin windows linux
GOARCHS = amd64 386
.PHONY: release-all $(GOOSES) $(GOARCHS)
release: $(GOOSES)

$(GOOSES): GOOS := app $@
$(GOOSES): $(GOARCHS)

$(GOARCHS): GOARCH := $@
$(GOARCHS): build

build:
GOOS=$(GOOS) GOARCH=$(GOARCH) go install ...

当我真正尝试构建时,我得到:

GOOS= GOARCH= go install ...

据我所知,:=并未导致$@在作业时被评估。这有可能以某种方式实现吗?如果没有,我基本上想要做的就是迭代OS'列表中的每个项目,然后遍历每个架构,直到我构建了所有选项。如果没有明确指定每个架构/ os组合,这至少是可能的吗?

1 个答案:

答案 0 :(得分:2)

假设您的命令有效,这将处理迭代:

GOOSES = darwin windows linux
GOARCHS = amd64 386

build:

define template
build: build_$(1)_$(2)
.PHONY: build_$(1)_$(2)
build_$(1)_$(2):
    GOOS=$(1) GOARCH=$(2) go install ...
endef

$(foreach GOARCH,$(GOARCHS),$(foreach GOOS,$(GOOSES),$(eval $(call template,$(GOOS),$(GOARCH)))))