-
Notifications
You must be signed in to change notification settings - Fork 16
/
Makefile
140 lines (124 loc) · 5.57 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
SHELL=/bin/bash
# Variables
BUILD_DIR ?= ./bin
CGO_ENABLED ?= 0
VERSION ?= $(shell awk -F'"' 'NR==2{print $$4}' ./release.json)
GOOS ?= unset
GOARCH ?= unset
## If GOOS=windows, then the executable is named cybr.exe
## and the compressed file is named cybr-cli_${VERSION}_${GOOS}_${GOARCH}.zip
ifeq (${GOOS}, windows)
TARGET_EXEC := cybr.exe
FILE_COMPRESSED := ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.zip
FILE_MD5 := ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.zip.md5
FILE_SHA256 := ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.zip.sha256
endif
TARGET_EXEC ?= cybr
FILE_MD5 ?= ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.md5
FILE_SHA256 ?= ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.sha256
FILE_COMPRESSED ?= ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.tar.gz
# Rules
## Version
version:
@echo "Current version: ${VERSION}"
@echo "GOOS: ${GOOS}"
@echo "GOARCH: ${GOARCH}"
## Build
build:
@echo "Building ${TARGET_EXEC} into ${BUILD_DIR}..."
@go build -o ${BUILD_DIR}/${TARGET_EXEC} .
## Test All
test-all: vet test
## Vet
vet:
@echo "Running go vet..."
@go vet ./...
## Test
test:
@echo "Running tests..."
@go test -v ./...
## Compile
compile:
### If GOOS is not defined, then throw an error
ifeq (${GOOS}, unset)
@echo "GOOS is undefined. If you ran 'make release', run './release.sh' instead."
@exit 1
endif
### If GOARCH is not defined, then throw an error
ifeq (${GOARCH}, unset)
@echo "GOARCH is undefined"
@exit 1
endif
@echo "Building ${TARGET_EXEC} into ${BUILD_DIR}/${GOOS}/${GOARCH}..."
@mkdir -p ${BUILD_DIR}/${GOOS}/${GOARCH}
@CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${BUILD_DIR}/${GOOS}/${GOARCH}/${TARGET_EXEC} .
## Install
install:
@echo "Installing ${TARGET_EXEC} into ${HOME}/bin..."
@mkdir -p ${HOME}/bin
@go build -o ${HOME}/bin/${TARGET_EXEC} .
## Release
release: compile
### If GOOS=darwin, then sign the executable
ifeq (${GOOS}, darwin)
@echo "Signing ${TARGET_EXEC} for ${GOOS} ${GOARCH}..."
@codesign --deep --force --options=runtime \
--sign "81176FD6CB590056A09A92B6FA9502A75F0BB3A1" \
--timestamp "${BUILD_DIR}/${GOOS}/${GOARCH}/${TARGET_EXEC}"
@mkdir -p ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli
endif
### If GOOS=windows, then compress the executable into a zip
ifeq (${GOOS}, windows)
@echo "Compressing ${TARGET_EXEC} into ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.zip..."
@zip -j ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.zip ${BUILD_DIR}/${GOOS}/${GOARCH}/${TARGET_EXEC}
@echo "Generating MD5 checksum for ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.zip..."
@md5 -qs ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.zip > ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.zip.md5
@echo "Generating SHA256 checksum for ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.zip..."
@shasum -a 256 ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.zip | cut -f1 -d' ' > ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.zip.sha256
### If GOOS is not windows, then compress the executable into a tar.gz
else
@echo "Compressing ${TARGET_EXEC} into ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.tar.gz..."
@tar -czf ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.tar.gz -C ${BUILD_DIR}/${GOOS}/${GOARCH} ${TARGET_EXEC}
@echo "Generating MD5 checksum for ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.tar.gz..."
@md5 -qs ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.tar.gz > ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.tar.gz.md5
@echo "Generating SHA256 checksum for ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.tar.gz..."
@shasum -a 256 ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.tar.gz | cut -f1 -d' ' > ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.tar.gz.sha256
endif
### If GOOS=darwin, then build, sign, and notarize a package installer
ifeq (${GOOS}, darwin)
@echo "Building package installer structure..."
@ditto "${BUILD_DIR}/${GOOS}/${GOARCH}/${TARGET_EXEC}" "${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli/usr/local/bin/${TARGET_EXEC}"
@echo "Building package installer..."
@pkgbuild --root "${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli" \
--identifier "com.github.infamousjoeg.cybr-cli" \
--version "${VERSION}" \
--sign "42510BD69E802006418644C21E229DC4461D6673" \
${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.pkg
@echo "Notarizing package installer..."
@xcrun notarytool submit ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.pkg \
--keychain-profile "notary-cybrcli" \
--wait
@echo "Stapling package installer..."
@xcrun stapler staple ${BUILD_DIR}/${GOOS}/${GOARCH}/cybr-cli_${VERSION}_${GOOS}_${GOARCH}.pkg
endif
## Generate Documentation
.PHONY: docs
docs:
@echo "Generating documentation..."
@go run docs/main.go
## Clean
clean: clean-build clean-install
clean-all: clean-build clean-install clean-compile
clean-build:
@echo "Cleaning ${BUILD_DIR}..."
@rm -f ${BUILD_DIR}/${TARGET_EXEC}
clean-install:
@echo "Cleaning ${HOME}/bin..."
@rm -f ${HOME}/bin/${TARGET_EXEC}
clean-compile:
@echo "Cleaning ${BUILD_DIR}/linux..."
@rm -rf ${BUILD_DIR}/linux/*
@echo "Cleaning ${BUILD_DIR}/darwin..."
@rm -rf ${BUILD_DIR}/darwin/*
@echo "Cleaning ${BUILD_DIR}/windows..."
@rm -rf ${BUILD_DIR}/windows/*