module-playground: allow to cross-compile modules
authorLucas De Marchi <lucas.demarchi@intel.com>
Sat, 21 Feb 2015 05:22:54 +0000 (03:22 -0200)
committerLucas De Marchi <lucas.demarchi@intel.com>
Sat, 21 Feb 2015 13:40:27 +0000 (11:40 -0200)
This adds the needed infra to cross-compile modules so we can test them
in our testsuite. Right now we are only compiling mod-simple.ko for x86,
x86_64 and sparc64.

The makefiles are organized in a way it's easy to force a rebuild of a
module by calling the Makefile.arch directly and that allows the rule in
Makefile to not trigger in case we want to ship the modules
pre-compiled.

testsuite/module-playground/.gitignore
testsuite/module-playground/Makefile
testsuite/module-playground/Makefile.arch [new file with mode: 0644]
testsuite/populate-modules.sh

index dc6e6d8..436976f 100644 (file)
@@ -4,3 +4,7 @@
 .tmp_versions
 modules.order
 Module.symvers
+
+mod-simple-x86_64.c
+mod-simple-i386.c
+mod-simple-sparc64.c
index 215cc82..6d84523 100644 (file)
@@ -1,5 +1,7 @@
 ifneq ($(KERNELRELEASE),)
 # kbuild part of makefile
+
+ifneq ($(KMOD_TESTSUITE_ARCH_BUILD),1)
 obj-m := mod-simple.o
 
 # mod-foo depends on foo-x, and foo-x modules don't depend
@@ -25,14 +27,35 @@ obj-m += mod-fake-scsi-mod.o
 obj-m += mod-fake-cciss.o
 
 else
+# only build ARCH-specific module
+ifeq ($(ARCH),)
+    $(error ARCH must be set to a valid architecture)
+endif
+obj-m := mod-simple-$(ARCH).o
+endif
+
+else
 # normal makefile
 KDIR ?= /lib/modules/`uname -r`/build
 KVER ?= `uname -r`
 
-default:
+ARCH_SPECIFIC_MODULES := mod-simple-x86_64.ko mod-simple-i386.ko mod-simple-sparc64.ko
+
+default: modules arch-modules
+
+mod-simple-%.ko: mod-simple-%.c Makefile.arch
+       $(eval arch=$(patsubst mod-simple-%.ko,%,$@))
+       $(MAKE) KDIR=$(KDIR_$(arch)) ARCH=$(arch) CROSS_COMPILE=$(CROSS_COMPILE_$(arch)) -f Makefile.arch
+
+modules:
        $(MAKE) -C $(KDIR) M=$$PWD
 
+arch-modules: $(ARCH_SPECIFIC_MODULES)
+
 clean:
        $(MAKE) -C $(KDIR) M=$$PWD clean
+       $(MAKE) KDIR=$(KDIR_x86_64) ARCH=x86_64 CROSS_COMPILE=$(CROSS_COMPILE_x86_64) -f Makefile.arch clean
+       $(MAKE) KDIR=$(KDIR_i386) ARCH=i386 CROSS_COMPILE=$(CROSS_COMPILE_i386) -f Makefile.arch clean
+       $(MAKE) KDIR=$(KDIR_sparc64) ARCH=sparc64 CROSS_COMPILE=$(CROSS_COMPILE_sparc64) -f Makefile.arch clean
 
 endif
diff --git a/testsuite/module-playground/Makefile.arch b/testsuite/module-playground/Makefile.arch
new file mode 100644 (file)
index 0000000..47bd9cb
--- /dev/null
@@ -0,0 +1,14 @@
+ifeq ($(ARCH),)
+    $(error ARCH must be set to a valid architecture)
+endif
+
+default:
+       @cmp --quiet mod-simple.c mod-simple-$(ARCH).c || (     \
+               ln -sf mod-simple.c mod-simple-$(ARCH).c;       \
+               /bin/false                                      \
+       )
+       $(MAKE) -C $(KDIR_$(ARCH)) CROSS_COMPILE=$(CROSS_COMPILE_$(ARCH)) M=$$PWD KMOD_TESTSUITE_ARCH_BUILD=1
+
+clean:
+       $(MAKE) -C $(KDIR_$(ARCH)) CROSS_COMPILE=$(CROSS_COMPILE_$(ARCH)) M=$$PWD KMOD_TESTSUITE_ARCH_BUILD=1  clean
+       rm -f mod-simple-$(ARCH).c
index b61cbfa..938433d 100755 (executable)
@@ -37,6 +37,9 @@ map=(
     ["test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/block/cciss.ko"]="mod-fake-cciss.ko"
     ["test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/scsi/hpsa.ko"]="mod-fake-hpsa.ko"
     ["test-depmod/modules-order-compressed/lib/modules/4.4.4/kernel/drivers/scsi/scsi_mod.ko"]="mod-fake-scsi-mod.ko"
+    ["test-modinfo/mod-simple-i386.ko"]="mod-simple-i386.ko"
+    ["test-modinfo/mod-simple-x86_64.ko"]="mod-simple-x86_64.ko"
+    ["test-modinfo/mod-simple-sparc64.ko"]="mod-simple-sparc64.ko"
 )
 
 gzip_array=(