|
| 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 |
1 | 10 | SHELL=sh
|
2 | 11 |
|
3 | 12 | # Go variables
|
@@ -94,12 +103,25 @@ test:
|
94 | 103 | test-coverage-report:
|
95 | 104 | go tool cover -func=$(GO_COVERAGE_OUTPUT) -o=$(GO_COVERAGE_REPORT)
|
96 | 105 |
|
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 | + |
99 | 125 |
|
100 | 126 | .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