Skip to content

Instantly share code, notes, and snippets.

@ae6rt
Created November 7, 2014 18:05
Show Gist options
  • Save ae6rt/6671f5762e2144d18c8c to your computer and use it in GitHub Desktop.
Save ae6rt/6671f5762e2144d18c8c to your computer and use it in GitHub Desktop.
Go Makefile prototype
NAME := stashkins
ARCH := amd64
VERSION := 1.0
DATE := $(shell date)
COMMIT_ID := $(shell git rev-parse --short HEAD)
SDK_INFO := $(shell go version)
LD_FLAGS := -X main.version $(VERSION) -X main.commit $(COMMIT_ID) -X main.buildTime '$(DATE)' -X main.sdkInfo '$(SDK_INFO)'
all: clean binaries package
test:
godep go test
binaries: tools deps test
GOOS=darwin GOARCH=$(ARCH) godep go build -ldflags "$(LD_FLAGS)" -o $(NAME)-darwin-$(ARCH)
GOOS=linux GOARCH=$(ARCH) godep go build -ldflags "$(LD_FLAGS)" -o $(NAME)-linux-$(ARCH)
deps:
go get -v -u github.com/xoom/stash
go get -v -u github.com/xoom/jenkins
tools:
type godep > /dev/null 2>&1 || go get -v github.com/tools/godep
clean:
go clean
rm -f *.deb
package:
which fpm && fpm -s dir -t deb -v $(VERSION) -n stashkins -a amd64 -m"Mark Petrovic <[email protected]>" --prefix /usr/local/bin --description "https://github.com/xoom/stashkins" stashkins-linux-amd64
@ae6rt
Copy link
Author

ae6rt commented Nov 7, 2014

Here are the variable declarations in the stashkins.go code that ldflags works against:

var (
...
version string
commit string
buildTime string
sdkInfo string
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment