From 60c2b6745d30a3e7507059dc2ec0ec38f9abb981 Mon Sep 17 00:00:00 2001 From: Joachim Foerster Date: Tue, 12 Oct 2021 19:17:25 +0200 Subject: [PATCH] modules/mqnic/: Fix and enhance Makefile - Apply "Shared Makefile" style as found in [1] - Especially but not only for cross compilation: - Accept commonly used variable KDIR to specify kernel build directory - Additionally accept KERNEL_SRC (instead of KDIR) as used by PetaLinux/Yocto - Route all usual external module targets through to Kbuild - Provide "install" target as shortcut for module installation - Use $(MAKE) as recommended in [2] [1] https://www.kernel.org/doc/html/latest/kbuild/modules.html, section 3.1 [2] https://www.gnu.org/software/make/manual/make.html#MAKE-Variable, section 5.7.1. Signed-off-by: Joachim Foerster --- modules/mqnic/Makefile | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/mqnic/Makefile b/modules/mqnic/Makefile index 5c9c542f2..4b6876fcc 100644 --- a/modules/mqnic/Makefile +++ b/modules/mqnic/Makefile @@ -1,3 +1,4 @@ +ifneq ($(KERNELRELEASE),) # object files to build obj-m += mqnic.o @@ -16,9 +17,22 @@ mqnic-y += mqnic_cq.o mqnic-y += mqnic_eq.o mqnic-y += mqnic_ethtool.o +else + +ifneq ($(KERNEL_SRC),) +# alternatively to variable KDIR accept variable KERNEL_SRC as used in +# PetaLinux/Yocto for example +KDIR ?= $(KERNEL_SRC) +endif + +KDIR ?= /lib/modules/$(shell uname -r)/build + all: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + $(MAKE) -C $(KDIR) M=$(shell pwd) modules -clean: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean +help modules modules_install clean: + $(MAKE) -C $(KDIR) M=$(shell pwd) $@ +install: modules_install + +endif