obj-m := xr_usb_serial_common.o

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

# Pi 6.12+ rpt headers treat a spaced M= path as multiple modules and fail:
#   "building multiple external modules is not supported"
empty :=
space  := $(empty) $(empty)
src    := $(CURDIR)
ifneq (,$(findstring $(space),$(src)))
  POG422_BUILD_M ?= $(HOME)/.cache/pog422-xr-usb-serial-build
  $(shell mkdir -p "$(dir $(POG422_BUILD_M))" && rm -rf "$(POG422_BUILD_M)" && ln -sfn "$(CURDIR)" "$(POG422_BUILD_M)")
  src := $(POG422_BUILD_M)
endif

EXTRA_CFLAGS := -DDEBUG=0
# Bench: make HW_DEBUG=1  → Table-8 GPIO1/GPIO5 edge ring. Prod default 0.
HW_DEBUG ?= 0
EXTRA_CFLAGS += -DPOG422_HW_DEBUG=$(HW_DEBUG)

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

modules_install:
	$(MAKE) -C "$(KERNELDIR)" M="$(src)" modules_install

clean:
	rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions vtty

.PHONY: all modules_install clean
