From 5f9ebd3c86a34bdd0150db9652c774d6e2f98d3a Mon Sep 17 00:00:00 2001 From: Andrew D'Angelo Date: Fri, 4 Aug 2023 20:22:30 -0500 Subject: [PATCH] Handle manual build with Makefile --- Makefile | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index a7589f1..0e3f9a6 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,44 @@ obj-m += sharp.o sharp-objs += src/main.o src/drm_iface.o src/params_iface.o src/ioctl_iface.o ccflags-y := -DDEBUG -g -std=gnu99 -Wno-declaration-after-statement -.PHONY: all clean +.PHONY: all clean install uninstall -all: - $(MAKE) -C '$(LINUX_DIR)' M='$(PWD)' modules +# LINUX_DIR is set by Buildroot, but not if running manually +ifeq ($(LINUX_DIR),) +LINUX_DIR := /lib/modules/$(shell uname -r)/build +endif + +BOOT_CONFIG_LINE := dtoverlay=sharp + +all: sharp.ko sharp.dtbo + +sharp.ko: src/*.c src/*.h + $(MAKE) -C '$(LINUX_DIR)' M='$(shell pwd)' modules + +sharp.dtbo: sharp.dts + dtc -@ -I dts -O dtb -W no-unit_address_vs_reg -o $@ $< + +install: sharp.ko sharp.dtbo + # Install kernel module + $(MAKE) -C '$(LINUX_DIR)' M='$(shell pwd)' modules_install + # Install device tree overlay + install -D -m 0644 sharp.dtbo /boot/overlays/ + # Add configuration line if it wasn't already there + grep -qxF '$(BOOT_CONFIG_LINE)' /boot/config.txt \ + || echo '$(BOOT_CONFIG_LINE)' >> /boot/config.txt + # Add auto-load module line if it wasn't already there + grep -qxF 'sharp' /etc/modules \ + || echo 'sharp' >> /etc/modules + # Rebuild dependencies + depmod -A + +uninstall: + # Remove auto-load module line and create a backup file + sed -i.save '/sharp/d' /etc/modules + # Remove configuration line and create a backup file + sed -i.save '/$(BOOT_CONFIG_LINE)/d' /boot/config.txt + # Remove device tree overlay + rm -f /boot/overlays/sharp.dtbo clean: - $(MAKE) -C '$(LINUX_DIR)' M='$(PWD)' clean + $(MAKE) -C '$(LINUX_DIR)' M='$(shell pwd)' clean