GNU Make 简单展开变量和自动变量

huangapple go评论81阅读模式
英文:

GNU Make Simply Expanded Variables and Automatic Variables

问题

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

以便为几个不同的平台(例如Windows、Linux、Darwin)构建发布版本。

我的makefile目前看起来是这样的:

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 ...

所以据我所知,:=没有导致$@在赋值时被评估。有没有可能以某种方式实现这个?如果不行,我基本上只想在每个操作系统列表中迭代每个项目,然后在构建所有选项之前迭代每个架构。这样做是否可能,而不需要明确指定每个架构/操作系统组合?

英文:

I have a fairly simple makefile for a Go project and I want to be able to run something akin to:
make release-all

in order to build releases for a couple of different platforms (e.g. windows, linux, darwin).

My make file currently looks like this:

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 ...

When I actually try to build though, I get:

GOOS= GOARCH= go install ...

So as far as I can tell the := isn't causing the $@ to be evaluated on assignment. Is this possible to acheive somehow? If not, all I basically want to do is iterate over each item in list of OS'es and then over each of the architectures until I've built all the options. Is that at least possible without specifying each architecture/os combo explicitly?

答案1

得分: 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)))))

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

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)))))
英文:

Assuming that your command works, this will handle the iteration:

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)))))

huangapple
  • 本文由 发表于 2013年8月16日 06:47:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/18263144.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定