github.com/LGUG2Z/story@v0.4.1/Makefile (about) 1 # ############################################################################## # 2 # Makefile for Golang Project # 3 # Includes cross-compiling, installation, cleanup # 4 # Adapted from https://gist.github.com/cjbarker/5ce66fcca74a1928a155cfb3fea8fac4 # 5 # ############################################################################## # 6 7 # Check for required command tools to build or stop immediately 8 EXECUTABLES = git go find pwd 9 K := $(foreach exec,$(EXECUTABLES),\ 10 $(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH))) 11 12 ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 13 14 BINARY=story 15 VERSION=`cat VERSION` 16 COMMIT=`git rev-parse HEAD` 17 PLATFORMS=darwin linux 18 ARCHITECTURES=amd64 19 20 # Setup linker flags option for build that interoperate with variable names in src code 21 LDFLAGS=-ldflags "-X github.com/LGUG2Z/story/cli.Version=${VERSION} -X github.com/LGUG2Z/story/cli.Commit=${COMMIT}" 22 23 default: build 24 25 all: clean build_all install 26 27 build: 28 go build ${LDFLAGS} -o ${BINARY} 29 30 build_all: 31 $(foreach GOOS, $(PLATFORMS),\ 32 $(foreach GOARCH, $(ARCHITECTURES), $(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build -v -o $(BINARY)-$(GOOS)-$(GOARCH)))) 33 34 install: 35 go install ${LDFLAGS} 36 ln -sf ${GOPATH}/src/github.com/LGUG2Z/story/bash_autocomplete /usr/local/etc/bash_completion.d/story 37 38 fmt: 39 gofmt -s -w cli git manifest node main.go 40 goimports -w cli git manifest node main.go 41 42 release: 43 goreleaser --rm-dist 44 45 # Remove only what we've created 46 clean: 47 find ${ROOT_DIR} -name '${BINARY}[-?][a-zA-Z0-9]*[-?][a-zA-Z0-9]*' -delete 48 rm -rf dist 49 50 .PHONY: check clean install build_all all