Skip to content

Instantly share code, notes, and snippets.

@varunpant
Last active May 6, 2018 13:58
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 varunpant/79231da37d9550ced0ee1d01dcbdea0e to your computer and use it in GitHub Desktop.
Save varunpant/79231da37d9550ced0ee1d01dcbdea0e to your computer and use it in GitHub Desktop.
Makefile for Go Projects
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