# SPDX-License-Identifier: GPL-2.0

ifneq ($(KERNELRELEASE),)
# kbuild part of makefile
include Kbuild

else
# regular makefile
KERNEL_VERSION ?= $(shell uname -r)
KERNEL_SRC ?= /lib/modules/$(KERNEL_VERSION)/build

.PHONY: default modules clean modules_install bsp_modules pfeng pfeng_clean pfeng_install headers_install

default: bsp_modules

bsp_modules:
	$(MAKE) -C $(KERNEL_SRC) M=$$PWD modules

modules: bsp_modules pfeng

clean: pfeng_clean
	$(MAKE) -C $(KERNEL_SRC) M=$$PWD clean

modules_install: bsp_modules pfeng_install
	$(MAKE) -C $(KERNEL_SRC) M=$$PWD modules_install

pfeng: bsp_modules
	$(MAKE) -C pfeng/linux-pfeng KERNELDIR=$(KERNEL_SRC)

pfeng_clean:
	$(MAKE) -C pfeng/linux-pfeng KERNELDIR=$(KERNEL_SRC) clean

pfeng_install: pfeng
	$(MAKE) -C pfeng/linux-pfeng KERNELDIR=$(KERNEL_SRC) modules_install

headers_install:
	mkdir -p $(INSTALL_HDR_PATH)/usr/src/kernels/$(KERNEL_VERSION)
	rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
		include $(INSTALL_HDR_PATH)/usr/src/kernels/$(KERNEL_VERSION)/
	mkdir -p $(INSTALL_HDR_PATH)/usr/include
	rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
		include/uapi/ $(INSTALL_HDR_PATH)/usr/include/

endif
