Created
December 9, 2018 21:22
-
-
Save tullo/8570bbfb6f018a42009ac8130cce9df6 to your computer and use it in GitHub Desktop.
Makefile for Go Projects
This file contains 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
GOPATH=$(shell pwd)/vendor:$(shell pwd) | |
GOBIN=$(shell pwd)/bin | |
GOFILES=$(wildcard *.go) | |
GONAME=$(shell basename "$(PWD)") | |
PID=/tmp/go-$(GONAME).pid | |
build: | |
@echo "Building $(GOFILES) to ./bin" | |
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go build -o bin/$(GONAME) $(GOFILES) | |
get: | |
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go get . | |
install: | |
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go install $(GOFILES) | |
run: | |
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go run $(GOFILES) | |
watch: | |
@$(MAKE) restart & | |
@fswatch -o . -e 'bin/.*' | xargs -n1 -I{} make restart | |
restart: clear stop clean build start | |
start: | |
@echo "Starting bin/$(GONAME)" | |
@./bin/$(GONAME) & echo $$! > $(PID) | |
stop: | |
@echo "Stopping bin/$(GONAME) if it's running" | |
@-kill `[[ -f $(PID) ]] && cat $(PID)` 2>/dev/null || true | |
clear: | |
@clear | |
clean: | |
@echo "Cleaning" | |
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go clean | |
.PHONY: build get install run watch start stop restart clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment