Debian Codegraph @

Makefile

raw
1 .PHONY: all build dev clean release test installdirs install uninstall install-service uninstall-service service-systemd regen-proto
2
3 VERSION := $(shell git describe --always --dirty --tags)
4 SHA := $(shell git rev-parse --short HEAD)
5 BRANCH := $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
6 BUILD := $(SHA)-$(BRANCH)
7 BINARY_NAME := mirrorbits
8 BINARY := bin/$(BINARY_NAME)
9 TARBALL := dist/mirrorbits-$(VERSION).tar.gz
10 TEMPLATES := templates/
11 ifneq (${DESTDIR}$(PREFIX),)
12 TEMPLATES = ${DESTDIR}$(PREFIX)/share/mirrorbits
13 endif
14 PREFIX ?= /usr/local
15 PACKAGE = github.com/etix/mirrorbits
16
17 LDFLAGS := -X $(PACKAGE)/core.VERSION=$(VERSION) -X $(PACKAGE)/core.BUILD=$(BUILD) -X $(PACKAGE)/config.TEMPLATES_PATH=${TEMPLATES}
18 GOFLAGS := -ldflags "$(LDFLAGS)"
19 GOFLAGSDEV := -race -ldflags "$(LDFLAGS) -X $(PACKAGE)/core.DEV=-dev"
20
21 GOPATH ?= $(HOME)/go
22
23 export PATH := $(GOPATH)/bin:$(PATH)
24
25 PKG_CONFIG ?= /usr/bin/pkg-config
26 SERVICEDIR_SYSTEMD ?= $(shell $(PKG_CONFIG) systemd --variable=systemdsystemunitdir)
27
28 all: build
29
30 regen-proto: rpc/rpc.proto
31 @ if ! which protoc > /dev/null; then \
32 echo "error: protoc not installed" >&2; \
33 exit 1; \
34 fi
35 go install github.com/golang/protobuf/[email protected] && \
36 rm -f rpc/rpc.pb.go && \
37 protoc -I rpc rpc/rpc.proto --go_out=plugins=grpc:rpc
38
39 build:
40 GO111MODULE=on go build $(GOFLAGS) -o $(BINARY) .
41
42 dev:
43 GO111MODULE=on go build $(GOFLAGSDEV) -o $(BINARY) .
44
45 clean:
46 @echo Cleaning workspace...
47 @rm -f $(BINARY)
48 @rm -f contrib/init/systemd/mirrorbits.service
49 @rm -dRf dist
50
51 release: $(TARBALL)
52
53 test:
54 GO111MODULE=on go test $(GOFLAGS) ./...
55
56 installdirs:
57 mkdir -p ${DESTDIR}${PREFIX}/{bin,share} ${DESTDIR}$(PREFIX)/share/mirrorbits
58
59 install: build installdirs install-service
60 # For the 'make install' to work with sudo it might be necessary to add
61 # the Go binary path to the 'secure_path' and add 'GOPATH' to 'env_keep'.
62 @cp -vf $(BINARY) ${DESTDIR}${PREFIX}/bin/
63 @cp -vf templates/* ${DESTDIR}$(PREFIX)/share/mirrorbits
64
65 uninstall: uninstall-service
66 @rm -vf ${DESTDIR}${PREFIX}/bin/$(BINARY_NAME)
67 @rm -vfr ${DESTDIR}$(PREFIX)/share/mirrorbits
68
69 ifeq (,${SERVICEDIR_SYSTEMD})
70 install-service:
71 uninstall-service:
72 else
73 install-service: service-systemd
74 install -Dm644 contrib/init/systemd/mirrorbits.service ${DESTDIR}${SERVICEDIR_SYSTEMD}/mirrorbits.service
75
76 uninstall-service:
77 @rm -vf ${DESTDIR}${SERVICEDIR_SYSTEMD}/mirrorbits.service
78
79 service-systemd:
80 @sed "s|##PREFIX##|$(PREFIX)|" contrib/init/systemd/mirrorbits.service.in > contrib/init/systemd/mirrorbits.service
81 endif
82
83 $(TARBALL): build
84 @echo Packaging release...
85 @mkdir -p tmp/mirrorbits
86 @cp -f $(BINARY) tmp/mirrorbits/
87 @cp -r templates tmp/mirrorbits/
88 @cp mirrorbits.conf tmp/mirrorbits/
89 @mkdir -p dist/
90 @tar -czf $@ -C tmp mirrorbits && echo release tarball has been created: $@
91 @rm -rf tmp
92