|
| 1 | +# clatd Makefile |
| 2 | +# |
| 3 | +# Copyright (C) 2025 Daniel Gröber <dxld@debian.org> |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: MIT |
| 6 | + |
1 | 7 | DESTDIR= |
2 | 8 | PREFIX=/usr |
3 | 9 | SYSCONFDIR=/etc |
| 10 | +BINDIR = $(PREFIX)/sbin |
| 11 | + |
| 12 | +SYSTEMCTL = systemctl |
| 13 | + |
| 14 | +CLATD = $(DESTDIR)$(BINDIR)/clatd |
| 15 | +MANPAGE = $(DESTDIR)$(PREFIX)/share/man/man8/clatd.8 |
| 16 | +SYSTEMD_SYSSERVICEDIR = $(DESTDIR)$(SYSCONFDIR)/systemd/system |
| 17 | +NM_DISPATCHER = $(DESTDIR)$(SYSCONFDIR)/NetworkManager/dispatcher.d/50-clatd |
| 18 | + |
| 19 | +all: clatd.8 |
| 20 | +.ONESHELL: |
4 | 21 |
|
5 | | -APT_GET:=$(shell which apt-get) |
6 | | -DNF_OR_YUM:=$(shell which dnf || which yum) |
7 | | -SYSTEMCTL:=$(shell which systemctl) |
8 | | -TAYGA:=$(shell which tayga) |
| 22 | +clatd.8: clatd.pod |
| 23 | + pod2man \ |
| 24 | + --name clatd \ |
| 25 | + --center "clatd - CLAT, SIIT-DC and IPv6-only with many XLAT engines" \ |
| 26 | + --section 8 \ |
| 27 | + $< $@ |
9 | 28 |
|
10 | | -all: |
| 29 | +start: install |
| 30 | + $(SYSTEMCTL) --system daemon-reload |
| 31 | + $(SYSTEMCTL) --system -f --now enable clatd.service |
| 32 | + |
| 33 | +stop: |
| 34 | + $(SYSTEMCTL) --system disable --now clatd.service |
| 35 | + |
| 36 | +uninstall: stop |
| 37 | + -rm $(SYSTEMD_SYSSERVICE)/clatd.service \ |
| 38 | + $(SYSTEMD_SYSSERVICE)/clatd@.service \ |
| 39 | + $(NM_DISPATCHER) |
11 | 40 |
|
12 | 41 | install: |
13 | | - # Install the main script |
14 | | - install -D -m0755 clatd $(DESTDIR)$(PREFIX)/sbin/clatd |
15 | | - # Install manual page if pod2man is installed |
16 | | - pod2man --name clatd --center "clatd - a CLAT implementation for Linux" --section 8 README.pod $(DESTDIR)$(PREFIX)/share/man/man8/clatd.8 && gzip -f9 $(DESTDIR)$(PREFIX)/share/man/man8/clatd.8 || echo "pod2man is required to generate manual page" |
17 | | - # Install systemd service file if applicable for this system |
18 | | - if test -x "$(SYSTEMCTL)" && test -d "$(DESTDIR)$(SYSCONFDIR)/systemd/system"; then install -m0644 scripts/clatd.systemd $(DESTDIR)$(SYSCONFDIR)/systemd/system/clatd.service && $(SYSTEMCTL) daemon-reload; fi |
19 | | - if test -e "$(DESTDIR)$(SYSCONFDIR)/systemd/system/clatd.service" && test ! -e "$(DESTDIR)$(SYSCONFDIR)/systemd/system/multi-user.target.wants/clatd.service"; then $(SYSTEMCTL) enable clatd.service; fi |
20 | | - # Install NetworkManager dispatcher script if applicable |
21 | | - if test -d $(DESTDIR)$(SYSCONFDIR)/NetworkManager/dispatcher.d; then install -m0755 scripts/clatd.networkmanager $(DESTDIR)$(SYSCONFDIR)/NetworkManager/dispatcher.d/50-clatd; fi |
| 42 | + install -D -m0755 clatd $(CLATD) |
| 43 | + install -D -m0644 clatd.8 $(MANPAGE) |
| 44 | + install -D -m0644 scripts/*.service $(SYSTEMD_SYSSERVICEDIR)/ |
| 45 | + install -D -m0755 scripts/clatd.networkmanager $(NM_DISPATCHER) |
| 46 | + |
| 47 | +DEB_PACKAGES = \ |
| 48 | + perl-base perl-modules libnet-ip-perl libnet-dns-perl iproute2 nftables tayga |
| 49 | + |
| 50 | +RPM_PACKAGES = \ |
| 51 | + perl perl-IPC-Cmd perl-Net-IP perl-Net-DNS perl-File-Temp iproute nftables |
22 | 52 |
|
23 | 53 | installdeps: |
24 | | - # .deb/apt-get based distros |
25 | | - if test -x "$(APT_GET)"; then $(APT_GET) -y install perl-base perl-modules libnet-ip-perl libnet-dns-perl iproute2 nftables tayga; fi |
26 | | - # .rpm/DNF/YUM-based distros |
27 | | - if test -x "$(DNF_OR_YUM)"; then $(DNF_OR_YUM) -y install perl perl-IPC-Cmd perl-Net-IP perl-Net-DNS perl-File-Temp iproute nftables; fi |
28 | | - # If necessary, try to install the TAYGA .rpm using dnf/yum. It is unfortunately not available in all .rpm based distros (in particular CentOS/RHEL). |
29 | | - if test -x "$(DNF_OR_YUM)" && test ! -x "$(TAYGA)"; then $(DNF_OR_YUM) -y install tayga || echo "ERROR: Failed to install TAYGA using dnf/yum, the package is probably not included in your distro. Try enabling the EPEL repo <URL: https://fedoraproject.org/wiki/EPEL> and try again, or install TAYGA <URL: http://www.litech.org/tayga> directly from source."; exit 1; fi |
| 54 | + @prog_exists () command -v $$@ >/dev/null 2>&1; |
| 55 | + { PKGS='$(DEB_PACKAGES)'; PKG=apt; prog_exists $$PKG; } || \ |
| 56 | + { PKGS='$(RPM_PACKAGES)'; PKG=dnf; prog_exists $$PKG; } || \ |
| 57 | + { PKGS='$(RPM_PACKAGES)'; PKG=yum; prog_exists $$PKG; } || \ |
| 58 | + { PKG=false; echo 'ERROR: Failed to detect system package manager.'>&2;} |
| 59 | + $(DRY) $$PKG -y $$PKGS |
0 commit comments