From 62cc87cf879452caaf4dbdd1d05192014584f37a Mon Sep 17 00:00:00 2001 From: Mithrandie Date: Fri, 29 May 2020 23:16:56 +0900 Subject: [PATCH] Update Makefile. Create files associated with build under the REPOSITORY_ROOT/build directory. --- .gitignore | 3 ++- Makefile | 60 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index e8cf90dc..1bea8858 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ ################################ vendor/ csvq +build/ +dist/ *.output ################################ @@ -86,7 +88,6 @@ tramp # cask packages .cask/ -dist/ # Flycheck flycheck_*.el diff --git a/Makefile b/Makefile index c8bef94c..e6f5fdcf 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,32 @@ -BINARY=csvq -VERSION=$(shell git describe --tags --always) +GOPATH := $(shell pwd)/build +BINARY := csvq +PRERELEASE_ARCH := darwin/amd64 linux/amd64 windows/amd64 -SOURCEDIR=. -SOURCES := $(shell find $(SOURCEDIR) -name '*.go') +ifneq ($(shell command -v git && git remote -v 2>/dev/null | grep mithrandie/csvq.git && echo true),true) + VERSION := $(shell git describe --tags --always 2>/dev/null) +endif -LDFLAGS := -ldflags="-X github.com/mithrandie/csvq/lib/query.Version=$(VERSION)" +ifdef VERSION + LDFLAGS := -ldflags="-X github.com/mithrandie/csvq/lib/query.Version=$(VERSION)" +endif DIST_DIRS := find * -type d -exec .DEFAULT_GOAL: $(BINARY) -$(BINARY): $(SOURCES) - go build $(LDFLAGS) -o $(BINARY) +$(BINARY): build + +.PHONY: build +build: + GOPATH=$(GOPATH) go build $(LDFLAGS) -o $(GOPATH)/bin/$(BINARY) .PHONY: install install: - go install $(LDFLAGS) - -.PHONY: install-goyacc -install-goyacc: -ifeq ($(shell command -v goyacc 2>/dev/null),) - go get github.com/cznic/goyacc -endif - -.PHONY: yacc -yacc: install-goyacc - cd lib/parser && \ - goyacc -o parser.go -v parser.output parser.y && \ - cd ../../lib/json && \ - goyacc -p jq -o query_parser.go -v query_parser.output query_parser.y && \ - goyacc -p jp -o path_parser.go -v path_parser.output path_parser.y && \ - cd ../.. + GOPATH=$(GOPATH) go install $(LDFLAGS) .PHONY: clean clean: - if [ -f $(BINARY) ]; then rm $(BINARY); fi + GOPATH=$(GOPATH) go clean -i -cache -modcache .PHONY: install-gox install-gox: @@ -44,11 +36,11 @@ endif .PHONY: build-all build-all: install-gox - gox $(LDFLAGS) -output="dist/${BINARY}-${VERSION}-{{.OS}}-{{.Arch}}/{{.Dir}}" + GOPATH=$(GOPATH) gox $(LDFLAGS) -output="dist/${BINARY}-${VERSION}-{{.OS}}-{{.Arch}}/{{.Dir}}" .PHONY: build-pre-release build-pre-release: install-gox - gox $(LDFLAGS) --osarch="darwin/amd64 linux/amd64 windows/amd64" -output="dist/${BINARY}-${VERSION}-{{.OS}}-{{.Arch}}/{{.Dir}}" + GOPATH=$(GOPATH) gox $(LDFLAGS) --osarch="$(PRERELEASE_ARCH)" -output="dist/${BINARY}-${VERSION}-{{.OS}}-{{.Arch}}/{{.Dir}}" .PHONY: dist dist: @@ -67,3 +59,19 @@ ifeq ($(shell git tag --contains 2>/dev/null),) else git push origin $(VERSION) endif + +.PHONY: install-goyacc +install-goyacc: +ifeq ($(shell command -v goyacc 2>/dev/null),) + go get github.com/cznic/goyacc +endif + +.PHONY: yacc +yacc: install-goyacc + cd lib/parser && \ + goyacc -o parser.go -v parser.output parser.y && \ + cd ../../lib/json && \ + goyacc -p jq -o query_parser.go -v query_parser.output query_parser.y && \ + goyacc -p jp -o path_parser.go -v path_parser.output path_parser.y && \ + cd ../.. +