From 54b4ae14f85c444557d76386e922399a0bb44ff9 Mon Sep 17 00:00:00 2001 From: Coelacanthus Date: Sat, 27 May 2023 21:56:32 +0800 Subject: [PATCH] chore: refine Makefile with Makefile Conventions Users can now do the following: - use DESTDIR to specify another root dir - use PREFIX to specify another install path except for /usr/local, e.g. /usr for the system package. - load custom CFLAGS and LDFLAGS from environment variables - use CC to specify the C compiler These features are helpful to package it into Linux Distribution. Signed-off-by: Coelacanthus --- makefile | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/makefile b/makefile index 19f623d..8d6ba66 100644 --- a/makefile +++ b/makefile @@ -1,33 +1,35 @@ .DEFAULT_GOAL := all .PHONY: all clean install uninstall tncattach -compiler = gcc -flags = -Wall -std=gnu11 -static-libgcc +RM ?= rm +INSTALL ?= install +CC ?= gcc +CFLAGS ?= -Wall -std=gnu11 -static-libgcc +LDFLAGS ?= +PREFIX ?= /usr/local all: tncattach rebuild: clean all clean: @echo "Cleaning tncattach build..." - @rm -f tncattach + $(RM) -f tncattach tncattach: @echo "Making tncattach..." - @echo "Compiling with: ${compiler}" - ${compiler} ${flags} tncattach.c Serial.c TCP.c KISS.c TAP.c -o tncattach -Wall + @echo "Compiling with: $(CC)" + $(CC) $(CFLAGS) $(LDFLAGS) tncattach.c Serial.c TCP.c KISS.c TAP.c -o tncattach install: @echo "Installing tncattach..." - @chmod a+x tncattach - cp ./tncattach /usr/local/sbin/ + $(INSTALL) -d $(DESTDIR)/$(PREFIX)/bin + $(INSTALL) -Dm755 tncattach $(DESTDIR)/$(PREFIX)/bin/tncattach @echo "Installing man page..." - @mkdir -p /usr/local/man/man8 - @install -m 644 -o root -g root tncattach.8 /usr/local/man/man8/tncattach.8 - @echo "Updating mandb..." - @mandb -f /usr/local/man/man8/tncattach.8 2> /dev/null 1> /dev/null - @echo "Done" + gzip -9 tncattach.8 + $(INSTALL) -d $(DESTDIR)/$(PREFIX)/share/man/man8 + $(INSTALL) -Dm644 tncattach.8.gz $(DESTDIR)/$(PREFIX)/share/man/man8/tncattach.8.gz uninstall: @echo "Uninstalling tncattach" - rm /usr/local/sbin/tncattach - rm /usr/local/man/man8/tncattach.8 + $(RM) $(DESTDIR)/$(PREFIX)/bin/tncattach + $(RM) $(DESTDIR)/$(PREFIX)/share/man/man8/tncattach.8.gz