# SPDX-License-Identifier: GPL-2.0-or-later
#
# daedalus-v4l2 — out-of-tree kbuild for the Linux kernel V4L2
# stateless decoder shim. Forwards bitstream + controls to the
# daedalus-v4l2 userspace daemon via a chardev bridge.
#
# Build against the running kernel:
#   make
# Or against a specific kernel:
#   make KERNELDIR=/path/to/kernel/source
# Install (requires root):
#   sudo make install
# Clean:
#   make clean

obj-m := daedalus_v4l2.o
daedalus_v4l2-objs := daedalus_v4l2_main.o daedalus_v4l2_chardev.o

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

# Be strict: warnings are errors, kernel coding style enforced.
# include/ is for the shared kernel↔daemon wire protocol header.
ccflags-y := -Wall -Wextra -Wno-unused-parameter -I$(src)/../include

all:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

install: all
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
	depmod -a

clean:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) clean

# Run kernel checkpatch.pl against the source. Picks up the
# kernel-tree-installed checkpatch via the running kernel's
# build directory if present.
checkpatch:
	@if [ -x $(KERNELDIR)/scripts/checkpatch.pl ]; then \
		$(KERNELDIR)/scripts/checkpatch.pl --no-tree --strict -f *.c; \
	else \
		echo "checkpatch.pl not available at $(KERNELDIR)/scripts/"; \
		exit 1; \
	fi

.PHONY: all install clean checkpatch
