-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
86 lines (74 loc) · 1.89 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
APP=wirelogd
PREFIX?=/usr/local
_INSTDIR=${DESTDIR}${PREFIX}
BINDIR?=${_INSTDIR}/bin
SHAREDIR?=${_INSTDIR}/share/${APP}
MANDIR?=${_INSTDIR}/share/man
GOOS?=$(shell go env GOOS)
GOARCH?=$(shell go env GOARCH)
VERSION = $(shell git describe --always --dirty)
.PHONY: all
all: build
.PHONY: setup
## setup: Setup go modules
setup:
go get -u all
go mod tidy
go mod vendor
.PHONY: build
## build: Build for the current target
build:
@echo "Building..."
env CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -ldflags="-s -w -X 'main.version=${VERSION}'" -o build/${APP}-${GOOS}-${GOARCH} .
.PHONY: install
## install: Install the application
install:
@echo "Installing..."
install -Dm755 build/${APP}-${GOOS}-${GOARCH} ${BINDIR}/${APP}
install -Dm644 man/${APP}.1 ${MANDIR}/man1/${APP}.1
install -Dm644 contrib/config.json ${SHAREDIR}/config.json
install -Dm644 contrib/${APP}.service ${SHAREDIR}/${APP}.service
sed -i'' -e 's,/usr,${PREFIX},g' ${SHAREDIR}/${APP}.service
.PHONY: uninstall
## uninstall: Uninstall the application
uninstall:
@echo "Uninstalling..."
rm -f ${BINDIR}/${APP}
rm -f ${MANDIR}/man1/${APP}.1
rm -f ${SHAREDIR}/*
rmdir --ignore-fail-on-non-empty ${BINDIR}
rmdir --ignore-fail-on-non-empty ${SHAREDIR}
rmdir --ignore-fail-on-non-empty ${MANDIR}/man1
rmdir --ignore-fail-on-non-empty ${MANDIR}
.PHONY: lint
## lint: Run linters
lint:
@echo "Linting..."
go vet ./...
go fix ./...
staticcheck ./...
.PHONY: format
## format: Runs goimports on the project
format:
@echo "Formatting..."
go fmt ./...
.PHONY: test
## test: Runs go test
test:
@echo "Testing..."
go test ./...
.PHONY: run
## run: Runs go run
run:
go run -race ${APP}.go
.PHONY: clean
## clean: Cleans the binary
clean:
@echo "Cleaning..."
rm -rf build/
rm -rf dist/
.PHONY: help
## help: Print this help message
help:
@echo -e "Usage: \n"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'