randpup.git

Makefile

espurr
# randpup - ngram text generator kernel module
# Copyright (C) 2025 ArcNyxx
# see LICENCE.MIT file for licensing information

# kbuild and make portions separate
# see <https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree
# /Documentation/kbuild/modules.rst>
ifneq ($(KERNELRELEASE),)

obj-m := randpup.o
randpup-y := act.o kernel.o ngram.o util.o

else

KDIR ?= /lib/modules/`uname -r`/build

include config.mk

SRC = act.c ngram.c user.c util.c
HED = act.h ngram.h util.h
OBJ = $(SRC:.c=.o)

all: clean randpup

$(OBJ): config.mk $(HED) ngram.c

ngram.c: ngram.py
	./ngram.py >$@

.c.o:
	$(CC) $(CFLAGS) -c $<

randpup-us: clean $(OBJ)
	$(CC) $(OBJ) -o randpup $(LDFLAGS)

randpup-km: clean ngram.c
	$(MAKE) -C $(KDIR) M=$$PWD

randpup: randpup-us randpup-km

clean:
	rm -f randpup $(OBJ) ngram.c
	$(MAKE) -C $(KDIR) M=$$PWD clean

install-us: randpup-us
	mkdir -p $(PREFIX)/bin
	cp -f randpup $(PREFIX)/bin
	chmod 755 $(PREFIX)/bin/randpup

install-km: randpup-km
	modinfo randpup.ko && rmmod randpup.ko
	insmod randpup.ko

install-man:
	mkdir -p $(MANPREFIX)/man1
	sed 's/VERSION/$(VERSION)/g' < randpup.1 > $(MANPREFIX)/man1/randpup.1
	sed 's/VERSION/$(VERSION)/g' < randpup.4 > $(MANPREFIX)/man4/randpup.4
	chmod 644 $(MANPREFIX)/man1/randpup.1 $(MANPREFIX)/man4/randpup.4

install: install-us install-km install-man

uninstall-us:
	rm -f $(PREFIX)/bin/randpup

uninstall-km:
	rmmod randpup.ko

uninstall-man:
	rm -f $(MANPREFIX)/man1/randpup.1 $(MANPREFIX)/man4/randpup.4

uninstall: uninstall-us uninstall-km uninstall-man

.PHONY: all clean install uninstall

endif