-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Makefile
64 lines (53 loc) · 1.99 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
# https://wiki.archlinux.org/title/Go_package_guidelines
#
BINDIR := /usr/bin
SHAREDIR := /usr/share
MANDIR := /usr/share/man/man1
DOCS_DIR := ./docs
OUT_DIR := ./bin
BINARY_NAME ?= egpu-switcher
OUT_BIN := ${OUT_DIR}/${BINARY_NAME}
VERSION ?= $(shell git describe --tags)
DATE := $(shell date -u +%Y%m%d.%H%M%S)
ORIGIN ?= make
# GOFLAGS := -buildmode=pie \
# -trimpath \
# -mod=readonly \
# -modcacherw \
# -ldflags "-X github.com/hertg/egpu-switcher/internal/buildinfo.Version=${VERSION} -X github.com/hertg/egpu-switcher/internal/buildinfo.BuildTime=${DATE} -X github.com/hertg/egpu-switcher/internal/buildinfo.Origin=${ORIGIN} -linkmode external -extldflags \"${LDFLAGS}\""
all: build
build:
go build \
-ldflags "-X github.com/hertg/egpu-switcher/internal/buildinfo.Version=${VERSION} -X github.com/hertg/egpu-switcher/internal/buildinfo.BuildTime=${DATE} -X github.com/hertg/egpu-switcher/internal/buildinfo.Origin=${ORIGIN}" \
-o ${OUT_BIN}
@echo "binary compiled => ${OUT_BIN}"
clean:
rm -f ${OUT_BIN}
rm -fd ${OUT_DIR}
rm -rfd ${DOCS_DIR}
@echo "cleanup successful"
test:
go test ./...
lint:
go vet ./...
install:
@if [ ! -f ${OUT_BIN} ]; then\
echo "run 'build' command first";\
exit 1;\
fi
mkdir -p ${DESTDIR}${BINDIR}
cp ${OUT_BIN} ${DESTDIR}${BINDIR}/
@echo "binary installed at ${DESTDIR}${BINDIR}/${BINARY_NAME}"
${OUT_BIN} gendocs -o ${DOCS_DIR}
@echo "docs generated => ${DOCS_DIR}"
mkdir -p ${DESTDIR}${MANDIR}
cp docs/man/egpu-switcher*.1 ${DESTDIR}${MANDIR}/
rm -f ${DESTDIR}${MANDIR}/egpu-switcher*.1.gz
gzip ${DESTDIR}${MANDIR}/egpu-switcher*.1
@echo "manpages installed in ${DESTDIR}${MANDIR}"
uninstall:
egpu-switcher disable || echo "NOTE: unable to run 'egpu-switcher disable', maybe the egpu.service is still left on your system"
rm -f ${DESTDIR}${BINDIR}/egpu-switcher
@echo "removed binary at ${DESTDIR}${BINDIR}/egpu-switcher"
rm -f ${DESTDIR}${MANDIR}/egpu-switcher*.1.gz
@echo "removed manpages at ${DESTDIR}${MANDIR}/egpu-switcher*.1.gz"