Last active
December 25, 2015 08:27
-
-
Save gebv/0ae52416c337b075c394 to your computer and use it in GitHub Desktop.
makefile for the build of any golang application with vendors packages
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
.PHONY: build doc fmt test vendor_clean vendor_get vendor_update vet run stop | |
GOPATH := ${PWD}:${PWD}/vendor | |
APPPKG := fsv2 | |
CMDRUN := cmd/server | |
LOGPATH := ./bin/logs | |
LOGCURRENT := $(APPPKG) | |
PIDFILE := ./bin/$(APPPKG).run.pid | |
BUILDID := $(shell date +%Y-%m-%d:%H:%M:%S) | |
ifneq ("$(wildcard $(PIDFILE))","") | |
PID=$(shell cat $(PIDFILE)) | |
endif | |
default: build | |
run: | |
@echo Current PID='$(PID)' | |
ifndef PID | |
@echo Starting... | |
$(shell nohup ./bin/app.run -stderrthreshold=INFO > $(LOGPATH)/$(APPPKG).current.log 2>&1 & echo $$! > $(PIDFILE)) | |
@echo PID='$(shell cat $(PIDFILE))' | |
@echo $(LOGPATH)/$(APPPKG).current.log | |
else | |
@echo Аlready running in pid $(PID) | |
endif | |
stop: | |
@echo Current PID='$(PID)' | |
ifdef PID | |
@echo Stoping... | |
@echo PID='$(PID)' | |
$(shell kill -9 $(PID)) | |
@rm $(PIDFILE) | |
@cp $(LOGPATH)/$(APPPKG).current.log $(LOGPATH)/$(APPPKG).$(BUILDID).log | |
@rm $(LOGPATH)/$(APPPKG).current.log | |
else | |
@echo Nothing is running | |
endif | |
build: vet | |
GOPATH=$(GOPATH) go build -v -o ./bin/app.run ./src/$(CMDRUN) | |
build_osx_64: vet | |
GOOS="darwin" GOARCH="amd64" GOPATH=$(GOPATH) go build -v -o ./bin/app_osx_64.run ./src/$(CMDRUN) | |
fmt: | |
GOPATH=$(GOPATH) go fmt ./src/$(APPPKG)/... | |
vet: | |
GOPATH=$(GOPATH) go vet ./src/$(APPPKG)/... | |
test: | |
GOPATH=$(GOPATH) go test ./src/$(APPPKG)/... | |
dev_clear_log: | |
find ./bin/logs -type f -mtime +7 -print0 | xargs -0 rm -f | |
vendor_clean: | |
# find ./src -type d -not -name '*.run' | xargs rm | |
rm -dRf ./vendor | |
rm -dRf ./bin | |
rm -dRf ./pkg | |
vendor_get: vendor_clean | |
GOPATH=${PWD}/vendor go get -u -v \ | |
github.com/gorilla/mux \ | |
github.com/golang/glog \ | |
github.com/lib/pq \ | |
gopkg.in/pg.v3 \ | |
github.com/boj/redistore \ | |
github.com/gorilla/sessions \ | |
gopkg.in/bluesuncorp/validator.v8 \ | |
github.com/gorilla/csrf \ | |
github.com/gorilla/context \ | |
github.com/boj/redistore \ | |
github.com/mattbaird/elastigo | |
vendor_update: vendor_get | |
rm -rf `find ./vendor -type d -name .git` \ | |
&& rm -rf `find ./vendor -type d -name .hg` \ | |
&& rm -rf `find ./vendor -type d -name .bzr` \ | |
&& rm -rf `find ./vendor -type d -name .svn` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: rebuild by one command