Skip to content

Commit

Permalink
chore: Realign binary naming & ldflags
Browse files Browse the repository at this point in the history
Bring binary naming in Makefile in line with previous releases
(i.e. make a bare binary, named with suffixes, not in a tar.gz file).

Use Makefile foreach to reduce repetition.

Make ldflags more similar to Homebrew Go standard ldflags so
binaries downloaded from GH or built with Homebrew are more
closely aligned.
  • Loading branch information
Drew Robinson committed Jul 17, 2022
1 parent 120cfe8 commit 064559d
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ VERSION := $(shell git describe --tag $(GITCOMMIT) 2>/dev/null)

GITBRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
BUILDTIME := $(shell TZ=GMT date "+%Y-%m-%d_%H:%M_GMT")
LDFLAGS := "-X main.version=$(VERSION) -X main.GitCommit=$(GITCOMMIT) -X main.GitBranch=$(GITBRANCH) -X main.BuildTime=$(BUILDTIME)"
LDFLAGS := "-s -w -X main.version=$(VERSION) -X main.GitCommit=$(GITCOMMIT) -X main.GitBranch=$(GITBRANCH) -X main.BuildTime=$(BUILDTIME)"

SRCS = $(shell find . -name '*.go' | grep -v '^./vendor/')
PKGS := $(foreach pkg, $(sort $(dir $(SRCS))), $(pkg))

OS := linux darwin windows
ARCH := amd64 arm64

TESTARGS ?=

default:
Expand All @@ -17,34 +20,20 @@ install:
cp ahoy /usr/local/bin/ahoy
chmod +x /usr/local/bin/ahoy

cross: build_dir
GOOS=linux GOARCH=amd64 \
go build -ldflags $(LDFLAGS) -v -o ./builds/linux_amd64/ahoy

GOOS=linux GOARCH=arm64 \
go build -ldflags $(LDFLAGS) -v -o ./builds/linux_arm64/ahoy

GOOS=darwin GOARCH=amd64 \
go build -ldflags $(LDFLAGS) -v -o ./builds/darwin_amd64/ahoy

GOOS=darwin GOARCH=arm64 \
go build -ldflags $(LDFLAGS) -v -o ./builds/darwin_arm64/ahoy
build_dir:
mkdir -p ./builds

cross_tars: cross
COPYFILE_DISABLE=1 tar -zcvf ./builds/ahoy_linux_amd64.tar.gz -C builds/linux_amd64 ahoy
COPYFILE_DISABLE=1 tar -zcvf ./builds/ahoy_linux_arm64.tar.gz -C builds/linux_arm64 ahoy
COPYFILE_DISABLE=1 tar -zcvf ./builds/ahoy_darwin_amd64.tar.gz -C builds/darwin_amd64 ahoy
COPYFILE_DISABLE=1 tar -zcvf ./builds/ahoy_darwin_arm64.tar.gz -C builds/darwin_arm64 ahoy
cross: build_dir
$(foreach os,$(OS), \
$(foreach arch,$(ARCH), \
GOOS=$(os) GOARCH=$(arch) go build -trimpath -ldflags $(LDFLAGS) -v -o ./builds/ahoy-bin-$(os)-$(arch); \
) \
)

build_dir:
mkdir -p ./builds/linux_amd64
mkdir -p ./builds/linux_arm64
mkdir -p ./builds/darwin_amd64
mkdir -p ./builds/darwin_arm64
$(foreach arch,$(ARCH),mv ./builds/ahoy-bin-windows-$(arch) ./builds/ahoy-bin-windows-$(arch).exe;)

clean:
cd builds
rm -Rf linux* darwin* *.tar.gz
rm -vRf ./builds/ahoy-bin-*

fmtcheck:
$(foreach file,$(SRCS),gofmt $(file) | diff -u $(file) - || exit;)
Expand All @@ -66,4 +55,4 @@ test: fmtcheck staticcheck vet
version:
@echo $(VERSION)

.PHONY: clean test fmtcheck staticcheck vet gocyclo version testdeps cross cross_tars build_dir default install
.PHONY: clean test fmtcheck staticcheck vet gocyclo version testdeps cross build_dir default install

0 comments on commit 064559d

Please sign in to comment.