Skip to contentSkip to conversation

details on internal kbuild magic

DISCUSSION Mike Frysinger 2 participants 2 messages Jan 18, 2012 – Jan 21, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

i've been flipping through the source but haven't made much headway. the documentation doesn't really cover kbuild internals, so that didn't help. hopefully someone here can point me in the right direction.

i'm interested in the exact make mechanics that kbuild utilizes to avoid make recursion (make -C) but while supporting its own include recursion.

for example, fs/Makefile has lines like:

	obj-y += ramfs/

where is the logic that parses $(obj-y) and knows that it needs to recursively include ramfs/Makefile ?

also, how are collisions avoided in variable names ? for example, kernel/Makefile has lines like:
CFLAGS_REMOVE_irq_work.o = -pg
how does kbuild know to apply this to building kernel/irq_work.o and not a irq_work.o object in any other dir ?
-mike

#1 lore raw

Hi Mike.

Quoted 11 lines · Mike Frysinger

i've been flipping through the source but haven't made much headway. the documentation doesn't really cover kbuild internals, so that didn't help. hopefully someone here can point me in the right direction.

i'm interested in the exact make mechanics that kbuild utilizes to avoid make recursion (make -C) but while supporting its own include recursion.

for example, fs/Makefile has lines like:

	obj-y += ramfs/

where is the logic that parses $(obj-y) and knows that it needs to recursively include ramfs/Makefile ?

When the 'core' part of kbuild is started then this is done using:

	$(Q)$(MAKE) -f scripts/Makefile.build obj=$@

Where obj is the directory which contains the files to be build. In your example obj=fs

Makefile.build will include the following files:

-include include/config/auto.conf    <= The configuration (CONFIG_ symbols)
include scripts/Kbuild.include       <= core Kbuild stuff
include $(obj)/Makefile              <= the ramfs Makefile
include scripts/Makefile.lib         <= additional kbuild stuff required after ramfs file include

In Makefile.lib we append built-in.o to $(obj-y) and we prefix with $(obj) so we end up with:
obj-y == fs/ramfs/built-in.o

Later we add a dependency like this:

    fs/built-in.o: fs/ramfs/built-in.o

    It looks like this in Makefile.build:

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

So make knows it need to build fs/ramfs/built-in.o first.

In Makefile.lib we build up a list of .o files which does not live in the current directory in $(subdir-obj-y)

And in Makefile.build we tell make to visit the subdirs to build these files using:

    # To build objects in subdirs, we need to descend into the directories
    $(sort $(subdir-obj-y)): $(subdir-ym) ;

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

So make will visit fs/ and see that it needs to visit fs/ramfs/ before if can link fs/built-in.o

Simple - no?
Hope this helps.

Sam