All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: Tom Bart <tbartcz@gmail.com>
Cc: linux-kbuild@vger.kernel.org
Subject: Re: KBuild question
Date: Wed, 2 Mar 2011 22:40:50 +0100	[thread overview]
Message-ID: <20110302214050.GA7324@merkur.ravnborg.org> (raw)
In-Reply-To: <AANLkTi=vPJ_TacWUswaS9Zc-2ji0Wn5GhF2M+EKExoME@mail.gmail.com>

On Wed, Mar 02, 2011 at 10:11:46PM +0100, Tom Bart wrote:
> Hello,
> I have spend some time analysing KBuild source files.
Sounds boring :-)

> However there is
> one thing that is not clear for me. In the main makefile I have found
> the following statement:
> 
> Most importantly: sub-Makefiles should only ever modify files in
> their own directory. If in some directory we have a dependency on
> a file in another dir (which doesn't happen often, but it's often
> unavoidable when linking the built-in.o targets which finally
> turn into vmlinux), we will call a sub make in that other dir, and
> after that we are sure that everything which is in that other dir
> is now up to date.
> 
> Kernel is build in a recursive manner. I understand that according to
> the citation firstly all dependencies between different directories
> are identified and then the sub-directory walk through process is
> started. Unfortunately I cannot fine where this functionality is
> implemented? Can somebody point me the right place or maybe my line of
> reasoning is simply wrong?

A typical kbuild makefile fragment looks like this:

obj-y += foo/
obj-y += bar.o

Which tell kbuild to visit foo/ and create a built-in.o there.
And then back and build bar.o.
Finally link bar.o + foo/built-in.o => built-in.o

From the above I think you already grasped this.


In Makefile.lib we process all these variables.
We need to build foo/ before we can link
built-in.o.
So we calculate subdir-obj-y which is the list of files
that are dependent on all directories.
And directories are listed in subdir-ym.

So we have something like:

obj-y        => foo/built-in.o bar.o
subdir-obj-y => foo/built-in.o
subdir-ym    => foo/

In Makefiles.build we then have:

    $(builtin-target): $(obj-y) FORCE
            $(call if_changed,link_o_target)

Which tell us to build all files listed in obj-y and then link built-in.o

    $(sort $(subdir-obj-y)): $(subdir-ym) ;

Tell us we need to visit foo/ to build foo/built-in.o

    PHONY += $(subdir-ym)
    $(subdir-ym):
            $(Q)$(MAKE) $(build)=$@

And here we are told what to do to build in a sub-directory.


So after visiting the foo/ directory we have foo/built-in.o
And we can then link the final built-in.o (assuming we have bar.o)

This is recursive so it may go on at several levels.

If you start to look at modules it becomes a bit complicated...

	Sam

  reply	other threads:[~2011-03-02 21:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-02 21:11 KBuild question Tom Bart
2011-03-02 21:40 ` Sam Ravnborg [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-02-15 19:18 kbuild question Kumar Gala
2007-02-15 22:33 ` Sam Ravnborg
2007-02-15 23:44   ` Kumar Gala
2007-02-16  8:50     ` Sam Ravnborg
2007-02-16 10:23 ` Roman Zippel
2007-02-16 14:14   ` Kumar Gala
2007-02-18 17:16     ` Roman Zippel
2007-02-18 19:25       ` Sam Ravnborg
2007-03-15 15:22         ` Kumar Gala

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110302214050.GA7324@merkur.ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=tbartcz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.