Skip to content

Instantly share code, notes, and snippets.

@goliatone
Forked from TheHippo/Makefile
Created December 2, 2018 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goliatone/80e237f961e0f8b208bd4f6c520db171 to your computer and use it in GitHub Desktop.
Save goliatone/80e237f961e0f8b208bd4f6c520db171 to your computer and use it in GitHub Desktop.
Golang Makefile example
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