Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(make): add goal to build executable (#94) #103

Merged
merged 1 commit into from
May 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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