mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* PATCH  - kbuild documentation.
@ 2000-11-29 23:35 Neil Brown
  2000-11-30  0:36 ` Russell King
  0 siblings, 1 reply; 5+ messages in thread
From: Neil Brown @ 2000-11-29 23:35 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel, linux-kbuild


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
 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH  - kbuild documentation.
  2000-11-29 23:35 PATCH - kbuild documentation Neil Brown
@ 2000-11-30  0:36 ` Russell King
  2000-11-30  8:40   ` [KBUILD] " Christoph Hellwig
  2000-11-30  9:49   ` Neil Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Russell King @ 2000-11-30  0:36 UTC (permalink / raw)
  To: Neil Brown; +Cc: Linus Torvalds, linux-kernel, linux-kbuild

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        rmk@arm.linux.org.uk      --- ---
  | | | | 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 majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [KBUILD] Re: PATCH  - kbuild documentation.
  2000-11-30  0:36 ` Russell King
@ 2000-11-30  8:40   ` Christoph Hellwig
  2000-11-30  9:49   ` Neil Brown
  1 sibling, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2000-11-30  8:40 UTC (permalink / raw)
  To: Russell King; +Cc: Neil Brown, Linus Torvalds, linux-kernel, linux-kbuild

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.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH  - kbuild documentation.
  2000-11-30  0:36 ` Russell King
  2000-11-30  8:40   ` [KBUILD] " Christoph Hellwig
@ 2000-11-30  9:49   ` Neil Brown
  2000-11-30 11:46     ` [KBUILD] " Peter Samuelson
  1 sibling, 1 reply; 5+ messages in thread
From: Neil Brown @ 2000-11-30  9:49 UTC (permalink / raw)
  To: Russell King; +Cc: linux-kernel, linux-kbuild

On Thursday November 30, rmk@arm.linux.org.uk 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        rmk@arm.linux.org.uk      --- ---
>   | | | | 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 majordomo@vger.kernel.org
> Please read the FAQ at http://www.tux.org/lkml/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [KBUILD] Re: PATCH  - kbuild documentation.
  2000-11-30  9:49   ` Neil Brown
@ 2000-11-30 11:46     ` Peter Samuelson
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Samuelson @ 2000-11-30 11:46 UTC (permalink / raw)
  To: Neil Brown; +Cc: linux-kernel, linux-kbuild


[Neil Brown <neilb@cse.unsw.edu.au>]
> 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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-11-30 12:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-29 23:35 PATCH - kbuild documentation Neil Brown
2000-11-30  0:36 ` Russell King
2000-11-30  8:40   ` [KBUILD] " Christoph Hellwig
2000-11-30  9:49   ` Neil Brown
2000-11-30 11:46     ` [KBUILD] " Peter Samuelson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®