Created
March 6, 2020 23:57
-
-
Save shohi/b3d32aed8cb12fa722e03e8d17ef4e54 to your computer and use it in GitHub Desktop.
Makefile for Go Projects
This file contains hidden or 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