2000-11-30 00:06:29

by NeilBrown

[permalink] [raw]
Subject: PATCH - kbuild documentation.


Linus,
I thought I would document what I had learnt about Makefiles in
making the initialisation of drivers/md work better.

This patch (minus a few typos that I have since found and corrected)
was blessed by Michael Chastain on linux-kbuild.

Ofcourse, running "make vmlinux" doesn't convert documentation
patches into changes in a running kernel like it does for code
patches, so:

Linux Developers:
Please apply this patch to your brain. It works for me, bit if you
get a cerebral Oops, or a live-lock (hopefully no deadlock!!), please
send me a brain-dump and I will try to fix the problem :-)

NeilBrown




--- ./Documentation/kbuild/makefiles.txt 2000/11/29 20:44:19 1.1
+++ ./Documentation/kbuild/makefiles.txt 2000/11/29 23:27:10 1.2
@@ -32,6 +32,8 @@
7.6 Compilation flags
7.7 Miscellaneous variables
8 New-style variables
+ 8.1 New variables
+ 8.2 Converting to old-style
9 Compatibility with Linux Kernel 2.2
10 Credits

@@ -521,6 +523,8 @@
old-style variables. This is because Rules.make processes only the
old-style variables.

+See section 8.2 ("Converting to old-style") for examples.
+


--- 6.4 Rules.make section
@@ -679,6 +683,25 @@
options still control whether or not its $(O_TARGET) goes into
vmlinux. See the $(M_OBJS) example below.

+ Sometimes the ordering of all $(OX_OBJS) files before all
+ $(O_OBJS) files can be a problem, particularly if both
+ $(O_OBJS) files and $(OX_OBJS) files contain __initcall
+ declarations where order is important. To avoid this imposed
+ ordering, the use of $(OX_OBJS) can be dropped altogether and
+ $(MIX_OBJS) used instead.
+
+ If this approach is used, then:
+ - All objects to be linked into vmlinux should be listed in
+ $(O_OBJS) in the desired order.
+ - All objects to be created as modules should be listed in
+ $(M_OBJS)
+ - All objects that export symbols should also be listed in
+ $(MIX_OBJS).
+
+ This has the same effect as maintaining the
+ exported/non-exported split, except that there is more control
+ over the ordering of object files in vmlinux.
+


--- 7.3 Library file goals
@@ -865,6 +888,14 @@
$(LD) -r -o $@ $(sb-objs)


+ As is mentioned in section 7.2 ("Object file goals"),
+ $(MIX_OBJS) can also be used simply to list all objects that
+ export any symbols. If this approach is taken, then
+ $(O_OBJS), $(L_OBJS), $(M_OBJS) and $(MI_OBJS) should simply
+ lists all of the vmlinux object files, library object files,
+ module object files and intermediate module files
+ respectively. Duplication between $(MI_OBJS) and $(MIX_OBJS)
+ is not a problem.

--- 7.6 Compilation flags

@@ -993,6 +1024,8 @@
people define most variables using "new style" but then fall back to
"old style" for a few lines.

+--- 8.1 New variables
+
obj-y obj-m obj-n obj-

These variables replace $(O_OBJS), $(OX_OBJS), $(M_OBJS),
@@ -1184,6 +1217,41 @@
This means nls should be added to (subdir-y) and $(subdir-m) if
CONFIG_NFS = y.

+--- 8.2 Converting to old-style
+
+ The following example is taken from ./drivers/usb/Makefile.
+ Note that this uses MIX_OBJS to avoid the need for OX_OBJS and
+ MX_OBJS and thus to maintain the ordering of objects in $(obj-y)
+
+ # Translate to Rules.make lists.
+ multi-used := $(filter $(list-multi), $(obj-y) $(obj-m))
+ multi-objs := $(foreach m, $(multi-used), $($(basename $(m))-objs))
+ active-objs := $(sort $(multi-objs) $(obj-y) $(obj-m))
+
+ O_OBJS := $(obj-y)
+ M_OBJS := $(obj-m)
+ MIX_OBJS := $(filter $(export-objs), $(active-objs))
+
+ An example for libraries from drivers/acorn/scsi/Makefile:
+
+ # Translate to Rules.make lists.
+
+ L_OBJS := $(filter-out $(export-objs), $(obj-y))
+ LX_OBJS := $(filter $(export-objs), $(obj-y))
+ M_OBJS := $(sort $(filter-out $(export-objs), $(obj-m)))
+ MX_OBJS := $(sort $(filter $(export-objs), $(obj-m)))
+
+ As ordering is not so important in libraries, this still uses
+ LX_OBJS and MX_OBJS, though (presumably) it could be changed to
+ use MIX_OBJS as follows:
+
+ active-objs := $(sort $(obj-y) $(obj-m))
+ L_OBJS := $(obj-y)
+ M_OBJS := $(obj-m)
+ MIX_OBJS := $(filter $(export-objs), $(active-objs))
+
+
+ which is clearly shorted and arguably clearer.

=== 9 Compatibility with Linux Kernel 2.2


2000-11-30 07:02:01

by Russell King

[permalink] [raw]
Subject: Re: PATCH - kbuild documentation.

Neil Brown writes:
> + An example for libraries from drivers/acorn/scsi/Makefile:

This is no longer true; you'll have to find another example.

> + As ordering is not so important in libraries, this still uses
> + LX_OBJS and MX_OBJS, though (presumably) it could be changed to
> + use MIX_OBJS as follows:
> +
> + active-objs := $(sort $(obj-y) $(obj-m))
> + L_OBJS := $(obj-y)
> + M_OBJS := $(obj-m)
> + MIX_OBJS := $(filter $(export-objs), $(active-objs))
> +
> + which is clearly shorted and arguably clearer.

What if you have

obj-$(CONFIG_FOO) += foo.o foobar.o
obj-$(CONFIG_BAR) += bar.o foobar.o

and CONFIG_FOO=y and CONFIG_BAR=m? What about CONFIG_FOO=y and
CONFIG_BAR=y? Do we still support this method? If not, what is the
recommended way of doing this sort of stuff?
_____
|_____| ------------------------------------------------- ---+---+-
| | Russell King [email protected] --- ---
| | | | http://www.arm.linux.org.uk/personal/aboutme.html / / |
| +-+-+ --- -+-
/ | THE developer of ARM Linux |+| /|\
/ | | | --- |
+-+-+ ------------------------------------------------- /\\\ |

2000-11-30 09:11:59

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [KBUILD] Re: PATCH - kbuild documentation.

On Thu, Nov 30, 2000 at 12:36:28AM +0000, Russell King wrote:
> and CONFIG_FOO=y and CONFIG_BAR=m? What about CONFIG_FOO=y and
> CONFIG_BAR=y? Do we still support this method? If not, what is the
> recommended way of doing this sort of stuff?

To do this you need to extend the scheme a little bit. I once wrote a
patch that implements this scheme in a common place -
$(TOPDIR)/Makefile.inc - and sent it to Linux for inclusion, but it was
not applied. IF you are interested I could try to search it...

Christoph

--
Always remember that you are unique. Just like everyone else.


2000-11-30 10:20:11

by NeilBrown

[permalink] [raw]
Subject: Re: PATCH - kbuild documentation.

On Thursday November 30, [email protected] wrote:
> Neil Brown writes:
> > + An example for libraries from drivers/acorn/scsi/Makefile:
>
> This is no longer true; you'll have to find another example.
>
> > + As ordering is not so important in libraries, this still uses
> > + LX_OBJS and MX_OBJS, though (presumably) it could be changed to
> > + use MIX_OBJS as follows:
> > +
> > + active-objs := $(sort $(obj-y) $(obj-m))
> > + L_OBJS := $(obj-y)
> > + M_OBJS := $(obj-m)
> > + MIX_OBJS := $(filter $(export-objs), $(active-objs))
> > +
> > + which is clearly shorted and arguably clearer.
>
> What if you have
>
> obj-$(CONFIG_FOO) += foo.o foobar.o
> obj-$(CONFIG_BAR) += bar.o foobar.o
>
> and CONFIG_FOO=y and CONFIG_BAR=m? What about CONFIG_FOO=y and
> CONFIG_BAR=y? Do we still support this method? If not, what is the
> recommended way of doing this sort of stuff?

The first case (y and m) would be satisifed by

M_OBJS := $(filter-out $(O_OBJS) $(L_OBJS), $(obj-m))

but the second (y and y) wouldn't. If you want to be allowed to
mention a .o file twice, and still maintain ordering, you are asking a lot.
You could try:

obj-$(CONFIG_FOO)$(CONFIG_BAR) += foobar.o
obj-$(CONFIG_FOO) += foo.o foobar.o
obj-$(CONFIG_BAR) += bar.o foobar.o

O_OBJS := $(obj-y) $(obj-ym) $(obj-my)
M_OBJS := $(obj-m) $(obj-mm)

But that it starting to look ugly.

Maybe:
O_OBJS := $(shell echo $(obj-y) | tr ' ' '\n' | cat -n | sort -u +1 | sort -n | cut -f2)

But I don't think that is much better.

There is room for other good ideas here if this is a real need.

NeilBrown

(I love Unix pipelines)

> _____
> |_____| ------------------------------------------------- ---+---+-
> | | Russell King [email protected] --- ---
> | | | | http://www.arm.linux.org.uk/personal/aboutme.html / / |
> | +-+-+ --- -+-
> / | THE developer of ARM Linux |+| /|\
> / | | | --- |
> +-+-+ ------------------------------------------------- /\\\ |
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> Please read the FAQ at http://www.tux.org/lkml/

2000-11-30 12:17:26

by Peter Samuelson

[permalink] [raw]
Subject: Re: [KBUILD] Re: PATCH - kbuild documentation.


[Neil Brown <[email protected]>]
> O_OBJS := $(shell echo $(obj-y) | tr ' ' '\n' | cat -n | sort -u +1 | sort -n | cut -f2)

Clever. I like pipelines too. Here is a one-fork equivalent, untested:

nodups = $(shell g=' '; for f in $(1); do case $$g in (*" $$f "*) ;; (*) g="$$g$$f "; echo $$f; esac; done)

O_OBJS := $(call nodups,$(obj-y))

Peter