aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2018-02-27 04:14:44 +0000
committerFelix Hanley <felix@userspace.com.au>2018-02-27 04:14:44 +0000
commita6e10f4b154214903694cf96d57d942e080b1bd1 (patch)
tree412207d1a688951f47248c00697049ef0a993967 /Makefile
parent78470db44bb80b587a0e69af9413d95e62a1e565 (diff)
downloaddhtsearch-a6e10f4b154214903694cf96d57d942e080b1bd1.tar.gz
dhtsearch-a6e10f4b154214903694cf96d57d942e080b1bd1.tar.bz2
Update makefile to include docs and cross compile
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile47
1 files changed, 32 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 2fbc4c2..40685e4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,23 +1,40 @@
-BINARY=dhtsearch
-VERSION=$(shell git describe --tags --always)
-SRC=$(shell find . -type f -name '*.go')
-
-build: $(BINARY)
-
-$(BINARY): $(SRC)
- cd cmd && go build -ldflags "-w -s \
- -X main.version=$(VERSION)" \
- -o ../$(BINARY)
-test:
- go test -short -coverprofile=coverage.out
+TARGETS = linux-386 linux-amd64 linux-arm linux-arm64 darwin-amd64 windows-386 windows-amd64
+CMD = dhtsearch
+VERSION ?= $(shell git describe --tags --always)
+SRC = $(shell find . -type f -name '*.go')
+LDFLAGS = -ldflags="-w -s -X=main.version=$(VERSION)"
+BINARIES = $(patsubst %,$(CMD)-%-v$(VERSION), $(TARGETS))
+
+.DEFAULT_GOAL := help
+
+release: check-env $(BINARIES) ## Build all binaries
+
+build: check-env ## Build binary for current platform
+ cd cmd && go build -o ../$(CMD) $(LDFLAGS)
+
+standalone : TAGS = sqlite
+
+$(BINARIES): $(SRC)
+ env GOOS=`echo $@ |cut -d'-' -f2` GOARCH=`echo $@ |cut -d'-' -f3 |cut -d'.' -f1` cd cmd && go build -o ../$@ $(LDFLAGS)
+
+test: ## Run tests and create coverage report
+ go test -short -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
lint:
@for file in $$(find . -name 'vendor' -prune -o -type f -name '*.go'); do golint $$file; done
-clean:
- rm -f $(BINARY)
+clean: check-env ## Clean up temp files and binaries
+ rm -f $(BINARIES)
rm -rf coverage*
-.PHONY: install build test lint clean
+check-env:
+ifndef VERSION
+ $(error VERSION is undefined)
+endif
+
+help:
+ @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) |sort |awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
+
+.PHONY: help install build test lint clean