# SPDX-License-Identifier: GPL-2.0
# SPDX-FileCopyrightText: Copyright (C) 2025 Advanced Micro Devices, Inc.

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

export KSRC
ifneq (,$(wildcard $(CURDIR)/kernel-gcc.sh))
	MAKE := . $(CURDIR)/kernel-gcc.sh && $(MAKE)
endif

# With '+', the sub-make joins the parent jobserver and parallelism
# specified on the top-level 'make -jN' is honored end-to-end.
define KBUILD_RULE
	+$(MAKE) -C $(KSRC) M=$(CURDIR) LLVM=$(LLVM) CONFIG_PDS_VDPA=n
endef

all: modules

include $(CURDIR)/linux_ver.mk

modules:
	$(KBUILD_RULE)

modules_install:
	$(KBUILD_RULE) modules_install

install: modules_install

clean:
	$(KBUILD_RULE) clean

pds_core:
	$(KBUILD_RULE) CONFIG_PDS_CORE=m

pds-vfio-pci: pds_core
	$(KBUILD_RULE) CONFIG_PDS_VFIO_PCI=m

pds_fwctl: pds_core
	$(KBUILD_RULE) CONFIG_FWCTL_PDS=m

pds_vdpa: pds_core
	+$(MAKE) -C $(KSRC) M=$(CURDIR) LLVM=$(LLVM) CONFIG_PDS_VDPA=m

.PHONY: all modules modules_install clean \
    pds_core pds-vfio-pci pds_fwctl pds_vdpa
