more Makefile improvements

* warn upfront if go/dep/npm not available
* try to find dep in $GOPATH/bin if not installed globally
* only override variables if not externally defined, allowing manual override from command line
* split up Makefile into a buid/setup.mk for simplicity

I didn't actually find anything that made this Makefile not-linux
specific -- tested on Debian with the standard make installed.
This commit is contained in:
Jesse Hallam 2018-07-31 15:18:53 -04:00
parent 72c619f8bc
commit 2de3471aa2
No known key found for this signature in database
GPG key ID: E7959EB6518AF966
2 changed files with 54 additions and 22 deletions

View file

@ -1,20 +1,10 @@
GO=go
MANIFEST_FILE=plugin.json
GO ?= $(shell command -v go 2> /dev/null)
DEP ?= $(shell command -v dep 2> /dev/null)
NPM ?= $(shell command -v npm 2> /dev/null)
MANIFEST_FILE ?= plugin.json
# Ensure that the build tools are compiled. Go's caching makes this quick.
$(shell cd build/manifest && $(GO) build -o ../bin/manifest)
# Extract the plugin id from the manifest.
PLUGIN_ID=$(shell build/bin/manifest plugin_id)
ifeq ($(PLUGIN_ID),)
$(error Cannot parse id from $(MANIFEST_FILE))
endif
# Determine if a server is defined in the manifest
HAS_SERVER=$(shell build/bin/manifest has_server)
# Determine if a webapp is defined in the manifest
HAS_WEBAPP=$(shell build/bin/manifest has_webapp)
# Verify environment, and define PLUGIN_ID, HAS_SERVER and HAS_WEBAPP as needed.
include build/setup.mk
# all, the default target, tests, builds and bundles the plugin.
all: test dist
@ -24,10 +14,10 @@ all: test dist
apply:
./build/bin/manifest apply
# vendor ensures the server dependencies are installed
# server/.depensure ensures the server dependencies are installed
server/.depensure:
ifneq ($(HAS_SERVER),)
cd server && dep ensure
cd server && $(DEP) ensure
touch $@
endif
@ -44,7 +34,7 @@ endif
# webapp/.npminstall ensures NPM dependencies are installed without having to run this all the time
webapp/.npminstall:
ifneq ($(HAS_WEBAPP),)
cd webapp && npm install
cd webapp && $(NPM) install
touch $@
endif
@ -52,7 +42,7 @@ endif
.PHONY: webapp
webapp: webapp/.npminstall
ifneq ($(HAS_WEBAPP),)
cd webapp && npm run build;
cd webapp && $(NPM) run build;
endif
# bundle generates a tar bundle of the plugin for install
@ -103,12 +93,12 @@ endif
# test runs any lints and unit tests defined for the server and webapp, if they exist
.PHONY: test
test: webapp/.npminstall
test: server/.depensure webapp/.npminstall
ifneq ($(HAS_SERVER),)
cd server && $(GO) test -v -coverprofile=coverage.txt ./...
endif
ifneq ($(HAS_WEBAPP),)
cd webapp && npm run fix;
cd webapp && $(NPM) run fix;
endif
# clean removes all build artifacts