Skip to content

Commit

Permalink
Support for statically linked builds
Browse files Browse the repository at this point in the history
  • Loading branch information
maximumadmin committed Mar 4, 2021
1 parent bbb0521 commit 8e6f508
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@ build:
go build -v -o $(OUT_FILE) $(GO_FILE)
@ls -lh $(OUT_FILE)

# Build production binary.
# Build statically linked production binary.
release: clean
@{\
export GOFLAGS="-a -trimpath -ldflags=-w -ldflags=-s" ;\
if [ "$${GOARCH}" != "arm" ]; then \
export GOFLAGS="$${GOFLAGS} -buildmode=pie" ;\
fi ;\
CGO_ENABLED=0 go build -o $(OUT_FILE) $(GO_FILE) ;\
}
@ls -lh $(OUT_FILE)

# Build dinamically linked production binary.
release-dynamic: clean
@{\
export CGO_CPPFLAGS="$${CPPFLAGS}" ;\
export CGO_CFLAGS="$${CFLAGS}" ;\
export CGO_CXXFLAGS="$${CXXFLAGS}" ;\
export CGO_LDFLAGS="$${LDFLAGS}" ;\
export GOFLAGS="-a -trimpath -ldflags=-w -ldflags=-s" ;\
export GOFLAGS="-a -trimpath -ldflags=-linkmode=external -ldflags=-w -ldflags=-s" ;\
if [ "$${GOARCH}" != "arm" ]; then \
export GOFLAGS="$${GOFLAGS} -buildmode=pie" ;\
fi ;\
Expand Down

0 comments on commit 8e6f508

Please sign in to comment.