[klibc] kbuild: fix cleaning in kernel tree

Sam Ravnborg sam at ravnborg.org
Tue Aug 2 14:01:24 PDT 2005


To support cleaning a bit of resturcturing was needed in usr/Kbuild.
The current structure descend into klibc binary subdirectories only
if CONFIG_KLIBC is selected.

The is not yet support for adding the binaries to the initramfs image.
That will wait until we find a nice way to do so.

Also added a few statements to various Kbuild files to let 'make clean'
pick up all output files.
There is room for some generalization - but that will wait until klibc hit mainline.

Signed-off-by: Sam Ravnborg <sam at ravnborg.org>

---
commit b4c1af03a5b0c908b32ab60473cdfaa20ecfe0f6
tree 22fadf5e653f7465f4d39b76540d86a7d7c77021
parent 5069497d1331ed907edbc1a22155fa8778569f84
author Sam Ravnborg <sam at mars.(none)> Tue, 02 Aug 2005 23:00:30 +0200
committer Sam Ravnborg <sam at mars.(none)> Tue, 02 Aug 2005 23:00:30 +0200

 ash/Kbuild      |   11 +++++++++--
 gzip/Kbuild     |    2 ++
 ipconfig/Kbuild |    3 +++
 kinit/Kbuild    |    4 ++++
 nfsmount/Kbuild |    2 ++
 usr/Kbuild      |   42 +++++++++++++++++++++++-------------------
 utils/Kbuild    |    1 +
 7 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/ash/Kbuild b/ash/Kbuild
--- a/ash/Kbuild
+++ b/ash/Kbuild
@@ -35,12 +35,15 @@ EXTRA_USERCFLAGS := $(cflags-y)
 shared-y    := sh.shared
 sh.shared-y := $(sh-y)
 
+# For cleaning
+targets := $(static-y) $(shared-y)
 
 # bison produces substantially smaller output than byacc
 YACC =  bison -y
 LEX  =  lex
 
 # Generate token.h
+targets += token.h
 $(obj)/parser.o: $(obj)/token.h
 
 quiet_cmd_mktokens = GEN     $@
@@ -49,6 +52,7 @@ $(obj)/token.h: $(src)/mktokens
 	$(call cmd,mktokens)
 	
 # Generate builtins{.c + .h}
+targets += builtins.c builtins.h
 quiet_cmd_mkbuiltins = GEN     $@
       cmd_mkbuiltins = sh $< $(srctree)/$(src)/shell.h \
                              $(srctree)/$(src)/builtins.def $(obj) "$(cflags)"
@@ -57,6 +61,7 @@ $(obj)/builtins.h $(obj)/builtins.c: $(s
 	$(call cmd,mkbuiltins)
 
 # Generate init.c
+targets += init.c
 quiet_cmd_mkinit = GEN     $@
       cmd_mkinit = sh $< $(obj) $(filter-out $<, $^) && touch $@
       
@@ -66,16 +71,18 @@ $(obj)/init.c: $(src)/mkinit.sh $(all-sr
 	$(call cmd,mkinit)
 
 # Generate nodes{.c + .h}
+targets += nodes.c nodes.h
 quiet_cmd_mknodes = GEN     $@
       cmd_mknodes = sh $< $(srctree)/$(src)/nodetypes \
                           $(srctree)/$(src)/nodes.c.pat $(obj)
 
 $(obj)/nodes.c: $(obj)/nodes.h
-$(obj)/nodes.h: $(src)/mknodes
+$(obj)/nodes.h: $(src)/mknodes.sh
 	$(call cmd,mknodes)
 
 
 # Link built in to .c files - yrk
+targets += echo.c test.c kill.c printf.c
 
 quiet_cmd_cpbltin = CP      $@
       cmd_cpbltin = cat $< > $@
@@ -93,7 +100,7 @@ $(obj)/printf.c: $(src)/bltin/printf.c
 	$(call cmd,cpbltin)
 
 # Generate parser
-
+targets += arith.c arith_lex.c arith.h
 $(obj)/arith.c: $(src)/arith.y
 	$(YACC) $< -o $@
 
diff --git a/gzip/Kbuild b/gzip/Kbuild
--- a/gzip/Kbuild
+++ b/gzip/Kbuild
@@ -22,6 +22,8 @@ $(obj)/gunzip $(obj)/zcat: $(obj)/gzip
 $(obj)/gzip.stripped: $(obj)/gzip
 	$(call cmd,strip)
 
+# Cleaning
+targets := $(static-y) $(shared-y)
 
 # Old install target - TODO
 #install: all
diff --git a/ipconfig/Kbuild b/ipconfig/Kbuild
--- a/ipconfig/Kbuild
+++ b/ipconfig/Kbuild
@@ -24,6 +24,9 @@ lib-y := $(objs)
 static/ipconfig-y := $(objs)
 shared/ipconfig-y := $(objs)
 
+# Cleaning
+clean-dirs := static shared
+
 ifeq (a,b)
 # TODO - can we replace this with built-in.o?
 $(LIB): $(OBJS)
diff --git a/kinit/Kbuild b/kinit/Kbuild
--- a/kinit/Kbuild
+++ b/kinit/Kbuild
@@ -18,6 +18,10 @@ USERCFLAGS_nfsroot.o := -I$(src)/ipconfi
 
 # TODO - stripped image
 
+# Cleaning
+targets := $(static-y) $(shared-y)
+subdir- := ipconfig nfsmount
+
 ifeq (a,b)
 
 # This should perhaps be a shared binary?
diff --git a/nfsmount/Kbuild b/nfsmount/Kbuild
--- a/nfsmount/Kbuild
+++ b/nfsmount/Kbuild
@@ -21,6 +21,8 @@ dummypmap-y := dummypmap_test.o
 # TODO - do we want a stripped version
 # TODO - do we want the static.g + shared.g directories?
 
+clean-dirs := static shared
+
 ifeq (a,b)
 
 install: all
diff --git a/usr/Kbuild b/usr/Kbuild
--- a/usr/Kbuild
+++ b/usr/Kbuild
@@ -6,32 +6,33 @@
 export KLIBSRC := $(srctree)/$(src)/klibc
 export KLIBINC := $(srctree)/$(src)/include
 export KLIBOBJ := $(objtree)/$(obj)/klibc
+CONFIG_KLIBC := 1
 
-obj-y        := initramfs_data.o
-always       := klibc/libc.a
-hostprogs-y  := gen_init_cpio
-clean-files  := initramfs_data.cpio.gz initramfs_list
-
-# Descend down into klibc when cleaning
-subdir-      := klibc
-
-# Build klibc library
-$(obj)/klibc/libc.a: FORCE
-	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Kbuild.klibc obj=$(obj)/klibc
+# Klibc binaries
+ifdef CONFIG_KLIBC
+klibc := -f $(srctree)/scripts/Kbuild.klibc obj
+
+.PHONY: klibcdirs
+$(obj)/initramfs_list: klibcdirs
+
+klibcdirs: FORCE
+	$(Q)$(MAKE) $(klibc)=$(src)/klibc
+	$(Q)$(MAKE) $(klibc)=$(src)/kinit
+	$(Q)$(MAKE) $(klibc)=$(src)/utils
+	$(Q)$(MAKE) $(klibc)=$(src)/ash
+	$(Q)$(MAKE) $(klibc)=$(src)/gzip
+endif
+subdir- := klibc kinit utils ash gzip
 
-initramfs-y += gzip kinit ash utils
 
-initramfs-y := $(addprefix $(obj)/,$(initramfs-y))
-.PHONY: $(initramfs-y)
+# Generate builtin.o based on initramfs_data.o
+obj-y        := initramfs_data.o
 
 # initramfs_data.o contains the initramfs_data.cpio.gz image.
 # The image is included using .incbin, a dependency which is not
 # tracked automatically.
 $(obj)/initramfs_data.o: $(obj)/initramfs_data.cpio.gz FORCE
 
-$(initramfs-y): $(obj)/klibc/libc.a
-	$(Q)$(MAKE) -f $(srctree)/scripts/Kbuild.klibc obj=$@
-
 ifdef CONFIG_INITRAMFS_ROOT_UID
 gen_initramfs_args += -u $(CONFIG_INITRAMFS_ROOT_UID)
 endif
@@ -71,8 +72,10 @@ targets += $(quotefixed_initramfs_source
 else
 
 # INITRAMFS_SOURCE is not a cpio archive - create one
+hostprogs-y  := gen_init_cpio
+
 $(obj)/initramfs_data.cpio: $(obj)/gen_init_cpio \
-                            $(initramfs-y) $(obj)/initramfs_list FORCE
+                            $(obj)/initramfs_list FORCE
 	$(call if_changed,cpio)
 
 targets += initramfs_data.cpio
@@ -80,9 +83,10 @@ initramfs_data_cpio = $(obj)/initramfs_d
 
 endif
 
-
 $(obj)/initramfs_data.cpio.gz: $(initramfs_data_cpio) FORCE
 	$(call if_changed,gzip)
 
 targets += initramfs_data.cpio.gz
 
+# Cleaning time
+clean-files  := initramfs_data.cpio.gz initramfs_list
diff --git a/utils/Kbuild b/utils/Kbuild
--- a/utils/Kbuild
+++ b/utils/Kbuild
@@ -49,6 +49,7 @@ shared/insmod-y     := insmod.o
 static/uname-y      := uname.o
 shared/uname-y      := uname.o
 
+clean-dirs := static shared
 
 ifeq (a,b)
 install: all



More information about the klibc mailing list