-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathMakefile
55 lines (42 loc) · 1.88 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
.DEFAULT_GOAL := all
EXECUTABLE=trubka
WINDOWS=./bin/windows_amd64
LINUX=./bin/linux_amd64
DARWIN=./bin/darwin_amd64
VERSION=$(shell git describe --tags --abbrev=0)
COMMIT=$(shell git rev-parse HEAD)
BUILT := $(shell date -u '+%a %d %b %Y %H:%M:%S GMT')
RUNTIME=$(shell go version | cut -d' ' -f 3)
prepare:
@echo Cleaning the bin directory
@rm -rfv ./bin/*
windows:
@echo Building Windows amd64 binaries
@env GOOS=windows GOARCH=amd64 go build -v -o $(WINDOWS)/$(EXECUTABLE).exe -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.runtimeVer=$(RUNTIME) -X 'main.built=$(BUILT)'" *.go
linux:
@echo Building Linux amd64 binaries
@env GOOS=linux GOARCH=amd64 go build -v -o $(LINUX)/$(EXECUTABLE) -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.runtimeVer=$(RUNTIME) -X 'main.built=$(BUILT)'" *.go
darwin:
@echo Building Mac amd64 binaries
@env GOOS=darwin GOARCH=amd64 go build -v -o $(DARWIN)/$(EXECUTABLE) -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.runtimeVer=$(RUNTIME) -X 'main.built=$(BUILT)'" *.go
## Builds the binaries.
build: windows linux darwin
@echo Version: $(VERSION)
test: ## Runs the unit tests.
@echo Running unit tests
@go test -v -race ./...
package:
@echo Creating the zip file
@tar -C $(DARWIN) -cvzf ./bin/$(EXECUTABLE)_darwin-$(VERSION).tar.gz $(EXECUTABLE)
@zip -j ./bin/$(EXECUTABLE)_windows-$(VERSION).zip $(WINDOWS)/$(EXECUTABLE).exe
@tar -C $(LINUX) -cvzf ./bin/$(EXECUTABLE)_linux-$(VERSION).tar.gz $(EXECUTABLE)
@echo Darwin Checksum:
@shasum -a 256 ./bin/$(EXECUTABLE)_darwin-$(VERSION).tar.gz
install:
@cp -pv $(DARWIN)/$(EXECUTABLE)
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
all: test prepare build package clean
clean: ## Removes the artifacts.
@rm -rf $(WINDOWS) $(LINUX) $(DARWIN)
.PHONY: all