Skip to content

Commit 5b51391

Browse files
committed
build: follow GNU code standard
Signed-off-by: black-desk <me@black-desk.cn>
1 parent 8ac762d commit 5b51391

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

Makefile

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
DESTDIR?=
2+
prefix?=/usr/local
3+
bindir?=$(prefix)/bin
4+
libdir?=$(prefix)/lib
5+
libexecdir?=$(prefix)/libexec
6+
datarootdir?=$(prefix)/share
7+
INSTALL?=install
8+
INSTALL_PROGRAM?= $(INSTALL)
9+
INSTALL_DATA?= $(INSTALL) -m 644
110
SHELL=sh
211

312
# Go variables
@@ -94,12 +103,25 @@ test:
94103
test-coverage-report:
95104
go tool cover -func=$(GO_COVERAGE_OUTPUT) -o=$(GO_COVERAGE_REPORT)
96105

97-
PREFIX ?= /usr/local
98-
DESTDIR ?=
106+
.PHONY: install-bin
107+
install-bin:
108+
$(INSTALL_PROGRAM) cgtproxy "$(DESTDIR)$(bindir)"/cgtproxy
109+
110+
# List all paths that systemd will search for system level units using pkg-config
111+
systemd_system_unit_paths=$(subst :, , $(shell \
112+
pkg-config systemd --variable=systemd_system_unit_path))
113+
# Select the first path that is under $(libdir).
114+
systemd_system_unit_dir?=$(word 1, \
115+
$(filter $(libdir)%, $(systemd_system_unit_paths)))
116+
# If no path is found, use the default path, to make sure the unit can be found.
117+
ifeq ($(systemd_system_unit_dir),)
118+
systemd_system_unit_dir=$(shell \
119+
pkg-config systemd --variable=systemd_system_unit_dir)
120+
endif
121+
122+
install-systemd-system-unit:
123+
$(INSTALL_DATA) misc/systemd/cgtproxy.service "$(DESTDIR)$(systemd_system_unit_dir)"/cgtproxy.service
124+
99125

100126
.PHONY: install
101-
install:
102-
install -m755 -D cgtproxy \
103-
$(DESTDIR)$(PREFIX)/bin/cgtproxy
104-
install -m644 -D misc/systemd/cgtproxy.service \
105-
$(DESTDIR)$(PREFIX)/lib/systemd/system/cgtproxy.service
127+
install: install-bin install-systemd-system-unit

0 commit comments

Comments
 (0)