Skip to content

Commit

Permalink
disable cgo, build PIE when possible
Browse files Browse the repository at this point in the history
closes #26
  • Loading branch information
dundee committed Jan 29, 2021
1 parent fc02b77 commit c4db110
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NAME := gdu
PACKAGE := github.com/dundee/$(NAME)
VERSION := $(shell git describe --tags)
GOFLAGS ?= -buildmode=pie -trimpath -mod=readonly -modcacherw
LDFLAGS := "-s -w \
LDFLAGS := "-s -w -extldflags '-static' \
-X '$(PACKAGE)/build.Version=$(VERSION)' \
-X '$(PACKAGE)/build.User=$(shell id -u -n)' \
-X '$(PACKAGE)/build.Time=$(shell LC_ALL=en_US.UTF-8 date)'"
Expand All @@ -13,26 +13,28 @@ run:
build:
@echo "Version: " $(VERSION)
mkdir -p dist
GOFLAGS="$(GOFLAGS)" go build -ldflags=$(LDFLAGS) -o dist/$(NAME) .
GOFLAGS="$(GOFLAGS)" CGO_ENABLED=0 go build -a -ldflags=$(LDFLAGS) -o dist/$(NAME) .

build-all:
@echo "Version: " $(VERSION)
-mkdir dist
-gox \
-CGO_ENABLED=0 gox \
-os="darwin windows" \
-arch="amd64" \
-output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" \
-ldflags=$(LDFLAGS)

-gox \
-CGO_ENABLED=0 gox \
-os="linux freebsd netbsd openbsd" \
-output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" \
-ldflags=$(LDFLAGS)

cd dist; GOOS=linux GOARM=5 GOARCH=arm go build -ldflags=$(LDFLAGS) -o gdu_linux_armv5l ..
cd dist; GOOS=linux GOARM=6 GOARCH=arm go build -ldflags=$(LDFLAGS) -o gdu_linux_armv6l ..
cd dist; GOOS=linux GOARM=7 GOARCH=arm go build -ldflags=$(LDFLAGS) -o gdu_linux_armv7l ..
cd dist; GOOS=linux GOARCH=arm64 go build -ldflags=$(LDFLAGS) -o gdu_linux_arm64 ..
cd dist; GOFLAGS="$(GOFLAGS)" CGO_ENABLED=0 go build -a -ldflags=$(LDFLAGS) -o gdu_linux_amd64 ..

cd dist; CGO_ENABLED=0 GOOS=linux GOARM=5 GOARCH=arm go build -ldflags=$(LDFLAGS) -o gdu_linux_armv5l ..
cd dist; CGO_ENABLED=0 GOOS=linux GOARM=6 GOARCH=arm go build -ldflags=$(LDFLAGS) -o gdu_linux_armv6l ..
cd dist; CGO_ENABLED=0 GOOS=linux GOARM=7 GOARCH=arm go build -ldflags=$(LDFLAGS) -o gdu_linux_armv7l ..
cd dist; CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags=$(LDFLAGS) -o gdu_linux_arm64 ..

cd dist; for file in gdu_linux_* gdu_darwin_* gdu_netbsd_* gdu_openbsd_* gdu_freebsd_*; do tar czf $$file.tgz $$file; done
cd dist; for file in gdu_windows_*; do zip $$file.zip $$file; done
Expand Down

0 comments on commit c4db110

Please sign in to comment.