Sam Ravnborg
2006-Aug-01 11:57 UTC
[klibc] [PATCH] klibc/kbuild: proper library support for klibc programs
resume introduced a dependency on a few .o files located in usr/kinit/ which confused kbuild. Add proper library support so any targets specified with lib-y is build before visiting subdirectories and thus the resulting lib.a may be used from the subdirectory Kbuild files. This also removes the ugly hack committed a few days ago solving the same problem in a very unelegant way. Tested on x86_64 with "make -j". Signed-off-by: Sam Ravnborg <sam at ravnborg.org> --- scripts/Kbuild.klibc | 28 ++++++++++++++++++---------- usr/kinit/Kbuild | 13 +++++++------ usr/kinit/resume/Kbuild | 10 ++++++---- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/scripts/Kbuild.klibc b/scripts/Kbuild.klibc index f80345d..9101d51 100644 --- a/scripts/Kbuild.klibc +++ b/scripts/Kbuild.klibc @@ -17,10 +17,10 @@ # # If the userspace program consist of composite files do the following: # Kbuild: # -# static-y := kinit -# kinit-y := main.o netdev.c -# So ipconfig will be linked statically using the two .o files -# specified with ipconfig-y. +# static-y := kinit +# kinit-y := main.o netdev.c +# So kinit will be linked statically using the two .o files +# specified with kinit-y. # # Are part of the program located in a sub-directory do like this: # kinit-y += ipconfig/ @@ -28,6 +28,9 @@ # # And in the subdirectory: # ipconfig/Kbuild: # lib-y := packet.o dhcp_proto.o +# # All .o files listed with lib-y will be used to create a single .a file. +# # The .a file is created before any subdirectories are visited so it +# # may be used in the sub-directory programs. # ##### # For a klibc libary file do like this @@ -313,15 +316,18 @@ # dir/lib.a filea.o => file stripobj = $(subst $(obj)/,,$@) addliba = $(addprefix $(obj)/, $(patsubst %/, %/lib.a, $(1))) -link-deps = $(if $($(stripobj)-y), $(call addliba, $($(stripobj)-y)), $@.o) $(use-libs) +link-deps = $(if $($(stripobj)-y), $(call addliba, $($(stripobj)-y)), $@.o) \ + $(call objectify,$($(stripobj)-lib)) quiet_cmd_ld-static = KLIBCLD $@ cmd_ld-static = $(KLIBCLD) $(KLIBCLDFLAGS) -o $@ \ $(EXTRA_KLIBCLDFLAGS) \ $(KLIBCCRT0) \ + --start-group \ $(link-deps) \ - --start-group $(KLIBCLIBC) \ - $(KLIBCLIBGCC) --end-group ; \ + $(KLIBCLIBC) \ + $(KLIBCLIBGCC) \ + --end-group ; \ cp -f $@ $@.g ; \ $(KLIBCSTRIP) $(KLIBCSTRIPFLAGS) $@ @@ -333,9 +339,11 @@ quiet_cmd_ld-shared = KLIBCLD $@ cmd_ld-shared = $(KLIBCLD) $(KLIBCLDFLAGS) -o $@ \ $(EXTRA_KLIBCLDFLAGS) \ $(KLIBCEMAIN) $(KLIBCCRTSHARED) \ + --start-group \ $(link-deps) \ - --start-group -R $(KLIBCLIBCSHARED) \ - $(KLIBCLIBGCC) --end-group ; \ + -R $(KLIBCLIBCSHARED) \ + $(KLIBCLIBGCC) \ + --end-group ; \ cp -f $@ $@.g ; \ $(KLIBCSTRIP) $(KLIBCSTRIPFLAGS) $@ @@ -363,7 +371,7 @@ # Descending # --------------------------------------------------------------------------- .PHONY: $(subdir-y) $(kprog-dirs) $(klib-dirs) -$(sort $(subdir-y) $(kprog-dirs) $(klib-dirs)): $(before-descend) +$(sort $(subdir-y) $(kprog-dirs) $(klib-dirs)): $(lib-target) $(Q)$(MAKE) $(klibc)=$@ # Add FORCE to the prequisites of a target to force it to be always rebuilt. diff --git a/usr/kinit/Kbuild b/usr/kinit/Kbuild index f0c9541..ff1d449 100644 --- a/usr/kinit/Kbuild +++ b/usr/kinit/Kbuild @@ -2,12 +2,12 @@ # # Kbuild file for kinit # -before-descend := name_to_dev.o devname.o getarg.o -targets := $(before-descend) -before-descend := $(call objectify, $(before-descend)) -use-libs := $(before-descend) -static-y := kinit -kinit-y := kinit.o do_mounts.o ramdisk_load.o initrd.o +# library part of kinit. Is used by programs in sub-directories (resume et al) +lib-y := name_to_dev.o devname.o getarg.o +# use lib for kinit +kinit-y := lib.a + +kinit-y += kinit.o do_mounts.o ramdisk_load.o initrd.o kinit-y += getintfile.o readfile.o xpio.o kinit-y += do_mounts_md.o do_mounts_mtd.o nfsroot.o @@ -17,6 +17,7 @@ kinit-y += run-init/ kinit-y += fstype/ kinit-y += resume/ +static-y := kinit shared-y := kinit.shared kinit.shared-y := $(kinit-y) diff --git a/usr/kinit/resume/Kbuild b/usr/kinit/resume/Kbuild index 32b924e..034195d 100644 --- a/usr/kinit/resume/Kbuild +++ b/usr/kinit/resume/Kbuild @@ -7,19 +7,21 @@ shared-y := shared/resume # common .o files objs := resume.o resumelib.o -use-libs := $(call objectify, ../getarg.o ../name_to_dev.o ../devname.o) + # TODO - do we want a stripped version # TODO - do we want the static.g + shared.g directories? -# Create built-in.o with all object files (used by kinit) +# Create lib.a with all object files (used by kinit) lib-y := $(objs) # Additional include paths files KLIBCCFLAGS += -I$(srctree)/$(src)/.. # .o files used to built executables -static/resume-y := $(objs) -shared/resume-y := $(objs) +static/resume-y := $(objs) +static/resume-lib := ../lib.a +shared/resume-y := $(objs) +shared/resume-lib := ../lib.a # Cleaning clean-dirs := static shared -- 1.4.1.rc2.gfc04