-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
83 lines (70 loc) · 2.2 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
.DEFAULT_GOAL := help
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
VERSION := $(shell cat ./VERSION)
BUILDFLAGS=-s -w -X 'main.Version=${VERSION}'
PROJECTNAME=anwag
GOENV=CGO_ENABLED=0 GOPRIVATE="github.com/app-nerds/*" GONOPROXY="github.com/app-nerds/*"
GC=${GOENV} go build -ldflags="${BUILDFLAGS}" -mod=mod -o ${PROJECTNAME}
ifeq ($(OS),Windows_NT)
GOOS=windows
EXENAME=${PROJECTNAME}.exe
ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
GOARCH=amd64
else
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
GOARCH=amd64
endif
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
GOARCH=x86
endif
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
GOOS=linux
EXENAME=${PROJECTNAME}
endif
ifeq ($(UNAME_S),Darwin)
EXENAME=${PROJECTNAME}
GOOS=darwin
endif
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
GOARCH=amd64
endif
ifneq ($(filter %86,$(UNAME_P)),)
GOARCH=x86
endif
ifneq ($(filter arm%,$(UNAME_P)),)
GOARCH=arm64
endif
endif
#
# Build tasks
#
run: ## Run the app
go run .
build-windows: ## Create a compiled Windows binary
GOOS=windows GOARCH=amd64 ${GC}.exe
build-mac: ## Create a compiled MacOS binary (arm64)
GOOS=darwin GOARCH=arm64 ${GC}
build-mac-amd: ## Create a compiled MacOS binary (amd64)
GOOS=darwin GOARCH=amd64 ${GC}
build-linux: ## Create a compiled Linux binary (amd64)
GOOS=linux GOARCH=amd64 ${GC}
build: ## Automatically determine OS and Architecture, and build an executable
GOOS=${GOOS} GOARCH=${GOARCH} ${GC}
build-all: ## Build Windows, Linux, Mac
GOOS=windows GOARCH=amd64 ${GC}-windows-${VERSION}.exe
GOOS=darwin GOARCH=arm64 ${GC}-darwin-${VERSION}
GOOS=darwin GOARCH=amd64 ${GC}-darwin-amd64-${VERSION}
GOOS=linux GOARCH=amd64 ${GC}-linux-${VERSION}
package: ## Package executables into a ZIP file
zip ./${PROJECTNAME}-linux-amd64-${VERSION}.zip ./*linux*
zip ./${PROJECTNAME}-windows-amd64-${VERSION}.zip ./*windows*
zip ./${PROJECTNAME}-darwin-${VERSION}.zip ./*darwin*
install: build ## Create a symlink to this executable in /usr/local/bin
rm /usr/local/bin/${EXENAME}
ln -s $(PWD)/${EXENAME} /usr/local/bin/${EXENAME}