Skip to content

Commit

Permalink
Update Makefile.
Browse files Browse the repository at this point in the history
Create files associated with build under the REPOSITORY_ROOT/build directory.
  • Loading branch information
mithrandie committed May 30, 2020
1 parent 6967f81 commit 62cc87c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
################################
vendor/
csvq
build/
dist/
*.output

################################
Expand Down Expand Up @@ -86,7 +88,6 @@ tramp

# cask packages
.cask/
dist/

# Flycheck
flycheck_*.el
Expand Down
60 changes: 34 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand All @@ -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 ../..

0 comments on commit 62cc87c

Please sign in to comment.