Skip to content

Instantly share code, notes, and snippets.

@dev4mobile
Last active July 15, 2020 11:35
Show Gist options
  • Save dev4mobile/14fd7ddf6985e58db92e23fae8b89c92 to your computer and use it in GitHub Desktop.
Save dev4mobile/14fd7ddf6985e58db92e23fae8b89c92 to your computer and use it in GitHub Desktop.
This is go makefile template
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOCLEAN=$(GOCMD) clean
GOGET=$(GOCMD) get
BINARY_NAME=duck
all: build test
build:
$(GOBUILD) -o bin/${BINARY_NAME} -v
test:
$(GOTEST) -v ./...
run: build
./bin/${BINARY_NAME}
deps:
$(GOGET) github.com/gin-gonic/gin
#cross compilation
compile:
#Linux
GOOS=linux GOARCH=amd64 $(GOBUILD) -o bin/$(BINARY)-linux-amd64 -v
#MacOS
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o bin/$(BINARY)-darwin-amd64 -v
#Windows
GOOS=windows GOARCH=amd64 $(GOBUILD) -o bin/$(BINARY)-windows-amd64 -v
#docker build
docker-build:
docker run -it -v "${PWD}":/usr/src/myapp -w /usr/src/myapp -e GOOS=linux -e GOARCH=amd64 -e GOPROXY=https://goproxy.io,direct golang:latest ${GOBUILD} -o "$(BINARY_NAME)" -v
clean:
$(GOCLEAN)
-rm -rf bin/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment