* [LTP] [PATCH v3] mk/module.mk: add Makefile to build kernel modules
@ 2013-09-20 11:22 Alexey Kodanev
2013-09-25 17:02 ` chrubis
0 siblings, 1 reply; 4+ messages in thread
From: Alexey Kodanev @ 2013-09-20 11:22 UTC (permalink / raw)
To: ltp-list; +Cc: vasily.isaenko, Alexey Kodanev
Makefile example:
top_srcdir ?= ../../../..
include $(top_srcdir)/include/mk/testcases.mk
REQ_VERSION_MAJOR := 2
REQ_VERSION_PATCH := 6
MODULE_NAMES := Module01 Module02 ...
MAKE_TARGETS := test01 test02 ...
include $(top_srcdir)/include/mk/module.mk
include $(top_srcdir)/include/mk/generic_leaf_target.mk
Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
include/mk/module.mk | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 69 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..9304e4c
--- /dev/null
+++ b/include/mk/module.mk
@@ -0,0 +1,69 @@
+# 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 <alexey.kodanev@oracle.com>
+#
+# Include it to build kernel modules.
+# MODULE_NAMES, REQ_VERSION_MAJOR and REQ_VERSION_PATCH must be defined
+# beforehand.
+#
+
+ifneq ($(KERNELRELEASE),)
+
+obj-m := $(addsuffix .o, $(MODULE_NAMES))
+
+else
+
+# prerequisites
+$(if $(ENV_PRE_LOADED),,\
+ $(error You must load env_pre.mk before including this file))
+
+$(if $(MODULE_NAMES),,\
+ $(error You must define MODULE_NAMES))
+
+$(if $(REQ_VERSION_MAJOR),,\
+ $(error You must define REQ_VERSION_MAJOR))
+
+$(if $(REQ_VERSION_PATCH),,\
+ $(error You must define REQ_VERSION_MINOR))
+
+export ENV_PRE_LOADED
+export top_srcdir := $(abs_srcdir)/$(top_srcdir)
+
+ifeq ($(MAKECMDGOALS),clean)
+SKIP := 0
+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 $$?)
+
+ifeq ($(SKIP),0)
+MODULE_FILES := $(addsuffix .ko, $(MODULE_NAMES))
+MAKE_TARGETS += $(if $(filter $(MAKECMDGOALS),install),\
+ $(wildcard $(MODULE_FILES)),$(MODULE_FILES))
+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
+
+endif
--
1.7.1
------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13.
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v3] mk/module.mk: add Makefile to build kernel modules
2013-09-20 11:22 [LTP] [PATCH v3] mk/module.mk: add Makefile to build kernel modules Alexey Kodanev
@ 2013-09-25 17:02 ` chrubis
[not found] ` <52497EF2.50204@oracle.com>
0 siblings, 1 reply; 4+ messages in thread
From: chrubis @ 2013-09-25 17:02 UTC (permalink / raw)
To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list
Hi!
> Makefile example:
>
> top_srcdir ?= ../../../..
>
> include $(top_srcdir)/include/mk/testcases.mk
>
> REQ_VERSION_MAJOR := 2
> REQ_VERSION_PATCH := 6
>
> MODULE_NAMES := Module01 Module02 ...
> MAKE_TARGETS := test01 test02 ...
>
> include $(top_srcdir)/include/mk/module.mk
> include $(top_srcdir)/include/mk/generic_leaf_target.mk
Looks good.
> ---
> include/mk/module.mk | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 69 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..9304e4c
> --- /dev/null
> +++ b/include/mk/module.mk
> @@ -0,0 +1,69 @@
> +# 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 <alexey.kodanev@oracle.com>
> +#
> +# Include it to build kernel modules.
> +# MODULE_NAMES, REQ_VERSION_MAJOR and REQ_VERSION_PATCH must be defined
> +# beforehand.
> +#
> +
> +ifneq ($(KERNELRELEASE),)
> +
> +obj-m := $(addsuffix .o, $(MODULE_NAMES))
> +
> +else
> +
> +# prerequisites
> +$(if $(ENV_PRE_LOADED),,\
> + $(error You must load env_pre.mk before including this file))
> +
> +$(if $(MODULE_NAMES),,\
> + $(error You must define MODULE_NAMES))
> +
> +$(if $(REQ_VERSION_MAJOR),,\
> + $(error You must define REQ_VERSION_MAJOR))
> +
> +$(if $(REQ_VERSION_PATCH),,\
> + $(error You must define REQ_VERSION_MINOR))
> +
> +export ENV_PRE_LOADED
> +export top_srcdir := $(abs_srcdir)/$(top_srcdir)
I fail to see what are these two exports are for.
For what reason do we need to redefine top_srcdir?
> +ifeq ($(MAKECMDGOALS),clean)
> +SKIP := 0
> +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 $$?)
> +
> +ifeq ($(SKIP),0)
> +MODULE_FILES := $(addsuffix .ko, $(MODULE_NAMES))
> +MAKE_TARGETS += $(if $(filter $(MAKECMDGOALS),install),\
> + $(wildcard $(MODULE_FILES)),$(MODULE_FILES))
> +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
I think that we don't have to ignore the retval from 'rm -rf' as the -f
causes the rm ignore nonexistent files anyway. But that is minor.
> +endif
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
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=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v3] mk/module.mk: add Makefile to build kernel modules
[not found] ` <52497EF2.50204@oracle.com>
@ 2013-09-30 15:46 ` chrubis
[not found] ` <5249A54A.2000404@oracle.com>
0 siblings, 1 reply; 4+ messages in thread
From: chrubis @ 2013-09-30 15:46 UTC (permalink / raw)
To: alexey.kodanev; +Cc: vasily.isaenko, ltp-list
Hi!
> >> Makefile example:
> >>
> >> top_srcdir ?= ../../../..
> >>
> >> include $(top_srcdir)/include/mk/testcases.mk
> >>
> >> REQ_VERSION_MAJOR := 2
> >> REQ_VERSION_PATCH := 6
> >>
> >> MODULE_NAMES := Module01 Module02 ...
> >> MAKE_TARGETS := test01 test02 ...
> >>
> >> include $(top_srcdir)/include/mk/module.mk
> >> include $(top_srcdir)/include/mk/generic_leaf_target.mk
>
> I redefine top_srcdir to make it absolute because when "make" cd to
> kernel build directory and once again include LTP Makefile, the first
> include of env_pre.mk leads to non-existed file and kernel build stops
> with error. If top_srcdir absolute, no include errors in the kernel build.
>
> Actually we don't need this include of env_pre.mk in the kernel build
> system because it does nothing with the module build and usually it
> accomplished with the KERNELRELEASE variable or separate kbuild file.
> But to preserve the LTP Makefile API and also have a chance to build
> user-space tests, we include it and tell kernel build system that this
> one have already been loaded (exporting ENV_PRE_LOAD).
Hmm, I think that it may be more clear to put the linux kernel Makefile
part to the Makefile that is in the test directory, so that it will
became:
ifneq ($(KERNELRELEASE),)
obj-m := $(addsuffix .o, $(MODULE_NAMES))
else
top_srcdir ?= ../../../..
include $(top_srcdir)/include/mk/testcases.mk
REQ_VERSION_MAJOR := 2
REQ_VERSION_PATCH := 6
MAKE_TARGETS := test01 test02 ...
include $(top_srcdir)/include/mk/module.mk
include $(top_srcdir)/include/mk/generic_leaf_target.mk
endif
Which moves all the common code into module.mk and just leaves the
kernel recipe in the particular Makefile. That should guarantee that the
LTP build system and kernel build system stay separated and won't
interact. What do you think?
Or to use Kbuild file which should be preffered over Makefile,
unfortunately the documentation does not say which kernel version gets
the support for Kbuild for extrenal modules, so if it's a recent feature
we must go with the Makefile.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
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=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v3] mk/module.mk: add Makefile to build kernel modules
[not found] ` <5249A54A.2000404@oracle.com>
@ 2013-09-30 16:40 ` chrubis
0 siblings, 0 replies; 4+ messages in thread
From: chrubis @ 2013-09-30 16:40 UTC (permalink / raw)
To: alexey.kodanev; +Cc: vasily.isaenko, ltp-list
Hi!
> > Hmm, I think that it may be more clear to put the linux kernel Makefile
> > part to the Makefile that is in the test directory, so that it will
> > became:
> >
> > ifneq ($(KERNELRELEASE),)
> >
> > obj-m := $(addsuffix .o, $(MODULE_NAMES))
> >
> > else
> >
> > top_srcdir ?= ../../../..
> >
> > include $(top_srcdir)/include/mk/testcases.mk
> >
> > REQ_VERSION_MAJOR := 2
> > REQ_VERSION_PATCH := 6
> > MAKE_TARGETS := test01 test02 ...
> >
> > include $(top_srcdir)/include/mk/module.mk
> > include $(top_srcdir)/include/mk/generic_leaf_target.mk
> >
> > endif
> And "MODULE_NAMES := Module01 Module02" on the top of it, right?
Or directly written in the $(addsuffix ...) expression, or just write
the obj-m := foo.o there, since it's in one file it does not matter.
> > Or to use Kbuild file which should be preffered over Makefile,
> > unfortunately the documentation does not say which kernel version gets
> > the support for Kbuild for extrenal modules, so if it's a recent feature
> > we must go with the Makefile.
> >
> It can be made backward compatible with just the include of that file in
> the ifneq ($(KERNELRELEASE,)). But we have only one line, I don't think
> it necessary to do so.
Right.
I've looked into the kernel git log and the Kbuild documentation was
updated to mention the posibility to use Kbuild files around 2.6.33
which is still to late for us.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
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=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-09-30 16:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-20 11:22 [LTP] [PATCH v3] mk/module.mk: add Makefile to build kernel modules Alexey Kodanev
2013-09-25 17:02 ` chrubis
[not found] ` <52497EF2.50204@oracle.com>
2013-09-30 15:46 ` chrubis
[not found] ` <5249A54A.2000404@oracle.com>
2013-09-30 16:40 ` chrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.