Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile: evaluate os/arch based on target name #4236

Merged
merged 3 commits into from
May 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,23 @@ install: $(BUILD_DIR)/$(PROJECT)
cross: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform))

$(BUILD_DIR)/$(PROJECT)-%: $(STATIK_FILES) $(GO_FILES) $(BUILD_DIR) deploy/cross/Dockerfile
GOOS="$(firstword $(subst -, ,$*))" GOARCH="$(lastword $(subst -, ,$(subst .exe,,$*)))" \
$(eval os = $(firstword $(subst -, ,$*)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its is frustrating, we cant use keys values pairs all though its supported on bash4.
https://stackoverflow.com/questions/6047648/bash4-associative-arrays-error-declare-a-invalid-option
It would have been much easier to read and less error prone.

this change looks good to me.

$(eval arch = $(lastword $(subst -, ,$(subst .exe,,$*))))
$(eval ldflags = $(GO_LDFLAGS_$(os)))
$(eval tags = $(GO_BUILD_TAGS_$(os)))

docker build \
--build-arg GOOS=$(GOOS) \
--build-arg GOARCH=$(GOARCH) \
--build-arg TAGS=$(GO_BUILD_TAGS_$(GOOS)) \
--build-arg LDFLAGS=$(GO_LDFLAGS_$(GOOS)) \
--build-arg GOOS=$(os) \
--build-arg GOARCH=$(arch) \
--build-arg TAGS=$(tags) \
--build-arg LDFLAGS=$(ldflags) \
-f deploy/cross/Dockerfile \
-t skaffold/cross \
.

docker run --rm skaffold/cross cat /build/skaffold > $@
shasum -a 256 $@ > $@.sha256
shasum -a 256 $@ | tee $@.sha256
file $@ || true

.PHONY: $(BUILD_DIR)/VERSION
$(BUILD_DIR)/VERSION: $(BUILD_DIR)
Expand Down