Hello,
I have an idea on how to implement kbuild using non-recursive make,
which should be both more efficient and safer than the current recursive
make. Also part of the idea is to keep as much of the existing Makefiles
intact as possible.
How do we call the subdirectory Makefiles from the top-level Makefile?
They're included. But these Makefiles refer to files that exist within
their directory. This can be solved by setting a prefix variable every
time we include a subdirectory Makefile, and then afterwards add this
prefix to every filename that was added/set in the subdirectory
Makefile.
I have attached a simplified example for a proof of concept. It is a
micro example, but it should hopefully show you how I think kbuild can
move forwards in the future. I will of course also try to see if I can
implement this for the kernel myself, but I am not a kbuild expert, and
there are A LOT of things (many variables, many tricks used by the
makefiles) to take care of in the current build system!
Create the following files and directories.
mkdir drivers drivers/ide kbuild kernel
touch kernel/Makefile
touch drivers/Makefile drivers/ide/Makefile drivers/ide/cdrom.c
touch Makefile kbuild/Makefile.subdir
# Makefile
subdirs := drivers kernel # init mm lib ...
real-obj-y := # initialize to null string
real-obj-m := #
# This is a function that includes the contents of
kbuild/Makefile.subdir,
# so that we don't have to specify each and every variable/function name
# with a double dollar sign.
define include_subdir
$$(info including $(1))
current := $(1)
include kbuild/Makefile.subdir
endef
# Call the "function" include_subdir with a single argument that is the
# name of the subdirectory to process.
$(foreach subdir,$(subdirs),$(eval $(call include_subdir,$(subdir))))
# Debug output
$(info objects to be built: $(sort $(real-obj-y) $(real-obj-m)))
all: $(real-obj-y) $(real-obj-m)
# kbuild/Makefile.subdir
# $(current) is the name of the subdirectory we're in.
subdir-y := # initialize to null string
obj-y := #
obj-m := #
#...
include $(current)/Makefile
# Add the obj-ys and obj-ms with full paths
real-obj-y += $(addprefix $(current)/,$(obj-y))
real-obj-m += $(addprefix $(current)/,$(obj-m))
#...
# Recursively call the new subdirs that were introduced
$(foreach subdir,$(subdir-y),$(eval $(call
include_subdir,$(current)/$(subdir))))
# drivers/Makefile
subdir-y += ide/
# drivers/ide/Makefile
obj-y += cdrom.o
And run `make':
$ make
including drivers
including drivers/ide/
including kernel
objects to be built: drivers/ide//cdrom.o
cc -c -o drivers/ide//cdrom.o drivers/ide//cdrom.c
Good luck.
Kind regards,
Vegard Nossum
-
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html