Skip to content

Commit

Permalink
Use Pattern Rules in Makefile (#552)
Browse files Browse the repository at this point in the history
Convert the release/ section of the Makefile to using pattern rules.

This facilitates building for other platforms.
  • Loading branch information
directionless committed Feb 26, 2020
1 parent 81b227a commit ac8cfd9
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Makefile
Expand Up @@ -46,15 +46,13 @@ bench:
$(info INFO: Starting build $@)
go test -bench=.

release/goss-linux-386: $(GO_FILES)
$(info INFO: Starting build $@)
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-X main.version=$(TRAVIS_TAG) -s -w" -o release/$(cmd)-linux-386 $(exe)
release/goss-linux-amd64: $(GO_FILES)
$(info INFO: Starting build $@)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(TRAVIS_TAG) -s -w" -o release/$(cmd)-linux-amd64 $(exe)
release/goss-linux-arm: $(GO_FILES)
$(info INFO: Starting build $@)
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags "-X main.version=$(TRAVIS_TAG) -s -w" -o release/$(cmd)-linux-arm $(exe)


# Pattern rule for platform builds.
# `subst` substitutes space for -, thus making an array
# firstword, and word select indexes from said array.
release/goss-%: $(GO_FILES)
CGO_ENABLED=0 GOOS=$(firstword $(subst -, ,$*)) GOARCH=$(word 2, $(subst -, ,$*)) go build -ldflags "-X main.version=$(TRAVIS_TAG) -s -w" -o $@ $(exe)

release:
$(MAKE) clean
Expand Down

0 comments on commit ac8cfd9

Please sign in to comment.