Skip to content

Instantly share code, notes, and snippets.

@akovardin
Created October 21, 2018 20:17
Show Gist options
  • Save akovardin/04169ec6e89a38b206eb08b717bcf428 to your computer and use it in GitHub Desktop.
Save akovardin/04169ec6e89a38b206eb08b717bcf428 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