From 7e25da7bc4e226d4fe4abafe646f008e975705a2 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Fri, 9 Mar 2018 22:00:12 +0000 Subject: [PATCH] Improve Makefile, add multiple targets Adds targets to do things like: * build * install * vendor Signed-off-by: Eli Uriegas --- .gitignore | 4 ++-- Makefile | 33 +++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 890475a2dc..e7dd802940 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -vendor/ _vendor-*/ -dist/ \ No newline at end of file +dist/ +bin/ diff --git a/Makefile b/Makefile index c4ae65c804..faab0b2c39 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,32 @@ -.PHONY: default clean +DEP="$(shell go env GOPATH)/bin/dep" +PREFIX?=/usr/local/bin +LDFLAGS:=-ldflags '-X main.version=$(shell git rev-parse --abbrev-ref HEAD) -X main.commit=$(shell git rev-parse HEAD) -X "main.goversion=$(shell go version)"' -default: - go install -ldflags '-X main.version=$(shell git rev-parse --abbrev-ref HEAD) -X main.commit=$(shell git rev-parse HEAD) -X "main.goversion=$(shell go version)"' github.com/fossas/fossa-cli/cmd/fossa +all: build +$(DEP): ## Grab golang/dep utility + go get github.com/golang/dep/cmd/dep + +.PHONY: build +build: bin/fossa + +bin/fossa: + mkdir -p $$(dirname $@) + go build -o $@ $(LDFLAGS) github.com/fossas/fossa-cli/cmd/fossa + +$(PREFIX)/fossa: bin/fossa + mv $< $@ + +vendor: $(DEP) + $< ensure -v -update + +.PHONY: install +install: $(PREFIX)/fossa + +.PHONY: uninstall +uninstall: + rm $(PREFIX)/fossa + +.PHONY: clean clean: - rm -f $(GOPATH)/bin/fossa \ No newline at end of file + rm -f bin/fossa