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

Add Makefile flag for building static binary #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
VERSION := $(shell git describe --always --dirty)

ifdef STATIC
CGO := CGO_ENABLED=0
endif

help:
@echo 'make build - build the clipper executable'
@echo 'make tag - tag the current HEAD with VERSION'
@echo 'make archive - create an archive of the current HEAD for VERSION'
@echo 'make upload - upload the built archive of VERSION to Amazon S3'
@echo 'make all - build, tag, archive and upload VERSION'
@echo ''
@echo 'Append STATIC=1 to build a static binary.'

version:
@if [ "$$VERSION" = "" ]; then echo "VERSION not set"; exit 1; fi

clipper_linux:
GOOS=linux GOARCH=amd64 go build -ldflags="-X main.version=${VERSION}" -o clipper_linux clipper.go
$(CGO) GOOS=linux GOARCH=amd64 go build -ldflags="-X main.version=${VERSION}" -o clipper_linux clipper.go

clipper_darwin:
GOOS=darwin GOARCH=amd64 go build -ldflags="-X main.version=${VERSION}" -o clipper_darwin clipper.go
$(CGO) GOOS=darwin GOARCH=amd64 go build -ldflags="-X main.version=${VERSION}" -o clipper_darwin clipper.go

clipper_all: clipper_linux clipper_darwin

clipper: clipper.go
go build -ldflags="-X main.version=${VERSION}" $^
$(CGO) go build -ldflags="-X main.version=${VERSION}" $^

build: clipper

Expand Down