## Standard Makefile preamble ## according to https://tech.davis-hansson.com/p/make/ ## Specify a shell SHELL := bash ## set shell options .SHELLFLAGS := -eu -o pipefail -c ## Makefile defaults .ONESHELL: .DELETE_ON_ERROR: MAKEFLAGS += --warn-undefined-variables MAKEFLAGS += --no-builtin-rules ## Modify Makefile parsing ifeq ($(origin .RECIPEPREFIX), undefined) $(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later) endif .RECIPEPREFIX = > #---------------------------------------------------------------- # Variables #---------------------------------------------------------------- progName = scaffold arch = amd64 winbinName = $(progName).exe releaseTag = $(shell git describe --abbrev=0) #---------------------------------------------------------------- # Helpers #---------------------------------------------------------------- ## help: print this help message help: > @echo 'Usage:' > @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' ## confirm: a helper script to check your intent confirm: > @echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ] ## clean: clears temp files clean: > @echo 'Cleaning temp files ...' > @echo '' > buildTime.txt > @echo '' > buildVersion.txt > @echo 'Done cleaning.' #---------------------------------------------------------------- # Build #---------------------------------------------------------------- # build strips debugging info from binary linkerflags = '-s -w' prep: clean > date +"%F %a %T %Z" > buildTime.txt > git describe --always --tags --dirty --long > buildVersion.txt > @mkdir -p build build: prep linux windows linux: > @GOOS=$@ GOARCH=$(arch) go build -o build/$@/$(progName) . && echo $@ "Build success" || echo $@ "[FAILED] go build" windows: > @GOOS=$@ GOARCH=$(arch) go build -o build/$@/$(progName)-$(arch)-$(releaseTag).exe . && echo $@ "Build success" || echo $@ "[FAILED] go build" build-production: prep linx-production linux-production: > @GOOS=linx GOARCH=$(arch) go build -ldflags=${linkerflags} -o build/$@/$(progName) . && echo "production build success" || echo "[FAILED] production build" #------------------------------------------------------------- # Install - same as build, but places binary on system path #------------------------------------------------------------- install: prep > @go install . && echo "Build and Install success" || echo "[FAILED] go install" install-production: prep > @go install -ldflags=${linkerflags} . && echo "Production build and install success" || echo "[FAILED] Production install" ## Commands that don't relate to a specific file .PHONY: help confirm clean prep build build-production linux windows amd64