[klibc] kbuild: add Kbuild for utils and ash

Sam Ravnborg sam at ravnborg.org
Mon Aug 1 14:25:09 PDT 2005


Added a Kbuild file for utils/ and ash.
For utils/ I had to tell kbuild for each single binary
what .o file it used because the binary is placed in a subdirectory.

For ash I had to teach some of the script files that the output files
are stored in a directory != current directory.

cp-to-kernel also copies utils and ash now.

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

---
commit e29ea2b12b68a3fb9b548ebdbb52e35c40c25889
tree 6e0df257ab6a5dc94ae2c7f220a3b8d27abace45
parent 1b8f997e4838bb3f152d0f54067d64cc52dbb209
author Sam Ravnborg <sam at mars.(none)> Mon, 01 Aug 2005 23:21:46 +0200
committer Sam Ravnborg <sam at mars.(none)> Mon, 01 Aug 2005 23:21:46 +0200

 ash/Kbuild      |  113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ash/mkinit.sh   |    6 ++-
 ash/mktokens    |    4 +-
 cp-to-kernel.sh |   12 ++++++
 usr/Kbuild      |    2 -
 utils/Kbuild    |   56 +++++++++++++++++++++++++++
 6 files changed, 189 insertions(+), 4 deletions(-)

diff --git a/ash/Kbuild b/ash/Kbuild
new file mode 100644
--- /dev/null
+++ b/ash/Kbuild
@@ -0,0 +1,113 @@
+#
+# Kbuild file for Ash
+#
+
+
+static-y := sh
+
+sh-y := init.o
+sh-y += arith.o arith_lex.o
+sh-y +=	builtins.o cd.o echo.o error.o eval.o exec.o expand.o
+sh-y += input.o jobs.o main.o memalloc.o miscbltin.o
+sh-y += mystring.o nodes.o options.o parser.o redir.o
+sh-y += show.o syntax.o trap.o output.o var.o test.o
+
+cflags-y := -DSHELL
+
+cflags-$(CONFIG_KLIBC_SH_HISTORY) += -DKLIBC_SH_HISTORY
+    sh-$(CONFIG_KLIBC_SH_HISTORY) += histedit.o
+
+cflags-$(CONFIG_KLIBC_SH_PRINTF) += -DKLIBC_SH_PRINTF
+    sh-$(CONFIG_KLIBC_SH_PRINTF) += printf.o
+
+cflags-$(CONFIG_KLIBC_SH_ALIAS) += -DKLIBC_SH_ALIAS
+    sh-$(CONFIG_KLIBC_SH_ALIAS) += alias.o
+
+cflags-$(CONFIG_KLIBC_SH_MAIL) += -DKLIBC_SH_MAIL
+    sh-$(CONFIG_KLIBC_SH_MAIL) += mail.o
+
+cflags-y += -DJOBS=$(if $(CONFIG_KLIBC_SH_JOBS),1,0)
+    sh-$(CONFIG_KLIBC_SH_JOBS) += kill.o
+
+EXTRA_USERCFLAGS := $(cflags-y)
+
+# The shared binary
+shared-y    := sh.shared
+sh.shared-y := $(sh-y)
+
+
+# bison produces substantially smaller output than byacc
+YACC =  bison -y
+LEX  =  lex
+
+# Generate token.h
+$(obj)/parser.o: $(obj)/token.h
+
+quiet_cmd_mktokens = GEN     $@
+      cmd_mktokens = sh $< $(obj)
+$(obj)/token.h: $(src)/mktokens
+	$(call cmd,mktokens)
+	
+# Generate builtins{.c + .h}
+quiet_cmd_mkbuiltins = GEN     $@
+      cmd_mkbuiltins = sh $< $(srctree)/$(src)/shell.h \
+                             $(srctree)/$(src)/builtins.def $(obj) "$(cflags)"
+$(obj)/builtins.h $(obj)/builtins.c: $(src)/mkbuiltins $(src)/shell.h \
+                                     $(src)/builtins.def
+	$(call cmd,mkbuiltins)
+
+# Generate init.c
+quiet_cmd_mkinit = GEN     $@
+      cmd_mkinit = sh $< $(obj) $(filter-out $<, $^) && touch $@
+      
+# list all .c files excluding itself      
+all-src := $(addprefix $(src)/, $(filter-out init.c, $(sh-y:.o=.c)))
+$(obj)/init.c: $(src)/mkinit.sh $(all-src)
+	$(call cmd,mkinit)
+
+# Generate nodes{.c + .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
+	$(call cmd,mknodes)
+
+
+# Link built in to .c files - yrk
+
+quiet_cmd_cpbltin = CP      $@
+      cmd_cpbltin = cat $< > $@
+
+$(obj)/echo.c: $(src)/bltin/echo.c
+	$(call cmd,cpbltin)
+
+$(obj)/test.c: $(src)/bltin/test.c
+	$(call cmd,cpbltin)
+
+$(obj)/kill.c: $(src)/bltin/kill.c
+	$(call cmd,cpbltin)
+
+$(obj)/printf.c: $(src)/bltin/printf.c
+	$(call cmd,cpbltin)
+
+# Generate parser
+
+$(obj)/arith.c: $(src)/arith.y
+	$(YACC) $< -o $@
+
+$(obj)/arith_lex.o:   $(obj)/arith_lex.c   $(obj)/arith.h
+$(obj)/arith_yylex.o: $(obj)/arith_yylex.c $(obj)/arith.h
+
+$(obj)/arith_lex.c: $(src)/arith_lex.l
+	$(LEX) -o$@ $<
+
+$(obj)/arith.h: $(src)/arith.c
+	$(PERL) -ne 'print if ( /^\#\s*define\s+ARITH/ );' < $< > $@
+
+ifeq (a,b)
+install: all
+	$(INSTALL_EXEC) sh.shared $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)bin/sh
+
+endif
diff --git a/ash/mkinit.sh b/ash/mkinit.sh
--- a/ash/mkinit.sh
+++ b/ash/mkinit.sh
@@ -31,6 +31,8 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
+objdir=$1
+shift
 srcs="$*"
 
 nl='
@@ -139,7 +141,7 @@ for src in $srcs; do
 	done
 done
 
-exec >init.c.tmp
+exec >${objdir}/init.c.tmp
 
 echo "/*"
 echo " * This file was generated by the mkinit program."
@@ -192,4 +194,4 @@ echo "${event_shellproc%$nl}"
 echo "}"
 
 exec >&-
-mv init.c.tmp init.c
+mv ${objdir}/init.c.tmp ${objdir}/init.c
diff --git a/ash/mktokens b/ash/mktokens
--- a/ash/mktokens
+++ b/ash/mktokens
@@ -37,6 +37,8 @@
 # token marks the end of a list.  The third column is the name to print in
 # error messages.
 
+objdir=$1
+
 cat > /tmp/ka$$ <<\!
 TEOF	1	end of file
 TNL	0	newline
@@ -68,7 +70,7 @@ TESAC	1	"esac"
 TNOT	0	"!"
 !
 nl=`wc -l /tmp/ka$$`
-exec > token.h
+exec > ${objdir}/token.h
 awk '{print "#define " $1 " " NR-1}' /tmp/ka$$
 echo '
 /* Array indicating which tokens mark the end of a list */
diff --git a/cp-to-kernel.sh b/cp-to-kernel.sh
--- a/cp-to-kernel.sh
+++ b/cp-to-kernel.sh
@@ -56,6 +56,18 @@ if [ ! -d $kernel/usr/kinit/nfsmount ]; 
 fi
 cp -R nfsmount/* $kernel/usr/kinit/nfsmount
 
+echo "Copying ash"
+if [ ! -d $kernel/usr/ash ]; then
+	mkdir -p $kernel/usr/ash
+fi
+cp -R ash/* $kernel/usr/ash
+
+echo "Copying utils"
+if [ ! -d $kernel/usr/utils ]; then
+	mkdir -p $kernel/usr/utils
+fi
+cp -R utils/* $kernel/usr/utils
+
 echo "Copying kbuild files"
 cp scripts/Kbuild.klibc       $kernel/scripts
 # Newer kernel versions have Kbuild.include, so do not overwrite it
diff --git a/usr/Kbuild b/usr/Kbuild
--- a/usr/Kbuild
+++ b/usr/Kbuild
@@ -19,7 +19,7 @@ subdir-      := klibc
 $(obj)/klibc/libc.a: FORCE
 	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Kbuild.klibc obj=$(obj)/klibc
 
-initramfs-y += gzip kinit
+initramfs-y += gzip kinit ash utils
 
 initramfs-y := $(addprefix $(obj)/,$(initramfs-y))
 .PHONY: $(initramfs-y)
diff --git a/utils/Kbuild b/utils/Kbuild
new file mode 100644
--- /dev/null
+++ b/utils/Kbuild
@@ -0,0 +1,56 @@
+#
+# Kbuild file for klib utils
+#
+
+progs := chroot dd fstype mkdir mkfifo mount pivot_root umount
+progs += true false sleep ln nuke minips run-init printf cat
+progs += insmod uname
+
+static-y := $(addprefix static/, $(progs))
+shared-y := $(addprefix shared/, $(progs))
+
+# The binary is placed in a subdir, so we need to tell kbuild this
+static/chroot-y     := chroot.o
+shared/chroot-y     := chroot.o
+static/dd-y         := dd.o
+shared/dd-y         := dd.o
+static/fstype-y     := fstype.o
+shared/fstype-y     := fstype.o
+static/mkdir-y      := mkdir.o file_mode.o
+shared/mkdir-y      := mkdir.o file_mode.o
+static/mkfifo-y     := mkfifo.o file_mode.o
+shared/mkfifo-y     := mkfifo.o file_mode.o
+static/mount-y      := mount_main.o mount_opts.o
+shared/mount-y      := mount_main.o mount_opts.o
+static/pivot_root-y := pivot_root.o
+shared/pivot_root-y := pivot_root.o
+static/umount-y     := umount.o
+shared/umount-y     := umount.o
+static/true-y       := true.o
+shared/true-y       := true.o
+static/false-y      := false.o
+shared/false-y      := false.o
+static/sleep-y      := sleep.o
+shared/sleep-y      := sleep.o
+static/ln-y         := ln.o
+shared/ln-y         := ln.o
+static/nuke-y       := nuke.o
+shared/nuke-y       := nuke.o
+static/minips-y     := minips.o
+shared/minips-y     := minips.o
+static/run-init-y   := run-init.o
+shared/run-init-y   := run-init.o
+static/printf-y     := printf.o
+shared/printf-y     := printf.o
+static/cat-y        := cat.o
+shared/cat-y        := cat.o
+static/insmod-y     := insmod.o
+shared/insmod-y     := insmod.o
+static/uname-y      := uname.o
+shared/uname-y      := uname.o
+
+
+ifeq (a,b)
+install: all
+	$(INSTALL_EXEC) shared/* $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)bin	
+endif



More information about the klibc mailing list