Created
March 31, 2016 22:32
-
-
Save TheHippo/7e4d9ec4b7ed4c0d7a39839e6800cc16 to your computer and use it in GitHub Desktop.
Golang Makefile example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OUT := binariy-name | |
PKG := gitlab.com/group/project | |
VERSION := $(shell git describe --always --long --dirty) | |
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/) | |
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/) | |
all: run | |
server: | |
go build -i -v -o ${OUT} -ldflags="-X main.version=${VERSION}" ${PKG} | |
test: | |
@go test -short ${PKG_LIST} | |
vet: | |
@go vet ${PKG_LIST} | |
lint: | |
@for file in ${GO_FILES} ; do \ | |
golint $$file ; \ | |
done | |
static: vet lint | |
go build -i -v -o ${OUT}-v${VERSION} -tags netgo -ldflags="-extldflags \"-static\" -w -s -X main.version=${VERSION}" ${PKG} | |
run: server | |
./${OUT} | |
clean: | |
-@rm ${OUT} ${OUT}-v* | |
.PHONY: run server static vet lint |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment