[klibc] [PATCH] better kbuild integration

Sam Ravnborg sam at ravnborg.org
Tue Jul 26 03:11:29 PDT 2005


Following patch improves integration with kbuild.
With a future kernel (2.6.14-rc) it now has working support
for 'make clean'.
Included is an example of how to compile an early userspace program.
I selected gzip as the most simple one for this - and left out all
the links to different names (gunzip etc.)

Before proceeding with this I need some inputs on what functionality
is required by the kernel.

I foresee that the kernel provides a minimal set of executables like
today. Do we want them all to be placed direct under usr/?

And what type of support is requested for executables living outside the
kernel. Is the current CONFIG option OK for this?

Also a bit of configuration is needed. Do we like to see a user/Kconfig
dedicated to this?
That would most probarly move the config option away from:
Device drivers | Block Devices
Any input where to place it?

We also need a way to include the build executables in the initramfs
image. That ought to be controlled by some CONFIG_ option what is
included.


	Sam



klibc: better kbuild integration

Following patch improves kbuild integration with the linux kernel.
make clean is fixed (needs latest kbuild fixes that will appear in 2.6.14).
CFLAGS synchornised with current klibc
Sample Kbuild file provided for gzip
Infrastructure to add more klibc based application included in Kbuild file

	Sam

---
commit 8151f4a98f82fba4fe3b949f49da4ab8bba71501
tree 8f681e7a7bb81b168154ce90c3d6aabf88242cb1
parent 5691e96ebfccd21a1f75d3518dd55a96b311d1aa
author Sam Ravnborg <sam at mars.(none)> Tue, 26 Jul 2005 09:59:35 +0000
committer Sam Ravnborg <sam at mars.(none)> Tue, 26 Jul 2005 09:59:35 +0000

 cp-to-kernel.sh          |   14 +++++++++++--
 gzip/Kbuild              |   49 ++++++++++++++++++++++++++++++++++++++++++++++
 kernel/Kbuild            |   13 +++++++++++-
 kernel/Kbuild.klibc      |   12 +++++++----
 klibc/Kbuild             |    5 +++--
 klibc/socketcalls/Kbuild |    4 +++-
 klibc/syscalls/Kbuild    |    2 ++
 7 files changed, 88 insertions(+), 11 deletions(-)

diff --git a/cp-to-kernel.sh b/cp-to-kernel.sh
--- a/cp-to-kernel.sh
+++ b/cp-to-kernel.sh
@@ -12,7 +12,7 @@ fi
 
 kernel=$1
 if [ ! -d $kernel ]; then
-	echo "$kernel is not a kernel directory"
+	echo "$kernel is not a directory"
 	exit 1
 fi
 
@@ -32,8 +32,18 @@ if [ -z $2 ]; then
 	cp -R include/* $kernel/usr/include
 fi
 
+echo "Copying gzip"
+if [ ! -d $kernel/usr/bin/gzip ]; then
+	mkdir -p $kernel/usr/bin/gzip
+fi
+cp -R gzip/* $kernel/usr/bin/gzip
+
 echo "Copying kbuild files"
-cp kernel/Kbuild.*          $kernel/scripts
+cp kernel/Kbuild.klibc       $kernel/scripts
+# Newer kernel versions have Kbuild.include, so do not overwrite it
+if [ ! -f $kernel/scripts/Kbuild.include ]; then
+	cp kernel/Kbuild.include $kernel/scripts
+fi
 cp kernel/Kbuild            $kernel/usr
 cp klibc/Kbuild             $kernel/usr/klibc
 cp klibc/syscalls/Kbuild    $kernel/usr/klibc/syscalls
diff --git a/gzip/Kbuild b/gzip/Kbuild
new file mode 100644
--- /dev/null
+++ b/gzip/Kbuild
@@ -0,0 +1,49 @@
+
+user-progs := gzip
+gzip-y    := gzip.o util.o unzip.o inflate.o
+
+ifeq (a,b)
+
+Kept for convinience
+ZIPSRCS = zip.c deflate.c trees.c bits.c
+UNZIPSRCS = unzip.c inflate.c
+
+SRCS = gzip.c util.c $(UNZIPSRCS)
+OBJS = $(SRCS:.c=.o)
+HDRS = gzip.h tailor.h revision.h
+LIBS = $(KLIBC) $(LIBGCC)
+
+ifeq ($(ZIP),y)
+DEFS += -DSUPPORT_ZIP
+SRCS += $(ZIPSRCS)
+endif
+
+all:	gzip gunzip zcat gzip.stripped
+
+# Actual build-related targets
+
+gzip:	Makefile $(OBJS) $(CRT0) $(LIBS)
+	$(LD) $(LDFLAGS) -o $@ $(CRT0) $(OBJS) $(LIBS)
+
+gunzip:	gzip
+	rm -f $@
+	ln $< $@
+
+zcat: gzip
+	rm -f $@
+	ln $< $@
+
+gzip.stripped: gzip
+	$(STRIP) $< -o $@
+
+clean:
+	$(RM) -f core *.o gzip gunzip zcat gzip.stripped .*.d
+
+spotless: clean
+	rm -f *~
+
+# These should presumably be shared...
+install: all
+	$(INSTALL_EXEC) gzip gunzip zcat $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)bin
+	
+endif
diff --git a/kernel/Kbuild b/kernel/Kbuild
--- a/kernel/Kbuild
+++ b/kernel/Kbuild
@@ -7,15 +7,26 @@ 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
 
+initramfs-y += gzip
+
+initramfs-y := $(addprefix $(obj)/,$(initramfs-y))
+.PHONY: $(initramfs-y)
+
 # 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
@@ -34,7 +45,7 @@ filechk_initramfs_list = $(CONFIG_SHELL)
   $(srctree)/scripts/gen_initramfs_list.sh $(gen_initramfs_args) \
                                            $(quotefixed_initramfs_source)
 
-$(obj)/initramfs_list: FORCE
+$(obj)/initramfs_list: $(src)/Kbuild FORCE
 	$(call filechk,initramfs_list)
 
 quiet_cmd_cpio = CPIO    $@
diff --git a/kernel/Kbuild.klibc b/kernel/Kbuild.klibc
--- a/kernel/Kbuild.klibc
+++ b/kernel/Kbuild.klibc
@@ -31,8 +31,7 @@ KLIBSRC         := usr/klibc
 # Arch specific definitions for klibc
 include $(KLIBSRC)/arch/$(ARCH)/MCONFIG
 
-USERWARNFLAGS   := -Wall -Wpointer-arith -Wwrite-strings                 \
-                   -Wstrict-prototypes -Winline
+USERWARNFLAGS   := -W -Wall -Wsign-compare
 
 USERCROSS       := $(CROSS_COMPILE)
 
@@ -48,9 +47,10 @@ USERCPPFLAGS    := -I$(srctree)/usr/incl
                    -I$(srctree)/usr/include                              \
                    -Iinclude                                             \
                    $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include)   \
-                   -D__KLIBC__ -DBITSIZE=$(BITSIZE)
-USERCFLAGS      := $(USERCPPFLAGS) $(ARCHREQFLAGS) $(OPTFLAGS)           \
-                   $(USERWARNFLAGS)
+                   -D__KLIBC__=1 -D__KLIBC_MINOR__=0                     \
+		   -DBITSIZE=$(BITSIZE)
+USERCFLAGS      := $(USERCPPFLAGS) $(REQFLAGS) $(ARCHREQFLAGS)           \
+                   $(OPTFLAGS) $(USERWARNFLAGS)
 USERAFLAGS      := -D__ASSEMBLY__ $(USERCPPFLAGS)
 USERSTRIPFLAGS  := --strip-all -R .comment -R .note
 
@@ -201,6 +201,7 @@ __build : $(user-dirs) $(user-progs)
 # Descend if needed
 $(sort $(addsuffix /built-in.o,$(user-dirs))): $(user-dirs) ;
 
+# link program that has only a single .o file
 quiet_cmd_user-ld-single = USERLD  $@
       cmd_user-ld-single = $(USERLD) $(USERLDFLAGS) -o $@      \
                            $(USERCRT0) $<                      \
@@ -214,6 +215,7 @@ $(user-single): %: %.o $(USERCRT0) $(USE
 
 targets += $(user-single) $(user-single:=.o)
 
+# link programs that consist of more than one .o file
 multi-deps = $($(subst $(obj)/,,$@-y))
 link-multi-deps = $(addprefix $(obj)/, \
                     $(patsubst %/, %/built-in.o, $(multi-deps)))
diff --git a/klibc/Kbuild b/klibc/Kbuild
--- a/klibc/Kbuild
+++ b/klibc/Kbuild
@@ -119,6 +119,7 @@ $(SOLIB): $(CRT0) $(call objectify,__sha
 # Build sha1 hash values
 targets     += klibc.so libc.so.hash
 hostprogs-y := sha1hash
+clean-files += klibc-???????????????????????????.so
 
 quiet_cmd_solibhash = HASH    $@
       cmd_solibhash = $(USERNM) $< | egrep '^[0-9a-fA-F]+ [ADRTW] ' | \
@@ -129,7 +130,7 @@ $(SOLIB).hash: $(SOLIB) $(obj)/sha1hash 
 quiet_cmd_sohash = GEN     $@
       cmd_sohash = cat $< > $@;                                           \
                      $(USERSTRIP) $(USERSTRIPFLAGS) $@;                   \
-                     rm -f $(obj)/klibc-??????????????????????.so;        \
+                     rm -f $(obj)/klibc-???????????????????????????.so;   \
                      ln -f $@ $(obj)/klibc-`cat $(SOLIB).hash`.so
 $(SOHASH): $(SOLIB) $(SOLIB).hash
 	$(call cmd,sohash)
@@ -139,7 +140,7 @@ $(SOHASH): $(SOLIB) $(SOLIB).hash
 # build interp.o
 targets += interp.o
 
-quiet_cmd_interp = BUILD  $@
+quiet_cmd_interp = BUILD   $@
       cmd_interp = $(USERCC) $(usercflags) -D__ASSEMBLY__     \
                              -DLIBDIR=\"$(SHLIBDIR)\"         \
 			     -DSOHASH=\"`cat $(SOLIB).hash`\" \
diff --git a/klibc/socketcalls/Kbuild b/klibc/socketcalls/Kbuild
--- a/klibc/socketcalls/Kbuild
+++ b/klibc/socketcalls/Kbuild
@@ -4,7 +4,9 @@
 
 # Include automatically generated Makefile fragment.
 # It contains definition of socketcall-objs specifying name of all .o files
+ifeq ($(clean),)
 -include $(obj)/socketcalls.mk
+endif
 
 # Composite object containing all .o file
 always := socketcalls.o
@@ -17,7 +19,7 @@ klibc-dir := $(srctree)/usr/klibc
 targets     := socketcalls.o
 targets     += socketcalls.mk
 targets     += $(socketcall-objs)
-clean-files += *.o
+clean-files += *.S *.o
 
 # Create reloctable composite object file
 $(obj)/socketcalls.o: $(call objectify,$(socketcall-objs)) FORCE
diff --git a/klibc/syscalls/Kbuild b/klibc/syscalls/Kbuild
--- a/klibc/syscalls/Kbuild
+++ b/klibc/syscalls/Kbuild
@@ -4,7 +4,9 @@
 
 # Include automatically generated Makefile fragment.
 # It contains definition of syscall-objs specifying name of all .o files
+ifeq ($(clean),)
 -include $(obj)/syscalls.mk
+endif
 
 # Composite object containing all .o file
 always := syscalls.o



More information about the klibc mailing list