forked from ncarlier/webhookd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
90 lines (71 loc) · 2.01 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
.SILENT :
export GO111MODULE=on
# App name
APPNAME=webhookd
# Go configuration
GOOS?=$(shell go env GOHOSTOS)
GOARCH?=$(shell go env GOHOSTARCH)
# Add exe extension if windows target
is_windows:=$(filter windows,$(GOOS))
EXT:=$(if $(is_windows),".exe","")
# Archive name
ARCHIVE=$(APPNAME)-$(GOOS)-$(GOARCH).tgz
# Executable name
EXECUTABLE=$(APPNAME)$(EXT)
# Extract version infos
PKG_VERSION:=github.com/ncarlier/$(APPNAME)/pkg/version
VERSION:=`git describe --always --dirty`
GIT_COMMIT:=`git rev-list -1 HEAD --abbrev-commit`
BUILT:=`date`
define LDFLAGS
-X '$(PKG_VERSION).Version=$(VERSION)' \
-X '$(PKG_VERSION).GitCommit=$(GIT_COMMIT)' \
-X '$(PKG_VERSION).Built=$(BUILT)'
endef
all: build
# Include common Make tasks
root_dir:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
makefiles:=$(root_dir)/makefiles
include $(makefiles)/help.Makefile
## Clean built files
clean:
-rm -rf release
.PHONY: clean
## Build executable
build:
-mkdir -p release
echo "Building: $(EXECUTABLE) $(VERSION) for $(GOOS)-$(GOARCH) ..."
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -o release/$(EXECUTABLE)
.PHONY: build
release/$(EXECUTABLE): build
## Run tests
test:
go test ./...
.PHONY: test
## Install executable
install: release/$(EXECUTABLE)
echo "Installing $(EXECUTABLE) to ${HOME}/.local/bin/$(EXECUTABLE) ..."
cp release/$(EXECUTABLE) ${HOME}/.local/bin/$(EXECUTABLE)
.PHONY: install
## Create Docker image
image:
echo "Building Docker image ..."
docker build --rm -t ncarlier/$(APPNAME) .
.PHONY: image
## Generate changelog
changelog:
standard-changelog --first-release
.PHONY: changelog
## Create archive
archive: release/$(EXECUTABLE)
echo "Creating release/$(ARCHIVE) archive..."
tar czf release/$(ARCHIVE) README.md LICENSE CHANGELOG.md -C release/ $(EXECUTABLE)
rm release/$(EXECUTABLE)
.PHONY: archive
## Create distribution binaries
distribution:
GOARCH=amd64 make build archive
GOARCH=arm64 make build archive
GOARCH=arm make build archive
GOOS=darwin make build archive
.PHONY: distribution