Skip to content

Commit

Permalink
feat(make): add goal to build executable (#94), show help by default (#…
Browse files Browse the repository at this point in the history
…99)

Also, a bit of cleaning in the Makefile.

Fixes #94
Fixes #99

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed May 12, 2018
1 parent d2caa76 commit 10759be
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ GIT_BIN_NAME := git
GIT_BIN := $(shell command -v $(GIT_BIN_NAME) 2> /dev/null)
DEP_BIN_NAME := dep
DEP_BIN := $(shell command -v $(DEP_BIN_NAME) 2> /dev/null)
PIGEON_BIN_NAME := pigeon
PIGEON_BIN := $(shell command -v $(PIGEON_BIN_NAME) 2> /dev/null)
GO_BIN_NAME := go
GO_BIN := $(shell command -v $(GO_BIN_NAME) 2> /dev/null)
EXTRA_PATH=$(shell dirname $(GO_BINDATA_BIN))
Expand All @@ -14,28 +16,22 @@ PACKAGE_NAME := github.com/bytesparadise/libasciidoc
CUR_DIR=$(shell pwd)
TMP_PATH=$(CUR_DIR)/tmp
INSTALL_PREFIX=$(CUR_DIR)/bin
BINARY_PATH=$(INSTALL_PREFIX)/libasciidoc
VENDOR_DIR=vendor
SOURCE_DIR ?= .
SOURCES := $(shell find $(SOURCE_DIR) -path $(SOURCE_DIR)/vendor -prune -o -name '*.go' -print)
COVERPKGS := $(shell go list ./... | grep -v vendor | paste -sd "," -)

$(INSTALL_PREFIX):
# Build artifacts dir
@mkdir -p $(INSTALL_PREFIX)

$(TMP_PATH):
@mkdir -p $(TMP_PATH)
ifeq ($(OS),Windows_NT)
BINARY_PATH=$(INSTALL_PREFIX)/libasciidoc.exe
else
BINARY_PATH=$(INSTALL_PREFIX)/libasciidoc
endif

# Call this function with $(call log-info,"Your message")
define log-info =
@echo "INFO: $(1)"
endef

# If nothing was specified, run all targets as if in a fresh clone
.PHONY: all
## Default target - fetch dependencies, generate code and build.
all: prebuild-check get-deps generate build

.PHONY: help
# Based on https://gist.github.com/rcmachado/af3db315e31383502660
Expand Down Expand Up @@ -64,13 +60,20 @@ help:/
} \
}' $(MAKEFILE_LIST)

.PHONY: get-deps
.PHONY: deps
## Download build dependencies.
get-deps: $(VENDOR_DIR)
deps: $(VENDOR_DIR)

$(VENDOR_DIR):
$(DEP_BIN) ensure

$(INSTALL_PREFIX):
# Build artifacts dir
@mkdir -p $(INSTALL_PREFIX)

$(TMP_PATH):
@mkdir -p $(TMP_PATH)

.PHONY: prebuild-checks
prebuild-checks: $(TMP_PATH) $(INSTALL_PREFIX)
# Check that all tools where found
Expand All @@ -80,7 +83,9 @@ endif
ifndef DEP_BIN
$(error The "$(DEP_BIN_NAME)" executable could not be found in your PATH)
endif

ifndef PIGEON_BIN
$(error The "$(PIGEON_BIN_NAME)" executable could not be found in your PATH)
endif
ifndef GO_BIN
$(error The "$(GO_BIN_NAME)" executable could not be found in your PATH)
endif
Expand All @@ -91,8 +96,14 @@ generate:
@pigeon ./parser/asciidoc-grammar.peg > ./parser/asciidoc_parser.go


.PHONY: get-deps test
.PHONY: test
## run all tests except in the 'vendor' package
test:
test: deps generate
@echo $(COVERPKGS)
@ginkgo -r --randomizeAllSpecs --randomizeSuites --failOnPending --trace --race --compilers=2 --cover -coverpkg $(COVERPKGS)

.PHONY: build
## builds the binary executable from CLI
build: $(INSTALL_PREFIX) deps
@echo "building $(BINARY_PATH) ..."
@go build -o $(BINARY_PATH) cmd/libasciidoc/*.go

0 comments on commit 10759be

Please sign in to comment.