From: Cyril H. <su...@li...> - 2013-10-01 13:51:20
|
The branch, master, has been updated via f3b989fe1765ee5992a377c53b1f94990a033dfe (commit) via e05a5d3d174931707f3dfe9193f26b9c34497255 (commit) from 7f5bfb8ff65dfb8f910e25de65bf68291488924c (commit) - Log ----------------------------------------------------------------- commit f3b989fe1765ee5992a377c53b1f94990a033dfe Author: Cyril Hrubis <ch...@su...> Date: Tue Oct 1 15:37:02 2013 +0200 doc: Add documentation for module.mk The example Makefile is taken from commit message from the previous commit by Alexey Kodanev. Signed-off-by: Cyril Hrubis <ch...@su...> commit e05a5d3d174931707f3dfe9193f26b9c34497255 Author: Alexey Kodanev <ale...@or...> Date: Tue Oct 1 15:32:25 2013 +0400 mk/module.mk: add Makefile to build kernel modules Makefile example: ifneq ($(KERNELRELEASE),) obj-m := module01.o else top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk REQ_VERSION_MAJOR := 2 REQ_VERSION_PATCH := 6 MAKE_TARGETS := test01 test02 module01.ko include $(top_srcdir)/include/mk/module.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk endif Signed-off-by: Alexey Kodanev <ale...@or...> Reviewed-by: Cyril Hrubis <ch...@su...> ----------------------------------------------------------------------- Summary of changes: doc/build-system-guide.txt | 42 ++++++++++++++++++++ .../Makefile => include/mk/module.mk | 36 +++++++++------- 2 files changed, 62 insertions(+), 16 deletions(-) copy testcases/kernel/firmware/fw_load_kernel/Makefile => include/mk/module.mk (57%) diff --git a/doc/build-system-guide.txt b/doc/build-system-guide.txt index ea9966e..25ea158 100644 --- a/doc/build-system-guide.txt +++ b/doc/build-system-guide.txt @@ -73,6 +73,48 @@ include $(top_srcdir)/include/mk/env_pre.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk ------------------------------------------------------------------------------- +Kernel Modules +-------------- + +Some of the tests need to build kernel modules, happily LTP has +infrastructure for this. + +------------------------------------------------------------------------------- +ifneq ($(KERNELRELEASE),) + +obj-m := module01.o + +else + +top_srcdir ?= ../../../.. +include $(top_srcdir)/include/mk/testcases.mk + +REQ_VERSION_MAJOR := 2 +REQ_VERSION_PATCH := 6 +MAKE_TARGETS := test01 test02 module01.ko + +include $(top_srcdir)/include/mk/module.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk + +endif +------------------------------------------------------------------------------- + +This is example Makefile that allows you build kernel modules inside of LTP. +The prerequisities for the build are detected by the 'configure' script. + +The 'REQ_VERSION_MAJOR' and 'REQ_VERSION_PATCH' describe minimal kernel +version for which the build system tries to build the module. + +The buildsystem is also forward compatible with changes in Linux kernel +internal API so that if modul fails to build the failure is ignored both on +build and installation. If the userspace counterpart of the test fails to load +the module because the file does not exists, the test is skipped. + +Note the 'ifneq($(KERNELRELEASE),)', the reason it's there is that the +Makefile is executed twice, once by LTP build system and once by kernel +kbuild, see 'Documentation/kbuild/modules.txt' in the Linux kernel tree for +details on external module build. + Make Rules and Make Variables ----------------------------- diff --git a/testcases/kernel/firmware/fw_load_kernel/Makefile b/include/mk/module.mk similarity index 57% copy from testcases/kernel/firmware/fw_load_kernel/Makefile copy to include/mk/module.mk index 076d4ed..b903e8f 100644 --- a/testcases/kernel/firmware/fw_load_kernel/Makefile +++ b/include/mk/module.mk @@ -13,30 +13,34 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# Author: Alexey Kodanev <ale...@or...> +# +# Include it to build kernel modules. +# REQ_VERSION_MAJOR and REQ_VERSION_PATCH must be defined beforehand. +# -ifneq ($(KERNELRELEASE),) +$(if $(REQ_VERSION_MAJOR),,$(error You must define REQ_VERSION_MAJOR)) +$(if $(REQ_VERSION_PATCH),,$(error You must define REQ_VERSION_MINOR)) -ifdef CONFIG_FW_LOADER -obj-m := ltp_fw_load.o +ifneq ($(filter install clean,$(MAKECMDGOALS)),) +SKIP := 2 endif -else - -top_srcdir ?= ../../../.. -include $(top_srcdir)/include/mk/env_pre.mk +SKIP ?= $(shell [ "$(WITH_MODULES)" = yes ] && \ + [ $(LINUX_VERSION_MAJOR) -gt $(REQ_VERSION_MAJOR) ] || \ + [ $(LINUX_VERSION_MAJOR) -eq $(REQ_VERSION_MAJOR) -a \ + $(LINUX_VERSION_PATCH) -ge $(REQ_VERSION_PATCH) ]; echo $$?) -MAKE_TARGETS := ltp_fw_load.ko +ifneq ($(SKIP),0) +MAKE_TARGETS := $(filter-out %.ko, $(MAKE_TARGETS)) +MAKE_TARGETS += $(if $(filter 2,$(SKIP)),$(wildcard *.ko),) +endif # Ignoring the exit status of commands is done to be forward compatible with # kernel internal API changes. The user-space test will return TCONF, if it # doesn't find the module (i.e. it wasn't built either due to kernel-devel # missing or module build failure). -ltp_fw_load.ko: ltp_fw_load.c +%.ko: %.c -$(MAKE) -C $(LINUX_DIR) M=$(abs_srcdir) - -mv ltp_fw_load.ko ltp_fw_load.ko~ - -$(MAKE) -C $(LINUX_DIR) M=$(abs_srcdir) clean - -mv ltp_fw_load.ko~ ltp_fw_load.ko - -include $(top_srcdir)/include/mk/generic_leaf_target.mk - -endif + rm -rf *.mod.c *.o modules.order .tmp* .*.ko .*.cmd Module.symvers hooks/post-receive -- ltp |