Skip to content

Instantly share code, notes, and snippets.

@Inquizarus
Last active June 26, 2018 10:07
Show Gist options
  • Save Inquizarus/82793bed195c2df6943d303c8f663300 to your computer and use it in GitHub Desktop.
Save Inquizarus/82793bed195c2df6943d303c8f663300 to your computer and use it in GitHub Desktop.
boilerplate golang makefile
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
BINARY_NAME={{binary_name}}
BINARY_UNIX=$(BINARY_NAME)_unix
all: test build
build:
$(GOBUILD) -o $(BINARY_NAME) -v
test:
$(GOTEST) -v ./...
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f $(BINARY_UNIX)
run:
$(GOBUILD) -o $(BINARY_NAME) -v ./...
./$(BINARY_NAME)
# Cross compilation
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX) -v
docker-build:
docker run --rm -it -v "$(GOPATH)":/go -w /go/src/bitbucket.org/rsohlich/makepost golang:latest go build -o "$(BINARY_UNIX)" -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment