Skip to content

Instantly share code, notes, and snippets.

@devx
Created February 1, 2017 18:34
Show Gist options
  • Save devx/9891b91caa95f6a5b92bb967febd396d to your computer and use it in GitHub Desktop.
Save devx/9891b91caa95f6a5b92bb967febd396d to your computer and use it in GitHub Desktop.
Example Makefile for go Projects
BUILD_FLAGS := "-s -w -X main.GitVersion=`git rev-parse HEAD`"
SYSTEM = `uname -s`
default: clean build
linux-binary:
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags $(BUILD_FLAGS) -o builds/Linux/mediatord cmd/mediatord/main.go
osx-binary:
@CGO_ENABLED=0 GOOS=darwin go build -a -installsuffix cgo -ldflags $(BUILD_FLAGS) -o builds/Darwin/mediatord cmd/mediatord/main.go
build:
@go build -a -ldflags $(BUILD_FLAGS) -o builds/$(SYSTEM)/mediatord cmd/mediatord/main.go
install: build mv-bin
mv-bin:
@cp builds/${SYSTEM}/mediatord ${GOPATH}/bin/
clean:
rm -f cmd/mediatord/mediatord
rm -f builds/Darwin/mediatord
rm -f builds/Linux/mediatord
restore:
godep restore
depsave:
rm -f Godeps/Godeps.json
godep save
test:
go test -cover ./...
container: clean linux-binary
docker build -t quay.io/devx/mediatord:latest .
release: clean restore test osx-binary linux-binary
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment