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 <CoelacanthusHex@gmail.com>
This commit is contained in:
parent
d9b3d2b6ae
commit
54b4ae14f8
30
makefile
30
makefile
|
@ -1,33 +1,35 @@
|
||||||
.DEFAULT_GOAL := all
|
.DEFAULT_GOAL := all
|
||||||
.PHONY: all clean install uninstall tncattach
|
.PHONY: all clean install uninstall tncattach
|
||||||
|
|
||||||
compiler = gcc
|
RM ?= rm
|
||||||
flags = -Wall -std=gnu11 -static-libgcc
|
INSTALL ?= install
|
||||||
|
CC ?= gcc
|
||||||
|
CFLAGS ?= -Wall -std=gnu11 -static-libgcc
|
||||||
|
LDFLAGS ?=
|
||||||
|
PREFIX ?= /usr/local
|
||||||
|
|
||||||
all: tncattach
|
all: tncattach
|
||||||
rebuild: clean all
|
rebuild: clean all
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo "Cleaning tncattach build..."
|
@echo "Cleaning tncattach build..."
|
||||||
@rm -f tncattach
|
$(RM) -f tncattach
|
||||||
|
|
||||||
tncattach:
|
tncattach:
|
||||||
@echo "Making tncattach..."
|
@echo "Making tncattach..."
|
||||||
@echo "Compiling with: ${compiler}"
|
@echo "Compiling with: $(CC)"
|
||||||
${compiler} ${flags} tncattach.c Serial.c TCP.c KISS.c TAP.c -o tncattach -Wall
|
$(CC) $(CFLAGS) $(LDFLAGS) tncattach.c Serial.c TCP.c KISS.c TAP.c -o tncattach
|
||||||
|
|
||||||
install:
|
install:
|
||||||
@echo "Installing tncattach..."
|
@echo "Installing tncattach..."
|
||||||
@chmod a+x tncattach
|
$(INSTALL) -d $(DESTDIR)/$(PREFIX)/bin
|
||||||
cp ./tncattach /usr/local/sbin/
|
$(INSTALL) -Dm755 tncattach $(DESTDIR)/$(PREFIX)/bin/tncattach
|
||||||
@echo "Installing man page..."
|
@echo "Installing man page..."
|
||||||
@mkdir -p /usr/local/man/man8
|
gzip -9 tncattach.8
|
||||||
@install -m 644 -o root -g root tncattach.8 /usr/local/man/man8/tncattach.8
|
$(INSTALL) -d $(DESTDIR)/$(PREFIX)/share/man/man8
|
||||||
@echo "Updating mandb..."
|
$(INSTALL) -Dm644 tncattach.8.gz $(DESTDIR)/$(PREFIX)/share/man/man8/tncattach.8.gz
|
||||||
@mandb -f /usr/local/man/man8/tncattach.8 2> /dev/null 1> /dev/null
|
|
||||||
@echo "Done"
|
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
@echo "Uninstalling tncattach"
|
@echo "Uninstalling tncattach"
|
||||||
rm /usr/local/sbin/tncattach
|
$(RM) $(DESTDIR)/$(PREFIX)/bin/tncattach
|
||||||
rm /usr/local/man/man8/tncattach.8
|
$(RM) $(DESTDIR)/$(PREFIX)/share/man/man8/tncattach.8.gz
|
||||||
|
|
Loading…
Reference in New Issue