Golang makefile example
Here is a simple example of a makefile for a golang project.
.DEFAULT_GOAL := build
BINARY="BinaryName"
fmt:
go fmt ./
.PHONY: fmt
lint: fmt
golint ./
.PHONY: lint
vet: fmt
go vet ./
.PHONY: vet
build: vet
go build hello.go
.PHONY:build
mac:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ${BINARY}
win:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ${BINARY}
run:
@go run ./
gotool:
go fmt ./
go vet ./
clean:
@if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi
help:
@echo "make - clean, format, build"
@echo "make build - just build"
@echo "make run - just run"
@echo "make clean - clean binary file"
@echo "make gotool - run fmt and vet tools"
@echo "make mac - build for mac"
@echo "make win - build for windows"
Disclaimer
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.me
, replace # with @ - Not all the commands and scripts are tested in production environment, use at your own risk
- No privacy information is collected here