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 <[email protected]>
---
 include/mk/module.mk |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
 create mode 100644 include/mk/module.mk

diff --git a/include/mk/module.mk b/include/mk/module.mk
new file mode 100644
index 0000000..b903e8f
--- /dev/null
+++ b/include/mk/module.mk
@@ -0,0 +1,46 @@
+# Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# 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 <[email protected]>
+#
+# Include it to build kernel modules.
+# REQ_VERSION_MAJOR and REQ_VERSION_PATCH must be defined beforehand.
+#
+
+$(if $(REQ_VERSION_MAJOR),,$(error You must define REQ_VERSION_MAJOR))
+$(if $(REQ_VERSION_PATCH),,$(error You must define REQ_VERSION_MINOR))
+
+ifneq ($(filter install clean,$(MAKECMDGOALS)),)
+SKIP := 2
+endif
+
+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 $$?)
+
+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).
+%.ko: %.c
+       -$(MAKE) -C $(LINUX_DIR) M=$(abs_srcdir)
+       rm -rf *.mod.c *.o modules.order .tmp* .*.ko .*.cmd Module.symvers
-- 
1.7.1


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to