Merge with git+ssh://hera.kernel.org/pub/scm/libs/klibc/klibc.git
diff --git a/Kbuild b/Kbuild
new file mode 100644
index 0000000..0751877
--- /dev/null
+++ b/Kbuild
@@ -0,0 +1,17 @@
+#
+# Kbuild file for klibc
+#
+.PHONY: $(obj)/all
+always := all
+
+$(obj)/all:
+	$(Q)$(MAKE) $(klibc)=scripts/basic
+	$(Q)$(MAKE) $(klibc)=klibc
+	$(Q)$(MAKE) $(klibc)=usr/kinit
+	$(Q)$(MAKE) $(klibc)=dash
+	$(Q)$(MAKE) $(klibc)=utils
+	$(Q)$(MAKE) $(klibc)=gzip
+
+
+# Directories to visit during clean and install
+subdir- := scripts/basic klcc klibc dash utils gzip usr/kinit klibc/tests
diff --git a/MCONFIG b/MCONFIG
deleted file mode 100644
index 450e5c7..0000000
--- a/MCONFIG
+++ /dev/null
@@ -1,98 +0,0 @@
-# -*- makefile -*-
-#
-# Makefile configuration, without explicit rules
-#
-
-# CROSS is the prefix used for system tools like gcc, ld etc.
-CROSS   = 
-
-# KCROSS is the prefix we use for klibc installations.  This is usually
-# the same as CROSS, but may be different, e.g. to install an i386
-# cross-compilation suite on an x86-64 system, using the same gcc/binutils.
-KCROSS ?= $(CROSS)
-
-# Location for installation
-prefix      = /usr
-bindir      = $(prefix)/bin
-libdir      = $(prefix)/lib
-mandir      = $(prefix)/man
-INSTALLDIR  = $(prefix)/lib/klibc
-INSTALLROOT =
-
-INSTALL_EXEC = install -m 755
-INSTALL_DATA = install -m 644
-
-# Eventually support separate compilation, but we don't have it yet...
-OBJROOT = $(SRCROOT)
-
-# Kernel trees (source and obj) - can potentially be different
-KRNLSRC = $(SRCROOT)/linux
-KRNLOBJ = $(SRCROOT)/linux
-
-# klibc version information
-KLIBCVER = -D__KLIBC__=$(shell cut -d. -f1 < $(SRCROOT)/version) \
-	   -D__KLIBC_MINOR__=$(shell cut -d. -f2 < $(SRCROOT)/version)
-
-ARCH    = $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/parisc.*/parisc/)
-CC	= $(CROSS)gcc
-LD      = $(CROSS)ld
-KLIBSRC = $(SRCROOT)/klibc
-KLIBOBJ = $(OBJROOT)/klibc
-INCLUDE = -I$(SRCROOT)/include/arch/$(ARCH) \
-	  -I$(SRCROOT)/include/bits$(BITSIZE) \
-	  -I$(SRCROOT)/include \
-	  -I$(KRNLOBJ)/include -I$(KRNLOBJ)/include2 -I$(KRNLSRC)/include
-REQFLAGS = $(ARCHREQFLAGS) $(KLIBCVER) -nostdlib -nostdinc -iwithprefix include \
-	   $(INCLUDE)
-LDFLAGS =
-AR      = $(CROSS)ar
-RANLIB  = $(CROSS)ranlib
-NM	= $(CROSS)nm
-PERL    = perl
-OBJCOPY = $(CROSS)objcopy
-
-STRIP      = $(CROSS)strip
-STRIPFLAGS = --strip-all -R .comment -R .note
-STRIPCMD   = $(STRIP) $(STRIPFLAGS)
-
-HOST_CC      = gcc
-HOST_CFLAGS  = -g -O
-HOST_LDFLAGS = 
-HOST_LIBS    =
-
-# Static library paths
-CRT0      = $(KLIBOBJ)/crt0.o
-KLIBC     = $(KLIBOBJ)/libc.a
-LIBGCC    = $(shell $(CC) $(REQFLAGS) $(OPTFLAGS) --print-libgcc)
-
-# Shared library paths
-CRTSHARED = $(KLIBOBJ)/interp.o
-LIBSHARED = $(KLIBOBJ)/libc.so
-
-#
-# This indicates the location of the final version of the shared library.
-# THIS MUST BE AN ABSOLUTE PATH WITH NO FINAL SLASH.
-# Leave this empty to make it the root.
-#
-SHLIBDIR = /lib
-
-# Enable this to make perror/strerror return real error messages
-# This makes klibc.so and any static binary which uses these functions
-# about 4K bigger.
-ERRLIST = 1
-
-# Include zlib in klibc.  This roughly triples the size of klibc!
-ZLIB = 0
-
-#
-# Include arch-specific rule fragments
-#
-include $(KLIBSRC)/arch/$(ARCH)/MCONFIG
-
-ifeq ($(DEBUG),y)
-STRIP     = /bin/true -Since_we_are_debugging
-OPTFLAGS += -O1 -g
-endif
-
-# How to tell the linker main() is the entrypoint
-EMAIN ?= -e main
diff --git a/MRULES b/MRULES
deleted file mode 100644
index 41fdd07..0000000
--- a/MRULES
+++ /dev/null
@@ -1,45 +0,0 @@
-# -*- makefile -*-
-#
-# Standard pattern rules
-#
-
-.SUFFIXES: .c .o .a .so .lo .i .S .s .ls .ss .lss
-
-% : %.c	# Cancel default rule
-
-% : %.S
-
-.c.o:
-	$(CC) $(CFLAGS) -c -o $@ $<
-
-.c.i:
-	$(CC) $(CFLAGS) -E -o $@ $<
-
-.c.s:
-	$(CC) $(CFLAGS) -S -o $@ $<
-
-.S.o:
-	$(CC) $(CFLAGS) -D__ASSEMBLY__ -c -o $@ $<
-
-.S.s:
-	$(CC) $(CFLAGS) -D__ASSEMBLY__ -E -o $@ $<
-
-.S.lo:
-	$(CC) $(CFLAGS) $(SOFLAGS) -D__ASSEMBLY__ -c -o $@ $<
-
-.S.ls:
-	$(CC) $(CFLAGS) $(SOFLAGS) -D__ASSEMBLY__ -E -o $@ $<
-
-.s.o:
-	$(CC) $(CFLAGS) -x assembler -c -o $@ $<
-
-.ls.lo:
-	$(CC) $(CFLAGS) $(SOFLAGS) -x assembler -c -o $@ $<
-
-.c.lo:
-	$(CC) $(CFLAGS) $(SOFLAGS) -c -o $@ $<
-
-.c.ls:
-	$(CC) $(CFLAGS) $(SOFLAGS) -S -o $@ $<
-
-
diff --git a/Makefile b/Makefile
index c260039..8c500e3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,74 @@
 VERSION := $(shell cat version)
-SUBDIRS = klibc dash ipconfig nfsmount utils kinit gzip
 SRCROOT = .
 
-all:
+# kbuild compatibility
+export srctree  := $(shell pwd)
+export objtree  := $(shell pwd)
+export KLIBCSRC := klibc
+export KLIBCINC := include
+export KLIBCOBJ := klibc
+export KLIBCKERNELSRC := linux/
+
+export CC      := gcc
+NOSTDINC_FLAGS := -nostdlib -nostdinc -isystem $(shell $(CC) -print-file-name=include)
+
+export ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
+
+export HOSTCC     := gcc
+export HOSTCFLAGS := -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
+export PERL       := perl
+
+# Location for installation
+export prefix      = /usr
+export bindir      = $(prefix)/bin
+export libdir      = $(prefix)/lib
+export mandir      = $(prefix)/man
+export INSTALLDIR  = $(prefix)/lib/klibc
+export INSTALLROOT =
+
+# Create a fake .config as present in the kernel tree
+# But if it exists leave it alone
+$(if $(wildcard $(objtree)/.config),,$(shell echo CONFIG_KLIBC=y > .config))
+
+# Prefix Make commands with $(Q) to silence them
+# Use quiet_cmd_xxx, cmd_xxx to create nice output
+# use make V=1 to get verbose output
+
+ifdef V
+  ifeq ("$(origin V)", "command line")
+    KBUILD_VERBOSE = $(V)
+  endif
+endif
+ifndef KBUILD_VERBOSE
+  KBUILD_VERBOSE = 0
+endif
+
+ifeq ($(KBUILD_VERBOSE),1)
+  quiet =
+  Q =
+else
+  quiet=quiet_
+  Q = @
+endif
+
+# If the user is running make -s (silent mode), suppress echoing of
+# commands
+
+ifneq ($(findstring s,$(MAKEFLAGS)),)
+  quiet=silent_
+endif
+
+export quiet Q KBUILD_VERBOSE
+
+# Do not print "Entering directory ..."
+MAKEFLAGS += --no-print-directory
+
+# Shorthand to call Kbuild.klibc
+klibc := -f $(srctree)/scripts/Kbuild.klibc obj
+
+# Very first target
+.PHONY: all klcc klibc
+all: klcc klibc
 
 rpmbuild = $(shell which rpmbuild 2>/dev/null || which rpm)
 
@@ -13,65 +79,23 @@
 rpm: klibc.spec
 	+$(rpmbuild) -bb klibc.spec --target=$(ARCH)
 
-$(CROSS)klibc.config: Makefile
-	rm -f $@
-	echo 'ARCH=$(ARCH)' >> $@
-	echo 'CROSS=$(CROSS)' >> $@
-	echo 'KCROSS=$(KCROSS)' >> $@
-	echo 'CC=$(CC)' >> $@
-	echo 'LD=$(LD)' >> $@
-	echo 'REQFLAGS=$(filter-out -I%,$(REQFLAGS))' >> $@
-	echo 'OPTFLAGS=$(OPTFLAGS)' >> $@
-	echo 'LDFLAGS=$(LDFLAGS)' >> $@
-	echo 'STRIP=$(STRIP)' >> $@
-	echo 'STRIPFLAGS=$(STRIPFLAGS)' >> $@
-	echo 'EMAIN=$(EMAIN)' >> $@
-	echo 'BITSIZE=$(BITSIZE)' >> $@
-	echo 'prefix=$(INSTALLDIR)' >> $@
-	echo 'bindir=$(INSTALLDIR)/$(KCROSS)bin' >> $@
-	echo 'libdir=$(INSTALLDIR)/$(KCROSS)lib' >> $@
-	echo 'includedir=$(INSTALLDIR)/$(KCROSS)include' >> $@
+# Build klcc - it is the first target
+klcc:
+	$(Q)$(MAKE) $(klibc)=klcc
 
-$(CROSS)klcc: klcc.in $(CROSS)klibc.config makeklcc.pl
-	$(PERL) makeklcc.pl klcc.in $(CROSS)klibc.config \
-		$(shell bash -c 'type -p $(PERL)') > $@ || ( rm -f $@ ; exit 1 )
-	chmod a+x $@
+klibc:
+	$(Q)$(MAKE) $(klibc)=.
 
-%: local-%
-	@set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
+test: klibc
+	$(Q)$(MAKE) $(klibc)=klibc/tests
 
-local-all: $(CROSS)klcc
+clean:
+	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.clean obj=.
 
-local-clean:
-	rm -f klibc.config klcc
-
-local-spotless: local-clean
-	rm -f klibc.spec *~ tags
-
-local-install: $(CROSS)klcc
-	mkdir -p $(INSTALLROOT)$(bindir)
-	mkdir -p $(INSTALLROOT)$(mandir)/man1
-	mkdir -p $(INSTALLROOT)$(SHLIBDIR)
-	mkdir -p $(INSTALLROOT)$(INSTALLDIR)
-	-rm -rf $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
-	mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
-	mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)lib
-	mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)bin
-	set -xe ; for d in linux scsi asm-$(ARCH) asm-generic $(ASMARCH); do \
-	  mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)include/$$d ; \
-	  for r in $(KRNLSRC)/include $(KRNLOBJ)/include $(KRNLOBJ)/include2 ; do \
-	    [ ! -d $$r/$$d ] || \
-	      cp -rfL $$r/$$d/. $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/$$d/. ; \
-	  done ; \
-	done
-	cd $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include && ln -sf asm-$(ARCH) asm
-	cp -rf include/. $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/.
-	$(INSTALL_DATA) klcc.1 $(INSTALLROOT)$(mandir)/man1/$(KCROSS)klcc.1
-	$(INSTALL_EXEC) $(KCROSS)klcc $(INSTALLROOT)$(bindir)
+install: all
+	$(Q)$(MAKE) -f $(srctree)/scripts/Kbuild.install obj=.
 
 # This does all the prep work needed to turn a freshly exported git repository
 # into a release tarball tree
 release: klibc.spec
 	rm -f maketar.sh
-
--include MCONFIG
diff --git a/ash/Kbuild b/ash/Kbuild
new file mode 100644
index 0000000..1186369
--- /dev/null
+++ b/ash/Kbuild
@@ -0,0 +1,123 @@
+#
+# 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
+
+# locate .h files from generated .c files (make O=)
+cflags-y += -I$(srctree)/$(src)
+# locate generated .h files from normal .c files
+cflags-y += -I$(objtree)/$(obj)
+
+EXTRA_KLIBCCFLAGS := $(cflags-y)
+
+# The shared binary
+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     $@
+      cmd_mktokens = sh $< $(obj)
+$(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)"
+$(obj)/builtins.h $(obj)/builtins.c: $(src)/mkbuiltins $(src)/shell.h \
+                                     $(src)/builtins.def
+	$(call cmd,mkbuiltins)
+
+# Generate init.c
+targets += 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}
+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.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 $< > $@
+
+$(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
+targets += arith.c arith_lex.c arith.h
+$(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/ );' < $< > $@
+
+
+# Targets to install
+install-y := sh.shared
diff --git a/ash/mkinit.sh b/ash/mkinit.sh
new file mode 100644
index 0000000..623f669
--- /dev/null
+++ b/ash/mkinit.sh
@@ -0,0 +1,197 @@
+#! /bin/sh
+#	$NetBSD: mkinit.sh,v 1.1 2004/01/17 11:47:31 dsl Exp $
+
+# Copyright (c) 2003 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by David Laight.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. Neither the name of The NetBSD Foundation nor the names of its
+#    contributors may be used to endorse or promote products derived
+#    from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# 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='
+'
+
+includes=' "shell.h" "mystring.h" "init.h" '
+defines=
+decles=
+event_init=
+event_reset=
+event_shellproc=
+
+for src in $srcs; do
+	exec <$src
+	decnl="$nl"
+	while IFS=; read -r line; do
+		[ "$line" = x ]
+		case "$line " in
+		INIT["{ 	"]* ) event=init;;
+		RESET["{ 	"]* ) event=reset;;
+		SHELLPROC["{ 	"]* ) event=shellproc;;
+		INCLUDE[\ \	]* )
+			IFS=' 	'
+			set -- $line
+			# ignore duplicates
+			[ "${includes}" != "${includes%* $2 }" ] && continue
+			includes="$includes$2 "
+			continue
+			;;
+		MKINIT\  )
+			# struct declaration
+			decles="$decles$nl"
+			while
+				read -r line
+				decles="${decles}${line}${nl}"
+				[ "$line" != "};" ]
+			do
+				:
+			done
+			decnl="$nl"
+			continue
+			;;
+		MKINIT["{ 	"]* )
+			# strip initialiser
+			def=${line#MKINIT}
+			comment="${def#*;}"
+			def="${def%;$comment}"
+			def="${def%%=*}"
+			def="${def% }"
+			decles="${decles}${decnl}extern${def};${comment}${nl}"
+			decnl=
+			continue
+			;;
+		\#define[\ \	]* )
+			IFS=' 	'
+			set -- $line
+			# Ignore those with arguments
+			[ "$2" = "${2##*(}" ] || continue
+			# and multiline definitions
+			[ "$line" = "${line%\\}" ] || continue
+			defines="${defines}#undef  $2${nl}${line}${nl}"
+			continue
+			;;
+		* ) continue;;
+		esac
+		# code for events
+		ev="${nl}      /* from $src: */${nl}      {${nl}"
+		while
+			read -r line
+			[ "$line" != "}" ]
+		do
+			# The C program indented by an extra 6 chars using
+			# tabs then spaces. I need to compare the output :-(
+			indent=6
+			while
+				l=${line#	}
+				[ "$l" != "$line" ]
+			do
+				indent=$(($indent + 8))
+				line="$l"
+			done
+			while
+				l=${line# }
+				[ "$l" != "$line" ]
+			do
+				indent=$(($indent + 1))
+				line="$l"
+			done
+			[ -z "$line" -o "$line" != "${line###}" ] && indent=0
+			while
+				[ $indent -ge 8 ]
+			do
+				ev="$ev	"
+				indent="$(($indent - 8))"
+			done
+			while
+				[ $indent -gt 0 ]
+			do
+				ev="$ev "
+				indent="$(($indent - 1))"
+			done
+			ev="${ev}${line}${nl}"
+		done
+		ev="${ev}      }${nl}"
+		eval event_$event=\"\$event_$event\$ev\"
+	done
+done
+
+exec >${objdir}/init.c.tmp
+
+echo "/*"
+echo " * This file was generated by the mkinit program."
+echo " */"
+echo
+
+IFS=' '
+for f in $includes; do
+	echo "#include $f"
+done
+
+echo
+echo
+echo
+echo "$defines"
+echo
+echo "$decles"
+echo
+echo
+echo "/*"
+echo " * Initialization code."
+echo " */"
+echo
+echo "void"
+echo "init() {"
+echo "${event_init%$nl}"
+echo "}"
+echo
+echo
+echo
+echo "/*"
+echo " * This routine is called when an error or an interrupt occurs in an"
+echo " * interactive shell and control is returned to the main command loop."
+echo " */"
+echo
+echo "void"
+echo "reset() {"
+echo "${event_reset%$nl}"
+echo "}"
+echo
+echo
+echo
+echo "/*"
+echo " * This routine is called to initialize the shell to run a shell procedure."
+echo " */"
+echo
+echo "void"
+echo "initshellproc() {"
+echo "${event_shellproc%$nl}"
+echo "}"
+
+exec >&-
+mv ${objdir}/init.c.tmp ${objdir}/init.c
diff --git a/ash/mktokens b/ash/mktokens
new file mode 100644
index 0000000..24d568e
--- /dev/null
+++ b/ash/mktokens
@@ -0,0 +1,94 @@
+#!/bin/sh -
+#	$NetBSD: mktokens,v 1.10 2003/08/22 11:22:23 agc Exp $
+#
+# Copyright (c) 1991, 1993
+#	The Regents of the University of California.  All rights reserved.
+#
+# This code is derived from software contributed to Berkeley by
+# Kenneth Almquist.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. Neither the name of the University nor the names of its contributors
+#    may be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+#	@(#)mktokens	8.1 (Berkeley) 5/31/93
+
+# The following is a list of tokens.  The second column is nonzero if the
+# 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
+TSEMI	0	";"
+TBACKGND 0	"&"
+TAND	0	"&&"
+TOR	0	"||"
+TPIPE	0	"|"
+TLP	0	"("
+TRP	1	")"
+TENDCASE 1	";;"
+TENDBQUOTE 1	"`"
+TREDIR	0	redirection
+TWORD	0	word
+TIF	0	"if"
+TTHEN	1	"then"
+TELSE	1	"else"
+TELIF	1	"elif"
+TFI	1	"fi"
+TWHILE	0	"while"
+TUNTIL	0	"until"
+TFOR	0	"for"
+TDO	1	"do"
+TDONE	1	"done"
+TBEGIN	0	"{"
+TEND	1	"}"
+TCASE	0	"case"
+TESAC	1	"esac"
+TNOT	0	"!"
+!
+nl=`wc -l /tmp/ka$$`
+exec > ${objdir}/token.h
+awk '{print "#define " $1 " " NR-1}' /tmp/ka$$
+echo '
+/* Array indicating which tokens mark the end of a list */
+const char tokendlist[] = {'
+awk '{print "\t" $2 ","}' /tmp/ka$$
+echo '};
+
+const char *const tokname[] = {'
+sed -e 's/"/\\"/g' \
+    -e 's/[^	 ]*[	 ][	 ]*[^	 ]*[	 ][	 ]*\(.*\)/	"\1",/' \
+    /tmp/ka$$
+echo '};
+'
+sed 's/"//g' /tmp/ka$$ | awk '
+/TIF/{print "#define KWDOFFSET " NR-1; print ""; 
+      print "const char *const parsekwd[] = {"}
+/TIF/,/neverfound/{print "	\"" $3 "\","}'
+echo '	0
+};'
+
+rm /tmp/ka$$
diff --git a/cp-to-kernel.sh b/cp-to-kernel.sh
index bc9f915..37eba2b 100644
--- a/cp-to-kernel.sh
+++ b/cp-to-kernel.sh
@@ -12,7 +12,7 @@
 
 kernel=$1
 if [ ! -d $kernel ]; then
-	echo "$kernel is not a kernel directory"
+	echo "$kernel is not a directory"
 	exit 1
 fi
 
@@ -32,9 +32,38 @@
 	cp -R include/* $kernel/usr/include
 fi
 
+echo "Copying gzip"
+if [ ! -d $kernel/usr/gzip ]; then
+	mkdir -p $kernel/usr/gzip
+fi
+cp -R gzip/* $kernel/usr/gzip
+
+echo "Copying kinit ipconfig and nfsmount"
+if [ ! -d $kernel/usr/kinit ]; then
+	mkdir -p $kernel/usr/kinit
+fi
+cp -R usr/kinit/* $kernel/usr/kinit
+
+
+echo "Copying dash"
+if [ ! -d $kernel/usr/dash ]; then
+	mkdir -p $kernel/usr/dash
+fi
+cp -R dash/* $kernel/usr/dash
+
+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 kernel/Kbuild.*          $kernel/scripts
-cp kernel/Kbuild            $kernel/usr
+cp scripts/Kbuild.klibc       $kernel/scripts
+# Newer kernel versions have Kbuild.include, so do not overwrite it
+if [ ! -f $kernel/scripts/Kbuild.include ]; then
+	cp scripts/Kbuild.include $kernel/scripts
+fi
+cp usr/Kbuild               $kernel/usr
 cp klibc/Kbuild             $kernel/usr/klibc
 cp klibc/syscalls/Kbuild    $kernel/usr/klibc/syscalls
 cp klibc/socketcalls/Kbuild $kernel/usr/klibc/socketcalls
diff --git a/dash/Kbuild b/dash/Kbuild
new file mode 100644
index 0000000..25c6318
--- /dev/null
+++ b/dash/Kbuild
@@ -0,0 +1,118 @@
+#
+# Kbuild file for dash
+#
+
+YACC = bison -y
+
+COMMON_CFLAGS :=
+COMMON_CPPFLAGS := \
+	-DBSD=1 -DSMALL -DSHELL \
+	-DGLOB_BROKEN -DFNMATCH_BROKEN -DIFS_BROKEN \
+	-DJOBS=0
+
+CFLAGS := $(COMMON_CFLAGS)
+CPPFLAGS := $(COMMON_CPPFLAGS)
+CFLAGS_FOR_BUILD := $(COMMON_CFLAGS) 
+CPPFLAGS_FOR_BUILD := $(COMMON_CPPFLAGS)
+YFLAGS = -d
+
+DEFS := -DHAVE_CONFIG_H
+DEFAULT_INCLUDES := -I$(srctree)/$(src) -include $(srctree)/$(src)/config.h
+
+EXTRA_KLIBCCFLAGS := $(DEFS) $(DEFAULT_INCLUDES) $(CPPFLAGS) $(CFLAGS)
+HOST_EXTRACFLAGS := $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) 
+YACCCOMPILE = $(YACC) $(YFLAGS)
+
+SRCS :=	alias.c arith_yylex.c cd.c error.c eval.c exec.c expand.c \
+	histedit.c input.c jobs.c mail.c main.c memalloc.c miscbltin.c \
+	mystring.c options.c parser.c redir.c show.c trap.c output.c \
+	bltin/printf.c system.c bltin/test.c bltin/times.c var.c
+
+OBJ1 :=	builtins.o init.o nodes.o signames.o syntax.o
+OBJ2 :=	alias.o arith.o arith_yylex.o cd.o \
+	error.o eval.o exec.o expand.o \
+	histedit.o input.o jobs.o \
+	mail.o main.o memalloc.o \
+	miscbltin.o mystring.o options.o \
+	parser.o redir.o show.o trap.o \
+	output.o bltin/printf.o system.o \
+	bltin/test.o bltin/times.o var.o
+
+OBJS :=	$(OBJ1) $(OBJ2)
+
+HELPERS = mkinit mksyntax mknodes mksignames
+BUILT_SOURCES = arith.h builtins.h nodes.h syntax.h token.h
+CLEANFILES = \
+	$(BUILT_SOURCES) $(patsubst %.o,%.c,$(OBJ1)) \
+	arith.c $(HELPERS) builtins.def
+
+static-y := sh
+
+sh-y := $(OBJS)
+
+# The shared binary
+shared-y    := sh.shared
+sh.shared-y := $(sh-y)
+
+hostprogs-y := $(HELPERS)
+
+# For cleaning
+targets := $(static-y) $(shared-y) $(CLEANFILES)
+
+# Generate token.h
+$(obj)/parser.o: $(obj)/token.h
+
+quiet_cmd_mktokens = GEN     $@
+      cmd_mktokens = cd $(obj); sh $(srctree)/$<
+$(obj)/token.h: $(src)/mktokens
+	$(call cmd,mktokens)
+
+# Generate builtins.def
+targets += builtins.def
+quiet_cmd_mkbuiltins_def = GEN     $@
+      cmd_mkbuiltins_def = $(HOSTCC) $(hostc_flags) -x c -E -o $@ $<
+$(obj)/builtins.def: $(src)/builtins.def.in $(src)/config.h
+	$(call cmd,mkbuiltins_def)
+
+# Generate builtins{.c + .h}
+quiet_cmd_mkbuiltins = GEN     $@
+      cmd_mkbuiltins = cd $(obj); sh $(srctree)/$(src)/mkbuiltins builtins.def
+$(obj)/builtins.h $(obj)/builtins.c: $(src)/mkbuiltins $(obj)/builtins.def
+	$(call cmd,mkbuiltins)
+
+# Generate init.c
+quiet_cmd_mkinit = GEN     $@
+      cmd_mkinit = cd $(obj); ./mkinit $(addprefix $(srctree)/$(src)/, $(SRCS))
+$(obj)/init.c: $(obj)/mkinit $(addprefix $(src)/, $(SRCS))
+	$(call cmd,mkinit)
+
+# Generate nodes{.c + .h}
+quiet_cmd_mknodes = GEN     $@
+      cmd_mknodes = cd $(obj); ./mknodes $(srctree)/$(src)/nodetypes \
+			       $(srctree)/$(src)/nodes.c.pat
+$(obj)/nodes.c $(obj)/nodes.h: $(obj)/mknodes $(src)/nodetypes \
+			       $(src)/nodes.c.pat
+	$(call cmd,mknodes)
+
+quiet_cmd_mksyntax = GEN     $@
+      cmd_mksyntax = cd $(obj); ./mksyntax
+$(obj)/syntax.c $(obj)/syntax.h: $(obj)/mksyntax
+	$(call cmd,mksyntax)
+
+quiet_cmd_mksignames = GEN     $@
+      cmd_mksignames = cd $(obj); ./mksignames
+$(obj)/signames.c: $(obj)/mksignames
+	$(call cmd,mksignames)
+
+
+$(obj)/arith_yylex.o: $(obj)/arith.h
+
+$(obj)/arith.h $(obj)/arith.c: $(src)/arith.y
+	cd $(obj); \
+		$(YACCCOMPILE) $(srctree)/$<; \
+		mv y.tab.c arith.c; \
+		mv y.tab.h arith.h
+
+
+# Targets to install
+install-y := sh.shared
diff --git a/gzip/Kbuild b/gzip/Kbuild
new file mode 100644
index 0000000..c92eeea
--- /dev/null
+++ b/gzip/Kbuild
@@ -0,0 +1,29 @@
+#
+# Kbuild file for gzip
+#
+
+# The gzip executable
+static-y := gzip
+gzip-y   := gzip.o util.o unzip.o inflate.o
+
+# Additional targets 
+always := gunzip zcat gzip.stripped
+
+# Optional ZIP support
+gzip-$(CONFIG_KLIB_ZIP)   += zip.o deflate.o trees.o bits.o
+cflags-$(CONFIG_KLIB_ZIP) += -DSUPPORT_ZIP
+EXTRA_KLIBCCFLAGS := $(cflags-y)
+
+# Additionally linked targets
+$(obj)/gunzip $(obj)/zcat: $(obj)/gzip
+	$(call cmd,ln)
+
+# A stripped version of gzip
+$(obj)/gzip.stripped: $(obj)/gzip
+	$(call cmd,strip)
+
+# Cleaning
+targets := $(static-y) $(shared-y)
+
+# Targets to install
+install-y := gzip gunzip zcat
diff --git a/gzip/MCONFIG b/gzip/MCONFIG
deleted file mode 100644
index 66ba9bb..0000000
--- a/gzip/MCONFIG
+++ /dev/null
@@ -1,14 +0,0 @@
-# Things you might add to DEFS (configure usually figures out what to do):
-# -DGNU_STANDARD        Behave as gzip even if invoked as gunzip (GNU standard)
-# -DPROTO		Force function prototypes even if __STDC__ not defined
-# -DDEBUG		Debug code
-# -DDYN_ALLOC		Use dynamic allocation of large data structures
-# -DRECORD_IO           read() and write() are rounded to record sizes.
-# -DNO_SIZE_CHECK       stat() does not give a reliable file size
-
-DEFS    =
-
-WARNFLAGS = -W -Wall -Wsign-compare
-
-# Set this to y if you want to enable compression support
-ZIP     = n
diff --git a/gzip/Makefile b/gzip/Makefile
deleted file mode 100644
index d5f9f94..0000000
--- a/gzip/Makefile
+++ /dev/null
@@ -1,79 +0,0 @@
-# Generated automatically from Makefile.in by configure.
-# Makefile for gzip (GNU zip)    -*- Indented-Text -*-
-# Copyright (C) 1992-1993 Jean-loup Gailly and the Free Software Foundation
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-# $Id: Makefile,v 1.6 2005/03/01 22:36:46 hpa Exp $
-
-#### Start of system configuration section. ####
-
-SRCROOT = ..
-include ../MCONFIG
-include MCONFIG
-include ../MRULES
-
-#### End of system configuration section. ####
-
-MAKEDEPS = -Wp,-MD,.$(subst /,-,$*).d
-CFLAGS   = $(MAKEDEPS) $(DEFS) $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS)
-
-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)
-
-$(CRT0) $(LIBS):
-	@echo '*** error: $@ not up to date' || exit 1
-
-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
-
-ifneq ($(wildcard .*.d),)
-include $(wildcard .*.d)
-endif
diff --git a/include/bits32/bitsize/stddef.h b/include/bits32/bitsize/stddef.h
index c486041..3cf41ad 100644
--- a/include/bits32/bitsize/stddef.h
+++ b/include/bits32/bitsize/stddef.h
@@ -6,7 +6,7 @@
 #define _BITSIZE_STDDEF_H
 
 #define _SIZE_T
-#if defined(__s390__) || defined(__hppa__) || defined(__cris__)
+#if defined(__s390__) || defined(__cris__)
 typedef unsigned long size_t;
 #else
 typedef unsigned int size_t;
diff --git a/ipconfig/MCONFIG b/ipconfig/MCONFIG
deleted file mode 100644
index 472f092..0000000
--- a/ipconfig/MCONFIG
+++ /dev/null
@@ -1,8 +0,0 @@
-# -*- makefile -*-
-
-SRCROOT = ..
-
-include $(SRCROOT)/MCONFIG
-include $(SRCROOT)/MRULES
-
-CFLAGS = -Wp,-MD,$(dir $@).$(notdir $@).d $(OPTFLAGS) $(REQFLAGS) -Wstrict-prototypes -Wall -I.
diff --git a/ipconfig/Makefile b/ipconfig/Makefile
deleted file mode 100644
index c186452..0000000
--- a/ipconfig/Makefile
+++ /dev/null
@@ -1,44 +0,0 @@
-include MCONFIG
-
-COMMON_OBJS = main.o netdev.o packet.o
-DHCP_OBJS   = dhcp_proto.o
-BOOTP_OBJS  = bootp_proto.o
-PROGS       = ipconfig
-STATICPROGS := $(patsubst %,static/%,$(PROGS))
-SHAREDPROGS := $(patsubst %,shared/%,$(PROGS))
-LIB	    = libipconfig.a
-LIBS        = $(KLIBC) $(LIBGCC)
-
-OBJS := $(COMMON_OBJS) $(BOOTP_OBJS) $(DHCP_OBJS)
-
-all:	$(STATICPROGS) $(SHAREDPROGS) $(LIB)
-
-static/ipconfig: $(OBJS) $(CRT0) $(LIBS)
-	mkdir -p static static.g
-	$(LD) $(LDFLAGS) -o $@ $(CRT0) $(OBJS) $(LIBS)
-	cp -f $@ static.g
-	$(STRIPCMD) $@
-
-shared/ipconfig: $(OBJS) $(CRTSHARED) $(LIBSHARED) $(LIBGCC)
-	mkdir -p shared shared.g
-	$(LD) $(LDFLAGS) -o $@ $(EMAIN) $(CRTSHARED) $(OBJS) \
-		-R $(LIBSHARED) $(LIBGCC)
-	cp -f $@ shared.g
-	$(STRIPCMD) $@
-
-$(LIB): $(OBJS)
-	$(AR) cru $(LIB) $(OBJS)
-
-clean:
-	$(RM) *.o $(PROG) $(LIB) core
-	$(RM) -r static static.g shared shared.g
-
-spotless: clean
-	$(RM) *~ .*.d
-
-install: all
-	$(INSTALL_EXEC) shared/* $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)bin
-
-ifneq ($(wildcard .*.d),)
-include $(wildcard .*.d)
-endif
diff --git a/kernel/Kbuild.include b/kernel/Kbuild.include
deleted file mode 100644
index e917947..0000000
--- a/kernel/Kbuild.include
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# Generic kbuild routines
-#
-
-# The temporary file to save gcc -MD generated dependencies must not
-# contain a comma
-depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
-
-
-ifneq ($(KBUILD_NOCMDDEP),1)
-# Check if both arguments has same arguments. Result in empty string if equal
-# User may override this check using make KBUILD_NOCMDDEP=1
-arg-check = $(strip $(filter-out $(1), $(2)) $(filter-out $(2), $(1)) )
-
-endif
-
-# If quiet is set, only print short version of command
-cmd = @$(if $($(quiet)cmd_$(1)),\
-      echo '  $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1))
-
-
-# echo command. Short version is $(quiet) equals quiet, otherwise full command
-echo-cmd = $(if $($(quiet)cmd_$(1)), \
-	echo '  $(subst ','\'',$($(quiet)cmd_$(1)))';)
-
-# function to only execute the passed command if necessary
-# >'< substitution is for echo to work,
-# >$< substitution to preserve $ when reloading .cmd file
-# note: when using inline perl scripts [perl -e '...$$t=1;...'] in
-#       $(cmd_xxx) double $$ your perl vars
-# 
-if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
-	@set -e; \
-	$(echo-cmd) \
-	$(cmd_$(1)); \
-	echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' \
-	  > $(@D)/.$(@F).cmd)
-
-
-# execute the command and also postprocess generated .d dependencies
-# file
-if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^) \
-	$(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),                   \
-	@set -e; \
-	$(echo-cmd) \
-	$(cmd_$(1)); \
-	scripts/basic/fixdep $(depfile) $@ \
-	  '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
-	rm -f $(depfile); \
-	mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
-
-
diff --git a/kernel/Kbuild.klibc b/kernel/Kbuild.klibc
deleted file mode 100644
index 39b8d32..0000000
--- a/kernel/Kbuild.klibc
+++ /dev/null
@@ -1,281 +0,0 @@
-# ==========================================================================
-# Support for building klibc and related programs
-# ==========================================================================
-#
-# To create a kbuild file for a userspace program do the following:
-#
-# Kbuild:
-# 
-# user-progs := cat
-#
-# This will compile a file named cat.c -> the executable 'cat'
-# 
-# If the user space program consist of more files do the following:
-# Kbuild:
-#
-# user-progs := ipconfig
-# ipconfig-y := main.o netdev.c
-
-src := $(obj)
-
-.phony: __build
-__build:
-
-# Generic Kbuild routines
-include $(srctree)/scripts/Kbuild.include
-
-# Defines used when compiling early userspace (klibc programs)
-# ---------------------------------------------------------------------------
-KLIBSRC         := usr/klibc
-
-# Arch specific definitions for klibc
-include $(KLIBSRC)/arch/$(ARCH)/MCONFIG
-
-USERWARNFLAGS   := -Wall -Wpointer-arith -Wwrite-strings                 \
-                   -Wstrict-prototypes -Winline
-
-USERCROSS       := $(CROSS_COMPILE)
-
-USERLD          := $(USERCROSS)ld
-USERCC          := $(USERCROSS)gcc
-USERAR          := $(USERCROSS)ar
-USERRANLIB      := $(USERCROSS)ranlib
-USERSTRIP       := $(USERCROSS)strip
-USERNM          := $(USERCROSS)nm
-
-USERCPPFLAGS    := -I$(srctree)/usr/include/arch/$(ARCH)                 \
-                   -I$(srctree)/usr/include/bits$(BITSIZE)               \
-                   -I$(srctree)/usr/include                              \
-                   -Iinclude                                             \
-                   $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include)   \
-                   -D__KLIBC__ -DBITSIZE=$(BITSIZE)
-USERCFLAGS      := $(USERCPPFLAGS) $(ARCHREQFLAGS) $(OPTFLAGS)           \
-                   $(USERWARNFLAGS)
-USERAFLAGS      := -D__ASSEMBLY__ $(USERCPPFLAGS)
-USERSTRIPFLAGS  := --strip-all -R .comment -R .note
-
-USERLIBGCC      := $(shell $(USERCC) --print-libgcc)
-USERSHAREDFLAGS := $(SHAREDFLAGS)
-USERCRT0        := $(objtree)/$(KLIBSRC)/arch/$(ARCH)/crt0.o
-USERLIBC        := $(objtree)/$(KLIBSRC)/libc.a
-
-#
-# This indicates the location of the final version of the shared library.
-# THIS MUST BE AN ABSOLUTE PATH WITH NO FINAL SLASH.
-# Leave this empty to make it the root.
-#
-SHLIBDIR = /lib
-
-export USERLD USERCC USERAR USERSTRIP USERNM
-export USERCFLAGS USERAFLAGS USERLIBGCC USERSHAREDFLAGS USERSTRIPFLAGS
-export USERCRT0 USERLIBC SHLIBDIR
-
-# kernel configuration
-include .config
-
-# Add $(obj)/ for paths that is not absolute
-objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
-
-# Kbuild file in the directory that is being build
-include $(obj)/Kbuild
-
-#####
-# user-progs := handling
-
-# user-progs based on a single .c file (with same name)
-user-single := $(foreach p, $(user-progs), $(if $($(p)-y),,$(p)))
-
-# user-progs which is based on several .o files
-user-multi  := $(foreach p, $(user-progs), $(if $($(p)-y),$(p)))
-# objects used for user-progs with more then one .o file
-user-multi-objs := $(foreach p, $(user-multi), $($(p)-y))
-# objects build in this dir
-user-real-objs := $(patsubst %/,,$(user-multi-objs))
-# Directories we need to visit before user-multi-obs are up-to-date
-user-dirs :=  $(patsubst %/,%,$(filter %/, $(user-multi-objs))) 
-# replace all dir/ with dir/built-in.o
-user-multi-objs := $(patsubst %/, %/built-in.o, $(user-multi-objs))
-
-# $(output-dirs) are a list of directories that contain object files
-output-dirs := $(dir $(user-dirs))
-output-dirs += $(foreach f, $(hostprogs-y) $(targets), \
-               $(if $(dir $(f)), $(dir $(f))))
-output-dirs := $(strip $(sort $(filter-out ./,$(output-dirs))))
-
-# prefix so we get full dir
-user-progs      := $(addprefix $(obj)/,$(user-progs))
-user-single     := $(addprefix $(obj)/,$(user-single))
-user-multi      := $(addprefix $(obj)/,$(user-multi))
-user-multi-objs := $(addprefix $(obj)/,$(user-multi-objs))
-user-real-objs  := $(addprefix $(obj)/,$(user-real-objs))
-output-dirs     := $(addprefix $(obj)/,$(output-dirs))
-user-dirs       := $(addprefix $(obj)/,$(user-dirs))
-subdir-y        := $(addprefix $(obj)/,$(subdir-y))
-always          := $(addprefix $(obj)/,$(always))
-targets         := $(addprefix $(obj)/,$(targets))
-
-
-_usercflags    = $(USERCFLAGS) $(EXTRA_USERCFLAGS) $(USERCFLAGS_$(*F).o)
-_useraflags    = $(USERAFLAGS) $(EXTRA_USERAFLAGS) $(USERAFLAGS_$(*F).o)
-
-usercflags     = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(_usercflags)
-useraflags     = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(_useraflags)
-
-ifneq ($(KBUILD_SRC),)
-# Create output directory if not already present
-_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
-
-# Create directories for object files if directory does not exist
-# Needed when obj-y := dir/file.o syntax is used
-_dummy := $(foreach d,$(output-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
-endif
-
-# Do we have to make a built-in.o in this dir?
-ifneq ($(strip $(obj-y) $(obj-n) $(obj-)),)
-builtin-target := $(obj)/built-in.o
-endif
-
-__build: $(subdir-y) $(builtin-target) $(always)
-	@:
-
-# Compile C sources (.c)
-# ---------------------------------------------------------------------------
-
-quiet_cmd_cc_s_c = USERCC  $@
-      cmd_cc_s_c = $(USERCC) $(usercflags) -S -o $@ $< 
-
-%.s: %.c FORCE
-	$(call if_changed_dep,cc_s_c)
-
-quiet_cmd_cc_i_c = USERCPP $@
-      cmd_cc_i_c = $(USERCPP) $(usercflags)   -o $@ $<
-
-%.i: %.c FORCE
-	$(call if_changed_dep,cc_i_c)
-
-quiet_cmd_cc_o_c = USERCC  $@
-      cmd_cc_o_c = $(USERCC) $(usercflags) -c -o $@ $<
-
-%.o: %.c FORCE
-	$(call if_changed_dep,cc_o_c)
-
-# Compile assembler sources (.S)
-# ---------------------------------------------------------------------------
-
-quiet_cmd_as_s_S = USERCPP $@
-      cmd_as_s_S = $(USERCPP) $(useraflags)   -o $@ $< 
-
-%.s: %.S FORCE
-	$(call if_changed_dep,as_s_S)
-
-quiet_cmd_as_o_S = USERAS  $@
-      cmd_as_o_S = $(USERCC) $(useraflags) -c -o $@ $<
-
-%.o: %.S FORCE
-	$(call if_changed_dep,as_o_S)
-
-targets += $(real-objs-y)
-
-#
-# Rule to compile a set of .o files into one .o file
-#
-ifdef builtin-target
-quiet_cmd_link_o_target = LD      $@
-# If the list of objects to link is empty, just create an empty built-in.o
-cmd_link_o_target = $(if $(strip $(obj-y)),\
-                    $(USERLD) $(USERLDFLAGS) -r -o $@ $(filter $(obj-y), $^),\
-                    rm -f $@; $(AR) rcs $@)
-
-$(builtin-target): $(obj-y) FORCE
-	$(call if_changed,link_o_target)
-targets += $(builtin-target)
-endif # builtin-target
-
-
-ifdef user-progs
-# Compile userspace programs for the target
-# ===========================================================================
-
-__build : $(user-dirs) $(user-progs)
-
-# Descend if needed
-$(sort $(addsuffix /built-in.o,$(user-dirs))): $(user-dirs) ;
-
-quiet_cmd_user-ld-single = USERLD  $@
-      cmd_user-ld-single = $(USERLD) $(USERLDFLAGS) -o $@      \
-                           $(USERCRT0) $<                      \
-                           $(filter-out FORCE,$^)              \
-                           $(USERLIBC) $(USERLIBGCC)           \
-                           $(USERLIBGCC);                      \
-                           $(USERSTRIP) $(USERSTRIPFLAGS) $@
-
-$(user-single): %: %.o $(USERCRT0) $(USERLIBC) FORCE
-	$(call if_changed,user-ld-single)
-
-targets += $(user-single) $(user-single:=.o)
-
-multi-deps = $($(subst $(obj)/,,$@-y))
-link-multi-deps = $(addprefix $(obj)/, \
-                    $(patsubst %/, %/built-in.o, $(multi-deps)))
-
-quiet_cmd_user-ld-multi = USERLD  $@
-      cmd_user-ld-multi = $(USERLD) $(USERLDFLAGS) -o $@       \
-                           $(USERCRT0)                         \
-                           $(link-multi-deps)                  \
-                           $(USERLIBC) $(USERLIBGCC)           \
-                           $(USERLIBGCC);                      \
-                           $(USERSTRIP) $(USERSTRIPFLAGS) $@
-
-$(user-multi): $(user-multi-objs) FORCE
-	$(call if_changed,user-ld-multi)
-
-targets += $(user-multi) $(user-real-objs)
-endif
-
-
-# Compile programs on the host
-# ===========================================================================
-ifdef hostprogs-y
-include $(srctree)/scripts/Makefile.host
-endif
-
-# Descending
-# ---------------------------------------------------------------------------
-
-.PHONY: $(subdir-y) $(user-dirs)
-$(subdir-y) $(user-dirs):
-	$(Q)$(MAKE) $(klibc)=$@
-
-# Add FORCE to the prequisites of a target to force it to be always rebuilt.
-# ---------------------------------------------------------------------------
-
-.PHONY: FORCE
-
-FORCE:
-
-# Linking
-# Create a reloctable composite object file
-# ---------------------------------------------------------------------------
-quiet_cmd_userld = USERLD  $@
-      cmd_userld = $(USERLD) -r $(USERLDFLAGS) \
-                                $(EXTRA_USERLDFLAGS) $(USERLDFLAGS_$(@F)) \
-                                $(filter-out FORCE,$^) -o $@
-
-
-# Read all saved command lines and dependencies for the $(targets) we
-# may be building above, using $(if_changed{,_dep}). As an
-# optimization, we don't need to read them if the target does not
-# exist, we will rebuild anyway in that case.
-
-targets := $(wildcard $(sort $(targets)))
-cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
-
-ifneq ($(cmd_files),)
-  include $(cmd_files)
-endif
-
-# Shorthand for $(Q)$(MAKE) -f scripts/Kbuild.klibc obj
-# Usage:
-# $(Q)$(MAKE) $(klibc)=dir
-klibc := -rR -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Kbuild.klibc obj
-
diff --git a/kinit/Makefile b/kinit/Makefile
deleted file mode 100644
index 6ac41ea..0000000
--- a/kinit/Makefile
+++ /dev/null
@@ -1,38 +0,0 @@
-SRCROOT = ..
-include $(SRCROOT)/MCONFIG
-include $(SRCROOT)/MRULES
-
-MAKEDEPS = -Wp,-MD,.$(subst /,-,$*).d
-CFLAGS	= $(MAKEDEPS) $(OPTFLAGS) $(REQFLAGS) -W -Wall \
-	-I$(SRCROOT)/ipconfig \
-	-I$(SRCROOT)/nfsmount \
-#	-DINI_DEBUG -g
-
-LIBS	= \
-	$(SRCROOT)/nfsmount/libnfsmount.a \
-	$(SRCROOT)/ipconfig/libipconfig.a \
-	$(KLIBC) $(LIBGCC)
-PROGS	= kinit
-OBJS	= kinit.o do_mounts.o nfsroot.o getintfile.o initrd.o \
-	  open.o readfile.o
-
-all: $(PROGS)
-
-kinit: $(OBJS) $(LIBS) $(CRT0)
-	$(LD) $(LDFLAGS) -o $@ $(CRT0) $(OBJS) $(LIBS)
-	cp -f $@ $@.g
-	$(STRIPCMD) $@
-
-clean:
-	-rm -f *.o *.g kinit
-
-spotless: clean
-	-rm -f .*.d *~
-
-# This should perhaps be a shared binary?
-install: all
-	$(INSTALL_EXEC) $(PROGS) $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)bin
-
-ifneq ($(wildcard .*.d),)
-include $(wildcard .*.d)
-endif
diff --git a/klcc/Kbuild b/klcc/Kbuild
new file mode 100644
index 0000000..368bf36
--- /dev/null
+++ b/klcc/Kbuild
@@ -0,0 +1,44 @@
+#
+# Build klcc
+#
+
+always := $(KLIBCCROSS)klcc
+
+$(obj)/$(KLIBCCROSS)klibc.config: $(src)/Kbuild \
+				  $(srctree)/Makefile \
+                                  $(srctree)/scripts/Kbuild.klibc
+	@echo "  GEN     $@"
+	$(Q)rm -f $@
+	$(Q)echo 'ARCH=$(ARCH)' >> $@
+	$(Q)echo 'CROSS=$(KLIBCCROSS)' >> $@
+	$(Q)echo 'KCROSS=$(KCROSS)' >> $@
+	$(Q)echo 'CC=$(KLIBCCC)' >> $@
+	$(Q)echo 'LD=$(KLIBCLD)' >> $@
+	$(Q)echo 'REQFLAGS=$(filter-out -I%,$(KLIBCREQFLAGS))' >> $@
+	$(Q)echo 'OPTFLAGS=$(KLIBCOPTFLAGS)' >> $@
+	$(Q)echo 'LDFLAGS=$(KLIBCLDFLAGS)' >> $@
+	$(Q)echo 'STRIP=$(KLIBCSTRIP)' >> $@
+	$(Q)echo 'STRIPFLAGS=$(KLIBCSTRIPFLAGS)' >> $@
+	$(Q)echo 'EMAIN=$(KLIBCEMAIN)' >> $@
+	$(Q)echo 'BITSIZE=$(KLIBCBITSIZE)' >> $@
+	$(Q)echo 'prefix=$(INSTALLDIR)' >> $@
+	$(Q)echo 'bindir=$(INSTALLDIR)/$(KCROSS)bin' >> $@
+	$(Q)echo 'libdir=$(INSTALLDIR)/$(KCROSS)lib' >> $@
+	$(Q)echo 'includedir=$(INSTALLDIR)/$(KCROSS)include' >> $@
+
+
+# Generate klcc
+targets := $(KLIBCCROSS)klcc
+
+quiet_cmd_klcc = GEN     $@
+      cmd_klcc = $(PERL) $< $(srctree)/$(src)/klcc.in \
+                            $(obj)/$(KLIBCCROSS)klibc.config \
+                            $(shell bash -c 'type -p $(PERL)') \
+			      > $@ || ( rm -f $@ ; exit 1 ) && \
+			      chmod a+x $@
+$(obj)/$(KLIBCCROSS)klcc: $(src)/makeklcc.pl $(src)/klcc.in \
+                          $(obj)/$(KLIBCCROSS)klibc.config
+	$(call if_changed,klcc)
+
+# Cleaning targets
+clean-files := $(KLIBCCROSS)klibc.config $(KLIBCCROSS)klcc
diff --git a/klcc.1 b/klcc/klcc.1
similarity index 100%
rename from klcc.1
rename to klcc/klcc.1
diff --git a/klcc.in b/klcc/klcc.in
similarity index 100%
rename from klcc.in
rename to klcc/klcc.in
diff --git a/makeklcc.pl b/klcc/makeklcc.pl
similarity index 100%
rename from makeklcc.pl
rename to klcc/makeklcc.pl
diff --git a/klibc.spec.in b/klibc.spec.in
index eef5dbf..f9c75ef 100644
--- a/klibc.spec.in
+++ b/klibc.spec.in
@@ -82,8 +82,8 @@
 
 install -m 444 gzip/COPYING %{buildroot}%{bindocdir}/COPYING.gzip
 install -m 444 gzip/README %{buildroot}%{bindocdir}/README.gzip
-install -m 444 ipconfig/README %{buildroot}%{bindocdir}/README.ipconfig
-install -m 444 kinit/README %{buildroot}%{bindocdir}/README.kinit
+install -m 444 usr/kinit/ipconfig/README %{buildroot}%{bindocdir}/README.ipconfig
+install -m 444 usr/kinit/README %{buildroot}%{bindocdir}/README.kinit
 
 %clean
 rm -rf $RPM_BUILD_ROOT
diff --git a/klibc/Kbuild b/klibc/Kbuild
index be239a6..401486c 100644
--- a/klibc/Kbuild
+++ b/klibc/Kbuild
@@ -9,7 +9,7 @@
 	  atoi.o atol.o atoll.o \
 	  strtol.o strtoll.o strtoul.o strtoull.o \
 	  strtoimax.o strtoumax.o \
-	  globals.o exitc.o atexit.o onexit.o \
+	  globals.o exit.o atexit.o onexit.o \
 	  execl.o execle.o execv.o execvpe.o execvp.o execlp.o execlpe.o \
 	  fork.o wait.o wait3.o waitpid.o system.o setpgrp.o getpgrp.o \
 	  daemon.o \
@@ -32,6 +32,7 @@
 	  gethostname.o getdomainname.o getcwd.o \
 	  seteuid.o setegid.o \
 	  getenv.o setenv.o putenv.o __put_env.o unsetenv.o \
+	  clearenv.o nullenv.o \
 	  getopt.o readdir.o \
 	  syslog.o closelog.o pty.o getpt.o isatty.o reboot.o \
 	  time.o utime.o llseek.o nice.o getpriority.o \
@@ -48,6 +49,9 @@
 	zlib/uncompr.o zlib/deflate.o zlib/trees.o zlib/zutil.o \
 	zlib/inflate.o zlib/infback.o zlib/inftrees.o zlib/inffast.o
 
+# zlib specific flag
+EXTRA_CFLAGS := -DDYNAMIC_CRC_TABLE
+
 #####
 # Add any architecture-specific rules
 include $(obj)/arch/$(ARCH)/Makefile.inc
@@ -67,6 +71,8 @@
 CRT0     := $(call objectify,$(CRT0))
 INTERP_O := $(call objectify,$(INTERP_O))
 
+SOLIBHASH = $(shell cat $(SOLIB).hash)
+
 targets  := arch/$(ARCH)/crt0.o
 targets  += $(libc-y) $(ARCHOBJS)
 
@@ -95,10 +101,10 @@
 ######
 # Build static library: libc.a
 targets += libc.a __static_init.o
-quiet_cmd_libc = USERAR  $@
+quiet_cmd_libc = KLIBCAR $@
       cmd_libc = rm -f $@; \
-                 $(USERAR) cq $@ $(filter-out FORCE,$^); \
-                 $(USERRANLIB) $@
+                 $(KLIBCAR) cq $@ $(filter-out FORCE,$^); \
+                 $(KLIBCRANLIB) $@
 
 $(LIB): $(call objectify,__static_init.o) $(libc-deps) FORCE
 	$(call if_changed,libc)
@@ -107,9 +113,9 @@
 # Build shared library
 targets += libc.so __shared_init.o
 
-quiet_cmd_libcso = LD      $@
-      cmd_libcso = $(USERLD) $(USERLDFLAGS) $(USERSHAREDFLAGS) \
-                             -o $@ $(filter-out FORCE,$^) $(USERLIBGCC)
+quiet_cmd_libcso = KLIBCLD $@
+      cmd_libcso = $(KLIBCLD) $(KLIBCLDFLAGS) $(KLIBCSHAREDFLAGS) \
+                             -o $@ $(filter-out FORCE,$^) $(KLIBCLIBGCC)
 
 $(SOLIB): $(CRT0) $(call objectify,__shared_init.o) $(libc-deps) FORCE
 	$(call if_changed,libcso)
@@ -119,18 +125,19 @@
 # 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] ' | \
+      cmd_solibhash = $(KLIBCNM) $< | egrep '^[0-9a-fA-F]+ [ADRTW] ' | \
                                         sort | $(obj)/sha1hash > $@
 $(SOLIB).hash: $(SOLIB) $(obj)/sha1hash FORCE
 	$(call if_changed,solibhash)
 
 quiet_cmd_sohash = GEN     $@
       cmd_sohash = cat $< > $@;                                           \
-                     $(USERSTRIP) $(USERSTRIPFLAGS) $@;                   \
-                     rm -f $(obj)/klibc-??????????????????????.so;        \
-                     ln -f $@ $(obj)/klibc-`cat $(SOLIB).hash`.so
+                     $(KLIBCSTRIP) $(KLIBCSTRIPFLAGS) $@;                   \
+                     rm -f $(obj)/klibc-???????????????????????????.so;   \
+                     ln -f $@ $(obj)/klibc-$(SOLIBHASH).so
 $(SOHASH): $(SOLIB) $(SOLIB).hash
 	$(call cmd,sohash)
 
@@ -139,11 +146,23 @@
 # build interp.o
 targets += interp.o
 
-quiet_cmd_interp = BUILD  $@
-      cmd_interp = $(USERCC) $(usercflags) -D__ASSEMBLY__     \
+quiet_cmd_interp = BUILD   $@
+      cmd_interp = $(KLIBCCC) $(klibccflags) -D__ASSEMBLY__     \
                              -DLIBDIR=\"$(SHLIBDIR)\"         \
-			     -DSOHASH=\"`cat $(SOLIB).hash`\" \
+			     -DSOHASH=\"$(SOLIBHASH)\" \
 			     -c -o $@ $<
 
 $(INTERP_O): $(obj)/interp.S $(SOLIB).hash
 	$(call if_changed,interp)
+
+#####
+# Install klibc
+install-rule:
+	@echo "  INSTALL klibc to $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)lib"
+	$(Q)$(foreach f, $(LIB) $(SOLIB) $(CRT0) $(INTERP_O), \
+	  $(shell $(install-data) $(f) \
+	          $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)lib))
+	$(Q)$(install-lib) $(obj)/klibc-$(SOLIBHASH).so \
+	                      $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)lib
+	$(Q)$(install-lib) $(obj)/klibc-$(SOLIBHASH).so \
+	                      $(INSTALLROOT)$(SHLIBDIR)
diff --git a/klibc/MCONFIG b/klibc/MCONFIG
deleted file mode 100644
index 24af09d..0000000
--- a/klibc/MCONFIG
+++ /dev/null
@@ -1,20 +0,0 @@
-# -*- makefile -*-
-#
-# Makefile configuration, without explicit rules
-#
-
-SRCROOT = ..
-include ../MCONFIG
-include ../MRULES
-
-WARNFLAGS = -W -Wall -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Winline
-
-ifeq ($(ERRLIST),1)
-REQFLAGS += -DWITH_ERRLIST
-endif
-
-CFLAGS  = -Wp,-MT,$@,-MD,$(dir $@).$(notdir $@).d $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS)
-INCLUDE += -I./zlib
-CFLAGS  += -DDYNAMIC_CRC_TABLE
-
-SOFLAGS = -fPIC
diff --git a/klibc/Makefile b/klibc/Makefile
deleted file mode 100644
index f7b8ac5..0000000
--- a/klibc/Makefile
+++ /dev/null
@@ -1,193 +0,0 @@
-#
-# Makefile
-#
-# Main makefile
-#
-
-# Include configuration rules
-include MCONFIG
-
-INCLUDE += -I./zlib
-
-TESTS   = $(patsubst %.c,%,$(wildcard tests/*.c)) \
-	  $(patsubst %.c,%.shared,$(wildcard tests/*.c))
-LIBOBJS = vsnprintf.o snprintf.o vsprintf.o sprintf.o \
-	  asprintf.o vasprintf.o \
-	  vsscanf.o sscanf.o ctypes.o \
-	  strntoumax.o strntoimax.o \
-	  atoi.o atol.o atoll.o \
-	  strtol.o strtoll.o strtoul.o strtoull.o \
-	  strtoimax.o strtoumax.o \
-	  globals.o exit.o atexit.o onexit.o \
-	  execl.o execle.o execv.o execvpe.o execvp.o execlp.o execlpe.o \
-	  fork.o wait.o wait3.o waitpid.o system.o setpgrp.o getpgrp.o \
-	  daemon.o \
-	  printf.o vprintf.o fprintf.o vfprintf.o perror.o \
-	  statfs.o fstatfs.o umount.o \
-	  open.o fopen.o fread.o fread2.o fgetc.o fgets.o \
-	  fwrite.o fwrite2.o fputc.o fputs.o puts.o putchar.o \
-	  sleep.o usleep.o strtotimespec.o strtotimeval.o \
-	  raise.o abort.o assert.o alarm.o pause.o \
-	  __signal.o sysv_signal.o bsd_signal.o siglist.o siglongjmp.o \
-	  sigaction.o sigpending.o sigprocmask.o sigsuspend.o \
-	  brk.o sbrk.o malloc.o realloc.o calloc.o mmap.o \
-	  memcpy.o memcmp.o memset.o memccpy.o memmem.o memswap.o \
-	  memmove.o memchr.o memrchr.o \
-	  strcasecmp.o strncasecmp.o strndup.o strerror.o \
-	  strcat.o strchr.o strcmp.o strcpy.o strdup.o strlen.o strnlen.o \
-	  strncat.o strlcpy.o strlcat.o \
-	  strstr.o strncmp.o strncpy.o strrchr.o \
-	  strxspn.o strspn.o strcspn.o strpbrk.o strsep.o strtok.o \
-	  gethostname.o getdomainname.o getcwd.o \
-	  seteuid.o setegid.o \
-	  getenv.o setenv.o putenv.o __put_env.o unsetenv.o \
-	  clearenv.o nullenv.o \
-	  getopt.o readdir.o \
-	  syslog.o closelog.o pty.o getpt.o isatty.o reboot.o \
-	  time.o utime.o llseek.o nice.o getpriority.o \
-	  qsort.o \
-	  lrand48.o jrand48.o mrand48.o nrand48.o srand48.o seed48.o \
-	  inet/inet_ntoa.o inet/inet_aton.o inet/inet_addr.o \
-	  inet/inet_ntop.o inet/inet_pton.o inet/bindresvport.o \
-	  send.o recv.o
-
-ifeq ($(ERRLIST),1)
-LIBOBJS += errlist.o
-endif
-
-ifeq ($(ZLIB),1)
-LIBOBJS += zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/gzio.o \
-	   zlib/uncompr.o zlib/deflate.o zlib/trees.o zlib/zutil.o \
-	   zlib/inflate.o zlib/infback.o zlib/inftrees.o zlib/inffast.o
-endif
-
-SOLIB   = libc.so
-SOHASH  = klibc.so
-
-CRT0    = crt0.o
-LIB     = libc.a
-
-INTERP_O = interp.o
-
-all: tests $(CRT0) $(LIB) $(SOLIB) $(SOHASH) $(INTERP_O)
-
-# Add any architecture-specific rules
-include arch/$(ARCH)/Makefile.inc
-EMAIN ?= -e main
-
-tests: $(TESTS)
-
-tests/%.o : tests/%.c
-	$(CC) $(CFLAGS) -c -o $@ $<
-
-# This particular file uses a bunch of formats gcc don't know of, in order
-# to test the full range of our vsnprintf() function.  This outputs a bunch
-# of useless warnings unless we tell it not to.
-tests/testvsnp.o : tests/testvsnp.c
-	$(CC) $(CFLAGS) -Wno-format -c -o $@ $<
-
-tests/% : tests/%.o $(LIB) $(CRT0)
-	$(LD) $(LDFLAGS) -o $@ $(CRT0) $< $(LIB) $(LIBGCC)
-	cp $@ $@.stripped
-	$(STRIPCMD) $@.stripped
-
-tests/%.shared : tests/%.o interp.o $(SOLIB)
-	$(LD) $(LDFLAGS) -o $@ $(EMAIN) interp.o tests/$*.o -R $(SOLIB) $(LIBGCC)
-	cp $@ $@.stripped
-	$(STRIPCMD) $@.stripped
-
-$(LIB): __static_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj
-	rm -f $(LIB)
-	$(AR) cq $(LIB) __static_init.o $(LIBOBJS) $(ARCHOBJS) \
-		$(wildcard syscalls/*.o) $(wildcard socketcalls/*.o)
-	$(RANLIB) $(LIB)
-
-$(SOLIB): $(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj
-	$(LD) $(LDFLAGS) $(SHAREDFLAGS) -o $@ \
-		$(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) \
-	        $(wildcard syscalls/*.o) $(wildcard socketcalls/*.o) \
-		$(LIBGCC)
-
-sha1hash: sha1hash.c
-	$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $<
-
-$(SOLIB).hash: $(SOLIB) sha1hash
-	$(NM) $(SOLIB) | \
-		egrep '^[0-9a-fA-F]+ [ADRTW] ' | sort | ./sha1hash > $@
-
-$(SOHASH): $(SOLIB) $(SOLIB).hash
-	cp -f $(SOLIB) $@
-	$(STRIPCMD) $@
-	rm -f klibc-??????????????????????.so
-	ln -f $@ klibc-`cat $(SOLIB).hash`.so
-
-$(INTERP_O): interp.S $(SOLIB).hash
-	$(CC) $(CFLAGS) -D__ASSEMBLY__ -DLIBDIR=\"$(SHLIBDIR)\" \
-		-DSOHASH=\"`cat $(SOLIB).hash`\" \
-		-c -o $@ $<
-
-crt0.o: arch/$(ARCH)/crt0.o
-	cp arch/$(ARCH)/crt0.o .
-
-errlist.c:
-	$(PERL) makeerrlist.pl -q $(INCLUDE) -errlist > $@ || rm -f $@
-
-# We pass -ansi to keep cpp from define e.g. "i386" as well as "__i386__"
-SYSCALLS.i: SYSCALLS.def
-	$(CC) $(CFLAGS) -D__ASSEMBLY__ -ansi -x assembler-with-cpp -E -o $@ $<
-
-syscalls.nrs: ../include/sys/syscall.h
-	$(CC) $(CFLAGS) -Wp,-dM -x c -E -o $@ $<
-
-syscalls.dir: SYSCALLS.i syscalls.pl arch/$(ARCH)/sysstub.ph syscommon.h syscalls.nrs
-	rm -f syscalls/*.[Ssco] syscalls/*.obj
-	mkdir -p syscalls
-	$(PERL) syscalls.pl SYSCALLS.i arch/$(ARCH)/sysstub.ph $(ARCH) \
-		$(BITSIZE) syscalls.nrs \
-		syscalls ../include/klibc/havesyscall.h
-	touch $@
-
-../include/klibc/havesyscall.h: syscalls.dir
-	: Generated by side effect
-
-socketcalls.dir: SOCKETCALLS.def socketcalls.pl socketcommon.h
-	rm -f socketcalls/*.[Ssco] socketcalls/*.obj
-	mkdir -p socketcalls
-	$(PERL) socketcalls.pl SOCKETCALLS.def $(ARCH) socketcalls
-	touch $@
-
-%/static.obj: %.dir
-	$(MAKE) objects-$(basename $(notdir $@)) DIR=$*/
-
-STATIC = $(addsuffix .o,$(basename $(wildcard $(DIR)*.[cS])))
-
-objects-static: $(STATIC)
-	touch $(DIR)static.obj
-
-clean: archclean
-	find . -type f -a \( -name \*.[isoa] -o -name \*.l[iso] \) -print0 | xargs -0rt rm -f
-	rm -f *.a *.so *.hash *.syms *.stripped
-	rm -f $(TESTS) tests/*.stripped
-	rm -f syscalls/*.[Ssco] syscalls/*.obj syscalls.dir
-	rm -f socketcalls/*.[Ssco] socketcalls/*.obj socketcalls.dir
-	rm -f sha1hash errlist.c
-
-spotless: clean
-	rm -f ../include/klibc/havesyscall.h syscalls.nrs
-	find . \( -name \*~ -o -name '.*.d' \) -not -type d -print0 | \
-		xargs -0rt rm -f
-
-bitsize:
-	@echo $(BITSIZE)
-
-install: all
-	$(INSTALL_DATA) $(LIB) $(SOLIB) $(CRT0) $(INTERP_O) \
-		$(INSTALLROOT)$(INSTALLDIR)/$(CROSS)lib
-	$(INSTALL_EXEC) klibc-`cat $(SOLIB).hash`.so \
-		$(INSTALLROOT)$(INSTALLDIR)/$(CROSS)lib
-	$(INSTALL_EXEC) klibc-`cat $(SOLIB).hash`.so \
-		$(INSTALLROOT)/$(SHLIBDIR)
-
-ifneq ($(wildcard $(DIR).*.d),)
-include $(wildcard $(DIR).*.d)
-endif
diff --git a/klibc/arch/ppc/crt0.S b/klibc/arch/ppc/crt0.S
index 282f841..fd90c7d 100644
--- a/klibc/arch/ppc/crt0.S
+++ b/klibc/arch/ppc/crt0.S
@@ -11,10 +11,13 @@
 	addi	3,1,16
 	/*
 	 * the SVR4abippc.pdf specifies r7 as a pointer to 
-	 * a termination function pointer.
-	 * It is unused on Linux.
+	 * a termination function point
+	 * However, Section 8.4.1 of the LSB API docs say that
+	 * The value to be placed into register r7, the termination
+	 * function pointer, is not passed to the process.
+	 * So we stub it out, instead.
 	 */
-	mr	4,7
+	li	4,0
 	bl	__libc_init
 	
 	.size _start,.-_start
diff --git a/klibc/arch/ppc64/crt0.S b/klibc/arch/ppc64/crt0.S
index 872d2a0..3619181 100644
--- a/klibc/arch/ppc64/crt0.S
+++ b/klibc/arch/ppc64/crt0.S
@@ -25,7 +25,7 @@
 ._start:
 	stdu    %r1,-32(%r1)
 	addi    %r3,%r1,32
-	mr      %r4,%r7     /* fini */
+	li	%r4,0		/* fini (unused) */
 	b 	.__libc_init
 	nop
 
diff --git a/klibc/libc_init.c b/klibc/libc_init.c
index 081eb44..9383414 100644
--- a/klibc/libc_init.c
+++ b/klibc/libc_init.c
@@ -12,6 +12,13 @@
  *  void (*onexit)(void) -- Function to install into onexit
  */
 
+/*
+ * Several Linux ABIs don't pass the onexit pointer, and the ones that
+ * do never use it.  Therefore, unless USE_ONEXIT is defined, we just
+ * ignore the onexit pointer.
+ */
+/* #define USE_ONEXIT */
+
 #include <stddef.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -32,8 +39,6 @@
   uintptr_t v;
 };
 
-static struct atexit at_exit;
-
 __noreturn __libc_init(uintptr_t *elfdata, void (*onexit)(void))
 {
   int argc;
@@ -48,13 +53,17 @@
 #endif
   unsigned int page_size = 0, page_shift = 0;
 
+#ifdef USE_ONEXIT
   if ( onexit ) {
+    static struct atexit at_exit;
+
     at_exit.fctn = (void(*)(int, void *))onexit;
     /* at_exit.next = NULL already */
     __atexit_list = &at_exit;
   }
-
-  (void)onexit;			/* For now, we ignore this... */
+#else
+  (void)onexit;			/* Ignore this... */
+#endif
 
   argc = (int)*elfdata++;
   argv = (char **)elfdata;
diff --git a/klibc/libgcc/__moddi3.c b/klibc/libgcc/__moddi3.c
index 3e61365..c41d4f4 100644
--- a/klibc/libgcc/__moddi3.c
+++ b/klibc/libgcc/__moddi3.c
@@ -21,7 +21,7 @@
     minus ^= 1;
   }
   
-  (void) __udivmoddi4(num, den, &v);
+  (void) __udivmoddi4(num, den, (uint64_t *)&v);
   if ( minus )
     v = -v;
 
diff --git a/klibc/sigpending.c b/klibc/sigpending.c
index decfe32..0d8044b 100644
--- a/klibc/sigpending.c
+++ b/klibc/sigpending.c
@@ -7,7 +7,7 @@
 
 #ifndef __NR_sigpending
 
-__extern __rt_sigpending(sigset_t *, size_t);
+__extern int __rt_sigpending(sigset_t *, size_t);
 
 int sigpending(sigset_t *set)
 {
diff --git a/klibc/sigprocmask.c b/klibc/sigprocmask.c
index 372e0fd..35b37eb 100644
--- a/klibc/sigprocmask.c
+++ b/klibc/sigprocmask.c
@@ -7,7 +7,7 @@
 
 #ifndef __NR_sigprocmask
 
-__extern __rt_sigprocmask(int, const sigset_t *, sigset_t *, size_t);
+__extern int __rt_sigprocmask(int, const sigset_t *, sigset_t *, size_t);
 
 int sigprocmask(int how, const sigset_t *set, sigset_t *oset)
 {
diff --git a/klibc/socketcalls/Kbuild b/klibc/socketcalls/Kbuild
index e2c8bf7..9f58b16 100644
--- a/klibc/socketcalls/Kbuild
+++ b/klibc/socketcalls/Kbuild
@@ -4,35 +4,34 @@
 
 # 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
 
-klibc-dir := $(srctree)/usr/klibc
-
 #####
 # Generate socket calls stubs
 # Based on input from SOCKETCALLS.def generate socket call stubs
 targets     := socketcalls.o
 targets     += socketcalls.mk
 targets     += $(socketcall-objs)
-clean-files += *.o
+clean-files += *.S *.c *.o
 
 # Create reloctable composite object file
 $(obj)/socketcalls.o: $(call objectify,$(socketcall-objs)) FORCE
-	$(call if_changed,userld)
+	$(call if_changed,klibcld)
 	
 quiet_cmd_socketcalls = GEN     $@
-      cmd_socketcalls = $(PERL) $(klibc-dir)/socketcalls.pl        \
-			        $(klibc-dir)/SOCKETCALLS.def       \
+      cmd_socketcalls = $(PERL) $(KLIBCSRC)/socketcalls.pl          \
+                                $(KLIBCSRC)/SOCKETCALLS.def         \
                                 $(ARCH) $(obj) > $@ || rm -f $@
 
 # Generate socketcall stubs
-$(obj)/socketcalls.mk: $(klibc-dir)/socketcalls.pl                 \
-                       $(klibc-dir)/SOCKETCALLS.def                \
-		       $(call objectify, $(socketcall-objs:.o=.S)) \
-                       $(klibc-dir)/socketcommon.h 
+$(obj)/socketcalls.mk: $(KLIBCSRC)/socketcalls.pl                   \
+                       $(KLIBCSRC)/SOCKETCALLS.def                  \
+                       $(KLIBCSRC)/socketcommon.h 
 	$(call cmd,socketcalls)
 
 
diff --git a/klibc/strcasecmp.c b/klibc/strcasecmp.c
index 12aef40..fdc5795 100644
--- a/klibc/strcasecmp.c
+++ b/klibc/strcasecmp.c
@@ -7,7 +7,8 @@
 
 int strcasecmp(const char *s1, const char *s2)
 {
-  const unsigned char *c1 = s1, *c2 = s2;
+  const unsigned char *c1 = (const unsigned char *)s1;
+  const unsigned char *c2 = (const unsigned char *)s2;
   unsigned char ch;
   int d = 0;
 
diff --git a/klibc/strcmp.c b/klibc/strcmp.c
index f44774f..63a391b 100644
--- a/klibc/strcmp.c
+++ b/klibc/strcmp.c
@@ -6,7 +6,8 @@
 
 int strcmp(const char *s1, const char *s2)
 {
-  const unsigned char *c1 = s1, *c2 = s2;
+  const unsigned char *c1 = (const unsigned char *)s1;
+  const unsigned char *c2 = (const unsigned char *)s2;
   unsigned char ch;
   int d = 0;
 
diff --git a/klibc/strncasecmp.c b/klibc/strncasecmp.c
index 3309d1a..c400124 100644
--- a/klibc/strncasecmp.c
+++ b/klibc/strncasecmp.c
@@ -7,7 +7,8 @@
 
 int strncasecmp(const char *s1, const char *s2, size_t n)
 {
-  const unsigned char *c1 = s1, *c2 = s2;
+  const unsigned char *c1 = (const unsigned char *)s1;
+  const unsigned char *c2 = (const unsigned char *)s2;
   unsigned char ch;
   int d = 0;
 
diff --git a/klibc/strncmp.c b/klibc/strncmp.c
index 4dbde13..61f1fba 100644
--- a/klibc/strncmp.c
+++ b/klibc/strncmp.c
@@ -6,7 +6,8 @@
 
 int strncmp(const char *s1, const char *s2, size_t n)
 {
-  const unsigned char *c1 = s1, *c2 = s2;
+  const unsigned char *c1 = (const unsigned char *)s1;
+  const unsigned char *c2 = (const unsigned char *)s2;
   unsigned char ch;
   int d = 0;
 
diff --git a/klibc/syscalls/Kbuild b/klibc/syscalls/Kbuild
index be08f17..6758127 100644
--- a/klibc/syscalls/Kbuild
+++ b/klibc/syscalls/Kbuild
@@ -4,13 +4,13 @@
 
 # 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
 
-klibc-dir := $(srctree)/usr/klibc
-
 
 #####
 # Generate syscalls stubs
@@ -22,42 +22,42 @@
 targets += $(syscall-objs)
 
 # Side effect of running syscalls.pl
-clean-files += $(objtree)/usr/include/klibc/havesyscall.h
+clean-files += $(objtree)/$(KLIBCINC)/klibc/havesyscall.h
 # All the syscall stubs
 clean-files += *.o *.S *.c
 
 # Create reloctable composite object file
 $(obj)/syscalls.o: $(call objectify,$(syscall-objs)) FORCE
-	$(call if_changed,userld)
+	$(call if_changed,klibcld)
 
 # Generate assembler file (.i)
 # We pass -ansi to keep cpp from define e.g. "i386" as well as "__i386__"
 quiet_cmd_syscall.i = GEN     $@
-      cmd_syscall.i = $(USERCC) $(usercflags) -D__ASSEMBLY__ \
+      cmd_syscall.i = $(KLIBCCC) $(klibccflags) -D__ASSEMBLY__ \
                                 -ansi -x assembler-with-cpp -E -o $@ $<
-$(obj)/SYSCALLS.i: $(klibc-dir)/SYSCALLS.def FORCE
+$(obj)/SYSCALLS.i: $(KLIBCSRC)/SYSCALLS.def FORCE
 	$(call if_changed_dep,syscall.i)
 
 # Get syscalls numbers
 quiet_cmd_syscall.nrs = GEN     $@
-      cmd_syscall.nrs = $(USERCC) $(usercflags) -Wp,-dM -x c -E -o $@ $<
-$(obj)/syscalls.nrs: $(srctree)/usr/include/sys/syscall.h FORCE
+      cmd_syscall.nrs = $(KLIBCCC) $(klibccflags) -Wp,-dM -x c -E -o $@ $<
+$(obj)/syscalls.nrs: $(KLIBCINC)/sys/syscall.h FORCE
 	$(call if_changed_dep,syscall.nrs)
 
-# Generate usr/include/klibc/havesyscall.h + makefile fragment
+# Generate $(KLIBINC)/klibc/havesyscall.h + makefile fragment
 # Using sysstub.pl in arch dir generate all .S files
 quiet_cmd_syscalls = GEN     $@
-      cmd_syscalls = mkdir -p $(objtree)/usr/include/klibc/;                 \
-                     $(PERL) $(klibc-dir)/syscalls.pl $(obj)/SYSCALLS.i      \
-                             $(klibc-dir)/arch/$(ARCH)/sysstub.ph            \
-                             $(ARCH) $(BITSIZE) $(obj)/syscalls.nrs          \
-			     $(obj)                                          \
-                             $(objtree)/usr/include/klibc/havesyscall.h > $@ \
+      cmd_syscalls = mkdir -p $(KLIBCINC)/klibc/;                           \
+                     $(PERL) $(KLIBCSRC)/syscalls.pl $(obj)/SYSCALLS.i      \
+                             $(KLIBCSRC)/arch/$(ARCH)/sysstub.ph            \
+                             $(ARCH) $(KLIBCBITSIZE) $(obj)/syscalls.nrs    \
+                             $(obj)                                         \
+                             $(KLIBCINC)/klibc/havesyscall.h > $@           \
                              || rm -f $@
 
-$(obj)/syscalls.mk: $(klibc-dir)/syscalls.pl $(obj)/SYSCALLS.i \
-                    $(klibc-dir)/arch/$(ARCH)/sysstub.ph       \
-		    $(call objectify, $(syscall-objs:.o=.S))  \
-                    $(klibc-dir)/syscommon.h $(obj)/syscalls.nrs
+$(obj)/syscalls.mk: $(KLIBCSRC)/syscalls.pl $(obj)/SYSCALLS.i \
+                    $(KLIBCSRC)/arch/$(ARCH)/sysstub.ph       \
+                    $(call objectify, $(syscall-objs:.o=.S))  \
+                    $(KLIBCSRC)/syscommon.h $(obj)/syscalls.nrs
 	$(call cmd,syscalls)
 
diff --git a/klibc/tests/Kbuild b/klibc/tests/Kbuild
new file mode 100644
index 0000000..2525dbc
--- /dev/null
+++ b/klibc/tests/Kbuild
@@ -0,0 +1,43 @@
+#
+# Kbuild file for all test files
+#
+
+test-files := $(wildcard $(srctree)/$(src)/*.c)
+test-files := $(notdir $(test-files))
+
+# This particular file uses a bunch of formats gcc don't know of, in order
+# to test the full range of our vsnprintf() function.  This outputs a bunch
+# of useless warnings unless we tell it not to.
+KLIBCCFLAGS_testvsnp.o := -Wno-format
+
+static-y := $(test-files:.c=)
+shared-y := $(addsuffix .shared, $(static-y))
+
+environ.shared-y       := environ.o
+fcntl.shared-y         := fcntl.o
+getopttest.shared-y    := getopttest.o
+getpagesize.shared-y   := getpagesize.o
+hello.shared-y         := hello.o
+idtest.shared-y        := idtest.o
+malloctest.shared-y    := malloctest.o
+malloctest2.shared-y   := malloctest2.o
+memstrtest.shared-y    := memstrtest.o
+microhello.shared-y    := microhello.o
+minihello.shared-y     := minihello.o
+mmaptest.shared-y      := mmaptest.o
+nfs_no_rpc.shared-y    := nfs_no_rpc.o
+opentest.shared-y      := opentest.o
+rtsig.shared-y         := rtsig.o
+setenvtest.shared-y    := setenvtest.o
+setjmptest.shared-y    := setjmptest.o
+sigint.shared-y        := sigint.o
+stat.shared-y          := stat.o
+statfs.shared-y        := statfs.o
+strlcpycat.shared-y    := strlcpycat.o
+strtoimax.shared-y     := strtoimax.o
+strtotime.shared-y     := strtotime.o
+testrand48.shared-y    := testrand48.o
+testvsnp.shared-y      := testvsnp.o
+
+# Cleaning
+clean-files := $(static-y) $(shared-y) $(test-files:.c=.o)
diff --git a/nfsmount/MCONFIG b/nfsmount/MCONFIG
deleted file mode 100644
index 472f092..0000000
--- a/nfsmount/MCONFIG
+++ /dev/null
@@ -1,8 +0,0 @@
-# -*- makefile -*-
-
-SRCROOT = ..
-
-include $(SRCROOT)/MCONFIG
-include $(SRCROOT)/MRULES
-
-CFLAGS = -Wp,-MD,$(dir $@).$(notdir $@).d $(OPTFLAGS) $(REQFLAGS) -Wstrict-prototypes -Wall -I.
diff --git a/nfsmount/Makefile b/nfsmount/Makefile
deleted file mode 100644
index ce6159f..0000000
--- a/nfsmount/Makefile
+++ /dev/null
@@ -1,44 +0,0 @@
-include MCONFIG
-
-COMMON_OBJS = main.o mount.o portmap.o dummypmap.o sunrpc.o
-PROGS       = nfsmount
-STATICPROGS := $(patsubst %,static/%,$(PROGS))
-SHAREDPROGS := $(patsubst %,shared/%,$(PROGS))
-LIB	    = libnfsmount.a
-LIBS	    = $(KLIBC) $(LIBGCC)
-
-OBJS := $(COMMON_OBJS) $(BOOTP_OBJS) $(DHCP_OBJS)
-
-all:	$(STATICPROGS) $(SHAREDPROGS) $(LIB)
-
-static/nfsmount: $(OBJS) $(CRT0) $(LIBS)
-	mkdir -p static static.g
-	$(LD) $(LDFLAGS) -o $@ $(CRT0) $(OBJS) $(LIBS)
-	cp -f $@ static.g
-	$(STRIPCMD) $@
-
-shared/nfsmount: $(OBJS) $(CRTSHARED) $(LIBSHARED) $(LIBGCC)
-	mkdir -p shared shared.g
-	$(LD) $(LDFLAGS) -o $@ $(EMAIN) $(CRTSHARED) $(OBJS) \
-		-R $(LIBSHARED) $(LIBGCC)
-	cp -f $@ shared.g
-	$(STRIPCMD) $@
-
-dummypmap: dummypmap_test.o
-	$(LD) $(LDFLAGS) -o $@ $(CRT0) $^ $(LIBS)
-
-$(LIB): $(OBJS)
-	$(AR) cru $(LIB) $(OBJS)
-
-clean:
-	$(RM) *.o $(LIB) core
-	$(RM) -r static static.g shared shared.g
-
-spotless: clean
-	$(RM) *~ .*.d *~
-
-install: all
-	$(INSTALL_EXEC) shared/* $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)bin	
-ifneq ($(wildcard .*.d),)
-include $(wildcard .*.d)
-endif
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
new file mode 100644
index 0000000..db3c708
--- /dev/null
+++ b/scripts/Kbuild.include
@@ -0,0 +1,99 @@
+####
+# kbuild: Generic definitions
+
+# Convinient variables
+comma   := ,
+empty   :=
+space   := $(empty) $(empty)
+
+###
+# The temporary file to save gcc -MD generated dependencies must not
+# contain a comma
+depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
+
+###
+# filechk is used to check if the content of a generated file is updated.
+# Sample usage:
+# define filechk_sample
+#	echo $KERNELRELEASE
+# endef
+# version.h : Makefile
+#	$(call filechk,sample)
+# The rule defined shall write to stdout the content of the new file.
+# The existing file will be compared with the new one.
+# - If no file exist it is created
+# - If the content differ the new file is used
+# - If they are equal no change, and no timestamp update
+# - stdin is piped in from the first prerequisite ($<) so one has
+#   to specify a valid file as first prerequisite (often the kbuild file)
+define filechk
+	$(Q)set -e;				\
+	echo '  CHK     $@';			\
+	mkdir -p $(dir $@);			\
+	$(filechk_$(1)) < $< > $@.tmp;		\
+	if [ -r $@ ] && cmp -s $@ $@.tmp; then	\
+		rm -f $@.tmp;			\
+	else					\
+		echo '  UPD     $@';		\
+		mv -f $@.tmp $@;		\
+	fi
+endef
+
+###
+# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
+# Usage:
+# $(Q)$(MAKE) $(build)=dir
+build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
+
+# If quiet is set, only print short version of command
+cmd = @$(if $($(quiet)cmd_$(1)),\
+      echo '  $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1))
+
+# Add $(obj)/ for paths that is not absolute
+objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
+
+###
+# if_changed      - execute command if any prerequisite is newer than 
+#                   target, or command line has changed
+# if_changed_dep  - as if_changed, but uses fixdep to reveal dependencies
+#                   including used config symbols
+# if_changed_rule - as if_changed but execute rule instead
+# See Documentation/kbuild/makefiles.txt for more info
+
+ifneq ($(KBUILD_NOCMDDEP),1)
+# Check if both arguments has same arguments. Result in empty string if equal
+# User may override this check using make KBUILD_NOCMDDEP=1
+arg-check = $(strip $(filter-out $(1), $(2)) $(filter-out $(2), $(1)) )
+endif
+
+# echo command. Short version is $(quiet) equals quiet, otherwise full command
+echo-cmd = $(if $($(quiet)cmd_$(1)), \
+	echo '  $(subst ','\'',$($(quiet)cmd_$(1)))';)
+
+# function to only execute the passed command if necessary
+# >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file
+# note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars
+# 
+if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
+	@set -e; \
+	$(echo-cmd) \
+	$(cmd_$(1)); \
+	echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).cmd)
+
+# execute the command and also postprocess generated .d dependencies
+# file
+if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\
+	$(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),                  \
+	@set -e; \
+	$(echo-cmd) \
+	$(cmd_$(1)); \
+	scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
+	rm -f $(depfile); \
+	mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
+
+# Usage: $(call if_changed_rule,foo)
+# will check if $(cmd_foo) changed, or any of the prequisites changed,
+# and if so will execute $(rule_foo)
+if_changed_rule = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\
+			@set -e; \
+			$(rule_$(1)))
diff --git a/scripts/Kbuild.install b/scripts/Kbuild.install
new file mode 100644
index 0000000..cbde14b
--- /dev/null
+++ b/scripts/Kbuild.install
@@ -0,0 +1,122 @@
+#
+# Install klibc
+#
+# File is logically seperated in two pieces.
+# First piece is used when during a recursive descend of the klibc tree
+# and second piece is used to do the final steps in the install
+# If KLIBC_INSTALL is defined it tells us we are descending and we
+# use first piece of the file.
+
+# This indicates the location of the final version of the shared library.
+# THIS MUST BE AN ABSOLUTE PATH WITH NO FINAL SLASH.
+# Leave this empty to make it the root.
+#
+SHLIBDIR = /lib
+
+# First rule
+.PHONY: __install install-rule
+__install:
+
+# Install commands
+install-data := install -m 644
+install-lib  := install -m 755
+install-bin  := install -m 755
+
+# Install command
+quiet_cmd_install = INSTALL $(install-y)
+      cmd_install = $(install-bin) $(install-y) \
+                                   $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)bin
+
+ifeq ($(KLIBC_INSTALL),1)
+# First part - we are descending..
+
+# Reset variables (to get right type of assingment)
+subdir- :=
+
+# Include Kbuild file
+include $(srctree)/scripts/Kbuild.include
+include $(srctree)/$(obj)/Kbuild
+
+# Directories to visit
+# First find directories specified in lib-?, static-y and shared-y
+find-dir = $(patsubst %/,%,$(filter %/, $(1)))
+
+__subdir := $(call find-dir, $(lib-))
+__subdir += $(call find-dir, $(lib-y))
+
+__subdir += $(foreach e, $(static-y), $(call find-dir, $(e)))
+__subdir += $(foreach e, $(shared-y), $(call find-dir, $(e)))
+
+# Use subdir- in Kbuild file to tell kbuild to visit a specific dir
+subdir-  += $(__subdir)
+
+# Remove duplicates and add prefix
+subdir- := $(addprefix $(obj)/,$(sort $(subdir-)))
+
+# Files to install
+install-y := $(strip $(addprefix $(obj)/, $(install-y)))
+
+__install: $(subdir-) install-rule
+ifneq ($(install-y),)
+	$(call cmd,install)
+else
+	@:
+endif
+
+# Descending
+.PHONY: $(subdir-)
+$(subdir-):
+	$(Q)$(MAKE) KLIBC_INSTALL=1 \
+	            -f $(srctree)/scripts/Kbuild.install obj=$@
+
+# If quiet is set, only print short version of command
+cmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
+
+
+else
+##########################################################################
+# This is the first time this file is invoked, so kick off the
+# install process.
+# First we descend all sub-directories to let them do their install.
+# Second we do the final install steps.
+
+# Do actual install as a three steps approach
+# 1) Create directories, install headers and man pages
+# 2) Tell that we now install binaries
+# 3) Install binaries by descending
+.PHONY: header footer descend
+header:
+	$(Q)echo "  INSTALL headers + man pages to $(INSTALLROOT)$(INSTALLDIR)"
+	$(Q)mkdir -p $(INSTALLROOT)$(bindir)
+	$(Q)mkdir -p $(INSTALLROOT)$(mandir)/man1
+	$(Q)mkdir -p $(INSTALLROOT)$(SHLIBDIR)
+	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)
+	$(Q)-rm -rf $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
+	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
+	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)lib
+	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)bin
+	$(Q)set -e ; for d in linux scsi asm-$(ARCH) asm-generic $(ASMARCH); do \
+	  mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)include/$$d ; \
+	  for r in $(KLIBCKERNELSRC)/include $(KLIBCKERNELOBJ)/include \
+	           $(KLIBCKERNELOBJ)/include2 ; do \
+	    [ ! -d $$r/$$d ] || \
+	      cp -rfL $$r/$$d/. \
+	          $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/$$d/. ; \
+	  done ; \
+	done
+	$(Q)cd $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include && ln -sf asm-$(ARCH) asm
+	$(Q)cp -rf include/. $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/.
+	$(Q)$(install-data) $(srctree)/klcc/klcc.1 $(INSTALLROOT)$(mandir)/man1/$(KCROSS)klcc.1
+	$(Q)$(install-bin) $(objtree)/klcc/$(KCROSS)klcc $(INSTALLROOT)$(bindir)
+
+footer: header
+	$(Q)echo "  INSTALL binaries to $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)bin"
+
+descend: footer
+	$(Q)$(MAKE) KLIBC_INSTALL=1 \
+	            -f $(srctree)/scripts/Kbuild.install obj=$(obj)
+
+__install: descend
+	@:
+endif
+
diff --git a/scripts/Kbuild.klibc b/scripts/Kbuild.klibc
new file mode 100644
index 0000000..acf326d
--- /dev/null
+++ b/scripts/Kbuild.klibc
@@ -0,0 +1,320 @@
+# ==========================================================================
+# Support for building klibc and related programs
+# ==========================================================================
+#
+# To create a kbuild file for a userspace program do the following:
+#
+# Kbuild:
+# 
+# static-y := cat
+# # This will compile a file named cat.c -> the executable 'cat'
+# # The executable will be linked statically
+#
+# shared-y := cats
+# # This will compile a file named cats.c -> the executable 'cats'
+# # The executable will be linked shared
+#
+# If the userspace program consist of more files do the following:
+# Kbuild:
+#
+# static-y   := ipconfig
+# ipconfig-y := main.o netdev.c
+# So ipconfig will be linked statically using the two .o files
+# specified with ipconfig-y.
+#
+# To set directory wide CFLAGS use:
+# EXTRA_KLIBCCFLAGS := -DDEBUG
+# To set directory wide AFLAGS use:
+# EXTRA_KLIBCAFLAGS := -DDEBUG
+#
+# To set target specific CFLAGS (for .c files) use
+# KLIBCCFLAGS-main.o := -DDEBUG=3
+# To set target specific AFLAGS (for .s files) use
+# KLIBCAFLAGS-main.o := -DDEBUG=3
+
+src := $(obj)
+# Preset target and make sure it is a ':=' variable
+targets :=
+
+.phony: __build
+__build:
+
+# Generic Kbuild routines
+include $(srctree)/scripts/Kbuild.include
+
+# Defines used when compiling early userspace (klibc programs)
+# ---------------------------------------------------------------------------
+
+KLIBCREQFLAGS     :=
+KLIBCARCHREQFLAGS :=
+KLIBCOPTFLAGS     :=
+KLIBCWARNFLAGS    := -W -Wall -Wno-sign-compare
+KLIBCSHAREDFLAGS  := 
+KLIBCBITSIZE      :=
+KLIBCLDFLAGS      :=
+
+# Arch specific definitions for klibc
+include $(KLIBCSRC)/arch/$(ARCH)/MCONFIG
+
+# FIXME - backwards compatibility. Remove when all MCONFIGs are corrected
+KLIBCREQFLAGS     += $(REQFLAGS)
+KLIBCARCHREQFLAGS += $(ARCHREQFLAGS)
+KLIBCOPTFLAGS     += $(OPTFLAGS)
+KLIBCWARNFLAGS    += $(WARNFLAGS) -W -Wall -Wno-sign-compare
+KLIBCSHAREDFLAGS  += $(SHAREDFLAGS)
+KLIBCBITSIZE      := $(strip $(KLIBCBITSIZE) $(BITSIZE))
+KLIBCLDFLAGS      += $(LDFLAGS)
+KLIBCROSS        := $(CROSS_COMPILE)
+
+# binutils
+KLIBCLD          := $(KLIBCROSS)ld
+KLIBCCC          := $(KLIBCROSS)gcc
+KLIBCAR          := $(KLIBCROSS)ar
+KLIBCRANLIB      := $(KLIBCROSS)ranlib
+KLIBCSTRIP       := $(KLIBCROSS)strip
+KLIBCNM          := $(KLIBCROSS)nm
+
+
+# klibc include paths
+KLIBCCPPFLAGS    := -I$(KLIBCINC)/arch/$(ARCH)         \
+                    -I$(KLIBCINC)/bits$(KLIBCBITSIZE)  \
+                    -I$(KLIBCINC)
+# kernel include paths
+KLIBCCPPFLAGS    += -I$(KLIBCKERNELSRC)include                              \
+                     $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include)
+# klibc definitions
+KLIBCCPPFLAGS    += -D__KLIBC__=1 -D__KLIBC_MINOR__=0                       \
+		    -DBITSIZE=$(KLIBCBITSIZE)
+KLIBCCFLAGS      := $(KLIBCCPPFLAGS) $(KLIBCREQFLAGS) $(KLIBCARCHREQFLAGS)  \
+                    $(KLIBCOPTFLAGS) $(KLIBCWARNFLAGS)
+KLIBCAFLAGS      := -D__ASSEMBLY__ $(KLIBCCFLAGS)
+KLIBCSTRIPFLAGS  := --strip-all -R .comment -R .note
+
+KLIBCLIBGCC      := $(shell $(KLIBCCC) --print-libgcc)
+KLIBCCRT0        := $(KLIBCOBJ)/arch/$(ARCH)/crt0.o
+KLIBCLIBC        := $(KLIBCOBJ)/libc.a
+KLIBCCRTSHARED   := $(KLIBCOBJ)/interp.o
+KLIBCLIBCSHARED  := $(KLIBCOBJ)/libc.so
+# How to tell the linker main() is the entrypoint
+KLIBCEMAIN	?= -e main
+
+#
+# This indicates the location of the final version of the shared library.
+# THIS MUST BE AN ABSOLUTE PATH WITH NO FINAL SLASH.
+# Leave this empty to make it the root.
+#
+SHLIBDIR = /lib
+
+export KLIBCLD KLIBCCC KLIBCAR KLIBCSTRIP KLIBCNM
+export KLIBCCFLAGS KLIBCAFLAGS KLIBCLIBGCC KLIBCSHAREDFLAGS KLIBCSTRIPFLAGS
+export KLIBCCRT0 KLIBCLIBC SHLIBDIR
+
+# kernel configuration
+include .config
+
+# Add $(obj)/ for paths that is not absolute
+objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
+
+# Kbuild file in the directory that is being build
+include $(obj)/Kbuild
+
+#####
+# static-y + shared-y handling
+klibc-progs := $(static-y) $(shared-y)
+# klibc-progs based on a single .o file (with same name + .o)
+klibc-objs := $(foreach p, $(klibc-progs), $(if $($(p)-y),,$(p)))
+klibc-objs := $(addsuffix .o, $(klibc-objs))
+# klibc-progs which is based on several .o files
+klibc-multi := $(foreach p, $(klibc-progs), $(if $($(p)-y),$(p)))
+# objects used for klibc-progs with more then one .o file
+klibc-objs += $(foreach p, $(klibc-multi), $($(p)-y))
+# objects build in this dir
+klibc-real-objs := $(patsubst %/,,$(klibc-objs))
+# Directories we need to visit before klibc-objs are up-to-date
+klibc-dirs :=  $(patsubst %/,%,$(filter %/, $(klibc-objs))) 
+# replace all dir/ with dir/lib.a
+klibc-objs := $(patsubst %/, %/lib.a, $(klibc-objs))
+
+targets += $(static-y) $(shared-y)
+
+# $(output-dirs) are a list of directories that contain object files
+output-dirs := $(dir $(klibc-dirs))
+output-dirs += $(foreach f, $(hostprogs-y) $(targets), \
+               $(if $(dir $(f)), $(dir $(f))))
+output-dirs := $(strip $(sort $(filter-out ./,$(output-dirs))))
+
+# prefix so we get full dir
+static-y        := $(addprefix $(obj)/,$(static-y))
+shared-y        := $(addprefix $(obj)/,$(shared-y))
+klibc-objs      := $(addprefix $(obj)/,$(klibc-objs))
+klibc-real-objs := $(addprefix $(obj)/,$(klibc-real-objs))
+output-dirs     := $(addprefix $(obj)/,$(output-dirs))
+klibc-dirs      := $(addprefix $(obj)/,$(klibc-dirs))
+subdir-y        := $(addprefix $(obj)/,$(subdir-y))
+lib-y           := $(addprefix $(obj)/,$(lib-y))
+always          := $(addprefix $(obj)/,$(always))
+targets         := $(addprefix $(obj)/,$(targets))
+
+
+_klibccflags    = $(KLIBCCFLAGS) $(EXTRA_KLIBCCFLAGS) $(KLIBCCFLAGS_$(*F).o)
+_klibcaflags    = $(KLIBCAFLAGS) $(EXTRA_KLIBCAFLAGS) $(KLIBCAFLAGS_$(*F).o)
+
+klibccflags     = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(_klibccflags)
+klibcaflags     = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(_klibcaflags)
+
+# Create output directory if not already present
+_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
+
+# Create directories for object files if directory does not exist
+# Needed when lib-y := dir/file.o syntax is used
+_dummy := $(foreach d,$(output-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
+
+# Do we have to make a lib.a in this dir?
+ifneq ($(strip $(lib-y) $(lib-n) $(lib-)),)
+lib-target := $(obj)/lib.a
+endif
+
+__build: $(subdir-y) $(lib-target) $(always)
+	@:
+
+# Compile C sources (.c)
+# ---------------------------------------------------------------------------
+
+quiet_cmd_cc_s_c = KLIBCCC $@
+      cmd_cc_s_c = $(KLIBCCC) $(klibccflags) -S -o $@ $< 
+
+%.s: %.c FORCE
+	$(call if_changed_dep,cc_s_c)
+
+quiet_cmd_cc_o_c = KLIBCCC $@
+      cmd_cc_o_c = $(KLIBCCC) $(klibccflags) -c -o $@ $<
+
+%.o: %.c FORCE
+	$(call if_changed_dep,cc_o_c)
+
+# Compile assembler sources (.S)
+# ---------------------------------------------------------------------------
+
+quiet_cmd_as_o_S = KLIBCAS $@
+      cmd_as_o_S = $(KLIBCCC) $(klibcaflags) -c -o $@ $<
+
+%.o: %.S FORCE
+	$(call if_changed_dep,as_o_S)
+
+targets += $(real-objs-y)
+
+#
+# Rule to compile a set of .o files into one .o file
+#
+ifdef lib-target
+quiet_cmd_link_o_target = LD      $@
+# If the list of objects to link is empty, just create an empty lib.a
+cmd_link_o_target = $(if $(strip $(lib-y)),\
+                    rm -f $@; $(KLIBCAR) cru $@ $(filter $(lib-y), $^),\
+                    rm -f $@; $(KLIBCAR) crs $@)
+
+$(lib-target): $(lib-y) FORCE
+	$(call if_changed,link_o_target)
+targets += $(lib-target) $(lib-y)
+endif # lib-target
+
+
+ifdef klibc-progs
+# Compile klibcspace programs for the target
+# ===========================================================================
+
+__build : $(klibc-dirs) $(static-y) $(shared-y)
+
+# Descend if needed
+$(sort $(addsuffix /lib.a,$(klibc-dirs))): $(klibc-dirs) ;
+
+# Define dependencies for link of progs
+# For the simple program:
+#	file.o => file
+# A program with multiple objects
+#	filea.o, fileb.o => file
+# A program with .o files in another dir
+#	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) 
+
+quiet_cmd_ld-static = KLIBCLD $@
+      cmd_ld-static = $(KLIBCLD) $(KLIBCLDFLAGS) -o $@    \
+                       $(EXTRA_KLIBCLDFLAGS)              \
+                       $(KLIBCCRT0)                       \
+                       $(link-deps)                       \
+                       $(KLIBCLIBC) $(KLIBCLIBGCC)
+
+$(static-y): $(klibc-objs) $(lib-target) FORCE
+	$(call if_changed,ld-static)
+
+quiet_cmd_ld-shared = KLIBCLD $@
+      cmd_ld-shared = $(KLIBCLD) $(KLIBCLDFLAGS) -o $@    \
+                       $(EXTRA_KLIBCLDFLAGS)              \
+                       $(KLIBCEMAIN) $(KLIBCCRTSHARED)    \
+                       $(link-deps)                       \
+                       $(KLIBCLIBCSHARED) $(KLIBCLIBGCC)
+		       
+$(shared-y): $(klibc-objs) $(lib-target) FORCE
+	$(call if_changed,ld-shared)
+	
+targets += $(klibc-real-objs)
+endif
+
+# Compile programs on the host
+# ===========================================================================
+ifdef hostprogs-y
+include $(srctree)/scripts/Makefile.host
+endif
+
+# Descending
+# ---------------------------------------------------------------------------
+
+.PHONY: $(subdir-y) $(klibc-dirs)
+$(subdir-y) $(klibc-dirs):
+	$(Q)$(MAKE) $(klibc)=$@
+
+# Add FORCE to the prequisites of a target to force it to be always rebuilt.
+# ---------------------------------------------------------------------------
+
+.PHONY: FORCE
+
+FORCE:
+
+# Linking
+# Create a reloctable composite object file
+# ---------------------------------------------------------------------------
+quiet_cmd_klibcld = KLIBCLD $@
+      cmd_klibcld = $(KLIBCLD) -r $(KLIBCLDFLAGS) \
+                                $(EXTRA_KLIBCLDFLAGS) $(KLIBCLDFLAGS_$(@F)) \
+                                $(filter-out FORCE,$^) -o $@
+
+
+# Link target to a new name
+# ---------------------------------------------------------------------------
+quiet_cmd_ln = LN      $@
+      cmd_ln = rm -f $@ && ln $< $@
+
+# Strip target (remove all debugging info)
+quiet_cmd_strip = STRIP   $@
+      cmd_strip = $(KLIBCSTRIP) $(KLIBCSTRIPFLAGS) $< -o $@
+ 
+
+# Read all saved command lines and dependencies for the $(targets) we
+# may be building above, using $(if_changed{,_dep}). As an
+# optimization, we don't need to read them if the target does not
+# exist, we will rebuild anyway in that case.
+targets := $(wildcard $(sort $(targets)))
+cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
+
+ifneq ($(cmd_files),)
+  include $(cmd_files)
+endif
+
+# Shorthand for $(Q)$(MAKE) -f scripts/Kbuild.klibc obj
+# Usage:
+# $(Q)$(MAKE) $(klibc)=dir
+klibc := -rR -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Kbuild.klibc obj
+
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
new file mode 100644
index 0000000..8974ea5
--- /dev/null
+++ b/scripts/Makefile.clean
@@ -0,0 +1,96 @@
+# ==========================================================================
+# Cleaning up
+# ==========================================================================
+
+src := $(obj)
+
+.PHONY: __clean
+__clean:
+
+# Shorthand for $(Q)$(MAKE) scripts/Makefile.clean obj=dir
+# Usage:
+# $(Q)$(MAKE) $(clean)=dir
+clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
+
+# The filename Kbuild has precedence over Makefile
+kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
+include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile)
+
+# Figure out what we need to build from the various variables
+# ==========================================================================
+
+__subdir-y	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
+subdir-y	+= $(__subdir-y)
+__subdir-m	:= $(patsubst %/,%,$(filter %/, $(obj-m)))
+subdir-m	+= $(__subdir-m)
+__subdir-n	:= $(patsubst %/,%,$(filter %/, $(obj-n)))
+subdir-n	+= $(__subdir-n)
+__subdir-	:= $(patsubst %/,%,$(filter %/, $(obj-)))
+subdir-		+= $(__subdir-)
+
+# Subdirectories we need to descend into
+
+subdir-ym	:= $(sort $(subdir-y) $(subdir-m))
+subdir-ymn      := $(sort $(subdir-ym) $(subdir-n) $(subdir-))
+
+# Add subdir path
+
+subdir-ymn	:= $(addprefix $(obj)/,$(subdir-ymn))
+
+# build a list of files to remove, usually releative to the current
+# directory
+
+__clean-files	:= $(extra-y) $(EXTRA_TARGETS) $(always) \
+		   $(targets) $(clean-files)             \
+		   $(host-progs)                         \
+		   $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
+
+# as clean-files is given relative to the current directory, this adds
+# a $(obj) prefix, except for absolute paths
+
+__clean-files   := $(wildcard                                               \
+                   $(addprefix $(obj)/, $(filter-out /%, $(__clean-files))) \
+		   $(filter /%, $(__clean-files)))
+
+# as clean-dirs is given relative to the current directory, this adds
+# a $(obj) prefix, except for absolute paths
+
+__clean-dirs    := $(wildcard                                               \
+                   $(addprefix $(obj)/, $(filter-out /%, $(clean-dirs)))    \
+		   $(filter /%, $(clean-dirs)))
+
+# ==========================================================================
+
+quiet_cmd_clean    = CLEAN   $(obj)
+      cmd_clean    = rm -f $(__clean-files)
+quiet_cmd_cleandir = CLEAN   $(__clean-dirs)
+      cmd_cleandir = rm -rf $(__clean-dirs)
+
+
+__clean: $(subdir-ymn)
+ifneq ($(strip $(__clean-files)),)
+	+$(call cmd,clean)
+endif
+ifneq ($(strip $(__clean-dirs)),)
+	+$(call cmd,cleandir)
+endif
+ifneq ($(strip $(clean-rule)),)
+	+$(clean-rule)
+endif
+	@:
+
+
+# ===========================================================================
+# Generic stuff
+# ===========================================================================
+
+# Descending
+# ---------------------------------------------------------------------------
+
+.PHONY: $(subdir-ymn)
+$(subdir-ymn):
+	$(Q)$(MAKE) $(clean)=$@
+
+# If quiet is set, only print short version of command
+
+cmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
diff --git a/scripts/Makefile.host b/scripts/Makefile.host
new file mode 100644
index 0000000..2d51970
--- /dev/null
+++ b/scripts/Makefile.host
@@ -0,0 +1,156 @@
+# ==========================================================================
+# Building binaries on the host system
+# Binaries are used during the compilation of the kernel, for example
+# to preprocess a data file.
+#
+# Both C and C++ is supported, but preferred language is C for such utilities.
+#
+# Samle syntax (see Documentation/kbuild/makefile.txt for reference)
+# hostprogs-y := bin2hex
+# Will compile bin2hex.c and create an executable named bin2hex
+#
+# hostprogs-y    := lxdialog
+# lxdialog-objs := checklist.o lxdialog.o
+# Will compile lxdialog.c and checklist.c, and then link the executable
+# lxdialog, based on checklist.o and lxdialog.o
+#
+# hostprogs-y      := qconf
+# qconf-cxxobjs   := qconf.o
+# qconf-objs      := menu.o
+# Will compile qconf as a C++ program, and menu as a C program.
+# They are linked as C++ code to the executable qconf
+
+# hostprogs-y := conf
+# conf-objs  := conf.o libkconfig.so
+# libkconfig-objs := expr.o type.o
+# Will create a shared library named libkconfig.so that consist of
+# expr.o and type.o (they are both compiled as C code and the object file
+# are made as position independent code).
+# conf.c is compiled as a c program, and conf.o is linked together with
+# libkconfig.so as the executable conf.
+# Note: Shared libraries consisting of C++ files are not supported
+
+__hostprogs := $(sort $(hostprogs-y)$(hostprogs-m))
+
+# hostprogs-y := tools/build may have been specified. Retreive directory
+obj-dirs += $(foreach f,$(__hostprogs), $(if $(dir $(f)),$(dir $(f))))
+obj-dirs := $(strip $(sort $(filter-out ./,$(obj-dirs))))
+
+
+# C code
+# Executables compiled from a single .c file
+host-csingle	:= $(foreach m,$(__hostprogs),$(if $($(m)-objs),,$(m)))
+
+# C executables linked based on several .o files
+host-cmulti	:= $(foreach m,$(__hostprogs),\
+		   $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
+
+# Object (.o) files compiled from .c files
+host-cobjs	:= $(sort $(foreach m,$(__hostprogs),$($(m)-objs)))
+
+# C++ code
+# C++ executables compiled from at least on .cc file
+# and zero or more .c files
+host-cxxmulti	:= $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
+
+# C++ Object (.o) files compiled from .cc files
+host-cxxobjs	:= $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
+
+# Shared libaries (only .c supported)
+# Shared libraries (.so) - all .so files referenced in "xxx-objs"
+host-cshlib	:= $(sort $(filter %.so, $(host-cobjs)))
+# Remove .so files from "xxx-objs"
+host-cobjs	:= $(filter-out %.so,$(host-cobjs))
+
+#Object (.o) files used by the shared libaries
+host-cshobjs	:= $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
+
+__hostprogs     := $(addprefix $(obj)/,$(__hostprogs))
+host-csingle	:= $(addprefix $(obj)/,$(host-csingle))
+host-cmulti	:= $(addprefix $(obj)/,$(host-cmulti))
+host-cobjs	:= $(addprefix $(obj)/,$(host-cobjs))
+host-cxxmulti	:= $(addprefix $(obj)/,$(host-cxxmulti))
+host-cxxobjs	:= $(addprefix $(obj)/,$(host-cxxobjs))
+host-cshlib	:= $(addprefix $(obj)/,$(host-cshlib))
+host-cshobjs	:= $(addprefix $(obj)/,$(host-cshobjs))
+obj-dirs        := $(addprefix $(obj)/,$(obj-dirs))
+
+#####
+# Handle options to gcc. Support building with separate output directory
+
+_hostc_flags   = $(HOSTCFLAGS)   $(HOST_EXTRACFLAGS)   $(HOSTCFLAGS_$(*F).o)
+_hostcxx_flags = $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) $(HOSTCXXFLAGS_$(*F).o)
+
+ifeq ($(KBUILD_SRC),)
+__hostc_flags	= $(_hostc_flags)
+__hostcxx_flags	= $(_hostcxx_flags)
+else
+__hostc_flags	= -I$(obj) $(call flags,_hostc_flags)
+__hostcxx_flags	= -I$(obj) $(call flags,_hostcxx_flags)
+endif
+
+hostc_flags    = -Wp,-MD,$(depfile) $(__hostc_flags)
+hostcxx_flags  = -Wp,-MD,$(depfile) $(__hostcxx_flags)
+
+#####
+# Compile programs on the host
+
+# Create executable from a single .c file
+# host-csingle -> Executable
+quiet_cmd_host-csingle 	= HOSTCC  $@
+      cmd_host-csingle	= $(HOSTCC) $(hostc_flags) -o $@ $< \
+	  	$(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
+$(host-csingle): %: %.c FORCE
+	$(call if_changed_dep,host-csingle)
+
+# Link an executable based on list of .o files, all plain c
+# host-cmulti -> executable
+quiet_cmd_host-cmulti	= HOSTLD  $@
+      cmd_host-cmulti	= $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
+			  $(addprefix $(obj)/,$($(@F)-objs)) \
+			  $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
+$(host-cmulti): %: $(host-cobjs) $(host-cshlib) FORCE
+	$(call if_changed,host-cmulti)
+
+# Create .o file from a single .c file
+# host-cobjs -> .o
+quiet_cmd_host-cobjs	= HOSTCC  $@
+      cmd_host-cobjs	= $(HOSTCC) $(hostc_flags) -c -o $@ $<
+$(host-cobjs): %.o: %.c FORCE
+	$(call if_changed_dep,host-cobjs)
+
+# Link an executable based on list of .o files, a mixture of .c and .cc
+# host-cxxmulti -> executable
+quiet_cmd_host-cxxmulti	= HOSTLD  $@
+      cmd_host-cxxmulti	= $(HOSTCXX) $(HOSTLDFLAGS) -o $@ \
+			  $(foreach o,objs cxxobjs,\
+			  $(addprefix $(obj)/,$($(@F)-$(o)))) \
+			  $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
+$(host-cxxmulti): %: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE
+	$(call if_changed,host-cxxmulti)
+
+# Create .o file from a single .cc (C++) file
+quiet_cmd_host-cxxobjs	= HOSTCXX $@
+      cmd_host-cxxobjs	= $(HOSTCXX) $(hostcxx_flags) -c -o $@ $<
+$(host-cxxobjs): %.o: %.cc FORCE
+	$(call if_changed_dep,host-cxxobjs)
+
+# Compile .c file, create position independent .o file
+# host-cshobjs -> .o
+quiet_cmd_host-cshobjs	= HOSTCC  -fPIC $@
+      cmd_host-cshobjs	= $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
+$(host-cshobjs): %.o: %.c FORCE
+	$(call if_changed_dep,host-cshobjs)
+
+# Link a shared library, based on position independent .o files
+# *.o -> .so shared library (host-cshlib)
+quiet_cmd_host-cshlib	= HOSTLLD -shared $@
+      cmd_host-cshlib	= $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
+			  $(addprefix $(obj)/,$($(@F:.so=-objs))) \
+			  $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
+$(host-cshlib): %: $(host-cshobjs) FORCE
+	$(call if_changed,host-cshlib)
+
+targets += $(host-csingle)  $(host-cmulti) $(host-cobjs)\
+	   $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) 
+
diff --git a/scripts/basic/Kbuild b/scripts/basic/Kbuild
new file mode 100644
index 0000000..22e09d2
--- /dev/null
+++ b/scripts/basic/Kbuild
@@ -0,0 +1,6 @@
+#
+# Kbuild file to build basic kbuild programs
+#
+
+hostprogs-y := fixdep
+always      := $(hostprogs-y)
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
new file mode 100644
index 0000000..0b61bea
--- /dev/null
+++ b/scripts/basic/fixdep.c
@@ -0,0 +1,390 @@
+/*
+ * "Optimize" a list of dependencies as spit out by gcc -MD
+ * for the kernel build
+ * ===========================================================================
+ *
+ * Author       Kai Germaschewski
+ * Copyright    2002 by Kai Germaschewski  <kai.germaschewski@gmx.de>
+ *
+ * This software may be used and distributed according to the terms
+ * of the GNU General Public License, incorporated herein by reference.
+ *
+ *
+ * Introduction:
+ *
+ * gcc produces a very nice and correct list of dependencies which
+ * tells make when to remake a file.
+ *
+ * To use this list as-is however has the drawback that virtually
+ * every file in the kernel includes <linux/config.h> which then again
+ * includes <linux/autoconf.h>
+ *
+ * If the user re-runs make *config, linux/autoconf.h will be
+ * regenerated.  make notices that and will rebuild every file which
+ * includes autoconf.h, i.e. basically all files. This is extremely
+ * annoying if the user just changed CONFIG_HIS_DRIVER from n to m.
+ *
+ * So we play the same trick that "mkdep" played before. We replace
+ * the dependency on linux/autoconf.h by a dependency on every config
+ * option which is mentioned in any of the listed prequisites.
+ *
+ * To be exact, split-include populates a tree in include/config/,
+ * e.g. include/config/his/driver.h, which contains the #define/#undef
+ * for the CONFIG_HIS_DRIVER option.
+ *
+ * So if the user changes his CONFIG_HIS_DRIVER option, only the objects
+ * which depend on "include/linux/config/his/driver.h" will be rebuilt,
+ * so most likely only his driver ;-)
+ *
+ * The idea above dates, by the way, back to Michael E Chastain, AFAIK.
+ *
+ * So to get dependencies right, there are two issues:
+ * o if any of the files the compiler read changed, we need to rebuild
+ * o if the command line given to the compile the file changed, we
+ *   better rebuild as well.
+ *
+ * The former is handled by using the -MD output, the later by saving
+ * the command line used to compile the old object and comparing it
+ * to the one we would now use.
+ *
+ * Again, also this idea is pretty old and has been discussed on
+ * kbuild-devel a long time ago. I don't have a sensibly working
+ * internet connection right now, so I rather don't mention names
+ * without double checking.
+ *
+ * This code here has been based partially based on mkdep.c, which
+ * says the following about its history:
+ *
+ *   Copyright abandoned, Michael Chastain, <mailto:mec@shout.net>.
+ *   This is a C version of syncdep.pl by Werner Almesberger.
+ *
+ *
+ * It is invoked as
+ *
+ *   fixdep <depfile> <target> <cmdline>
+ *
+ * and will read the dependency file <depfile>
+ *
+ * The transformed dependency snipped is written to stdout.
+ *
+ * It first generates a line
+ *
+ *   cmd_<target> = <cmdline>
+ *
+ * and then basically copies the .<target>.d file to stdout, in the
+ * process filtering out the dependency on linux/autoconf.h and adding
+ * dependencies on include/config/my/option.h for every
+ * CONFIG_MY_OPTION encountered in any of the prequisites.
+ *
+ * It will also filter out all the dependencies on *.ver. We need
+ * to make sure that the generated version checksum are globally up
+ * to date before even starting the recursive build, so it's too late
+ * at this point anyway.
+ *
+ * The algorithm to grep for "CONFIG_..." is bit unusual, but should
+ * be fast ;-) We don't even try to really parse the header files, but
+ * merely grep, i.e. if CONFIG_FOO is mentioned in a comment, it will
+ * be picked up as well. It's not a problem with respect to
+ * correctness, since that can only give too many dependencies, thus
+ * we cannot miss a rebuild. Since people tend to not mention totally
+ * unrelated CONFIG_ options all over the place, it's not an
+ * efficiency problem either.
+ *
+ * (Note: it'd be easy to port over the complete mkdep state machine,
+ *  but I don't think the added complexity is worth it)
+ */
+/*
+ * Note 2: if somebody writes HELLO_CONFIG_BOOM in a file, it will depend onto
+ * CONFIG_BOOM. This could seem a bug (not too hard to fix), but please do not
+ * fix it! Some UserModeLinux files (look at arch/um/) call CONFIG_BOOM as
+ * UML_CONFIG_BOOM, to avoid conflicts with /usr/include/linux/autoconf.h,
+ * through arch/um/include/uml-config.h; this fixdep "bug" makes sure that
+ * those files will have correct dependencies.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
+#include <ctype.h>
+#include <arpa/inet.h>
+
+#define INT_CONF ntohl(0x434f4e46)
+#define INT_ONFI ntohl(0x4f4e4649)
+#define INT_NFIG ntohl(0x4e464947)
+#define INT_FIG_ ntohl(0x4649475f)
+
+char *target;
+char *depfile;
+char *cmdline;
+
+void usage(void)
+
+{
+	fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n");
+	exit(1);
+}
+
+void print_cmdline(void)
+{
+	printf("cmd_%s := %s\n\n", target, cmdline);
+}
+
+char * str_config  = NULL;
+int    size_config = 0;
+int    len_config  = 0;
+
+/*
+ * Grow the configuration string to a desired length.
+ * Usually the first growth is plenty.
+ */
+void grow_config(int len)
+{
+	while (len_config + len > size_config) {
+		if (size_config == 0)
+			size_config = 2048;
+		str_config = realloc(str_config, size_config *= 2);
+		if (str_config == NULL)
+			{ perror("fixdep:malloc"); exit(1); }
+	}
+}
+
+
+
+/*
+ * Lookup a value in the configuration string.
+ */
+int is_defined_config(const char * name, int len)
+{
+	const char * pconfig;
+	const char * plast = str_config + len_config - len;
+	for ( pconfig = str_config + 1; pconfig < plast; pconfig++ ) {
+		if (pconfig[ -1] == '\n'
+		&&  pconfig[len] == '\n'
+		&&  !memcmp(pconfig, name, len))
+			return 1;
+	}
+	return 0;
+}
+
+/*
+ * Add a new value to the configuration string.
+ */
+void define_config(const char * name, int len)
+{
+	grow_config(len + 1);
+
+	memcpy(str_config+len_config, name, len);
+	len_config += len;
+	str_config[len_config++] = '\n';
+}
+
+/*
+ * Clear the set of configuration strings.
+ */
+void clear_config(void)
+{
+	len_config = 0;
+	define_config("", 0);
+}
+
+/*
+ * Record the use of a CONFIG_* word.
+ */
+void use_config(char *m, int slen)
+{
+	char s[PATH_MAX];
+	char *p;
+
+	if (is_defined_config(m, slen))
+	    return;
+
+	define_config(m, slen);
+
+	memcpy(s, m, slen); s[slen] = 0;
+
+	for (p = s; p < s + slen; p++) {
+		if (*p == '_')
+			*p = '/';
+		else
+			*p = tolower((int)*p);
+	}
+	printf("    $(wildcard include/config/%s.h) \\\n", s);
+}
+
+void parse_config_file(char *map, size_t len)
+{
+	int *end = (int *) (map + len);
+	/* start at +1, so that p can never be < map */
+	int *m   = (int *) map + 1;
+	char *p, *q;
+
+	for (; m < end; m++) {
+		if (*m == INT_CONF) { p = (char *) m  ; goto conf; }
+		if (*m == INT_ONFI) { p = (char *) m-1; goto conf; }
+		if (*m == INT_NFIG) { p = (char *) m-2; goto conf; }
+		if (*m == INT_FIG_) { p = (char *) m-3; goto conf; }
+		continue;
+	conf:
+		if (p > map + len - 7)
+			continue;
+		if (memcmp(p, "CONFIG_", 7))
+			continue;
+		for (q = p + 7; q < map + len; q++) {
+			if (!(isalnum(*q) || *q == '_'))
+				goto found;
+		}
+		continue;
+
+	found:
+		use_config(p+7, q-p-7);
+	}
+}
+
+/* test is s ends in sub */
+int strrcmp(char *s, char *sub)
+{
+	int slen = strlen(s);
+	int sublen = strlen(sub);
+
+	if (sublen > slen)
+		return 1;
+
+	return memcmp(s + slen - sublen, sub, sublen);
+}
+
+void do_config_file(char *filename)
+{
+	struct stat st;
+	int fd;
+	void *map;
+
+	fd = open(filename, O_RDONLY);
+	if (fd < 0) {
+		fprintf(stderr, "fixdep: ");
+		perror(filename);
+		exit(2);
+	}
+	fstat(fd, &st);
+	if (st.st_size == 0) {
+		close(fd);
+		return;
+	}
+	map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+	if ((long) map == -1) {
+		perror("fixdep: mmap");
+		close(fd);
+		return;
+	}
+
+	parse_config_file(map, st.st_size);
+
+	munmap(map, st.st_size);
+
+	close(fd);
+}
+
+void parse_dep_file(void *map, size_t len)
+{
+	char *m = map;
+	char *end = m + len;
+	char *p;
+	char s[PATH_MAX];
+
+	p = strchr(m, ':');
+	if (!p) {
+		fprintf(stderr, "fixdep: parse error\n");
+		exit(1);
+	}
+	memcpy(s, m, p-m); s[p-m] = 0;
+	printf("deps_%s := \\\n", target);
+	m = p+1;
+
+	clear_config();
+
+	while (m < end) {
+		while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
+			m++;
+		p = m;
+		while (p < end && *p != ' ') p++;
+		if (p == end) {
+			do p--; while (!isalnum(*p));
+			p++;
+		}
+		memcpy(s, m, p-m); s[p-m] = 0;
+		if (strrcmp(s, "include/linux/autoconf.h") &&
+		    strrcmp(s, "arch/um/include/uml-config.h") &&
+		    strrcmp(s, ".ver")) {
+			printf("  %s \\\n", s);
+			do_config_file(s);
+		}
+		m = p + 1;
+	}
+	printf("\n%s: $(deps_%s)\n\n", target, target);
+	printf("$(deps_%s):\n", target);
+}
+
+void print_deps(void)
+{
+	struct stat st;
+	int fd;
+	void *map;
+
+	fd = open(depfile, O_RDONLY);
+	if (fd < 0) {
+		fprintf(stderr, "fixdep: ");
+		perror(depfile);
+		exit(2);
+	}
+	fstat(fd, &st);
+	if (st.st_size == 0) {
+		fprintf(stderr,"fixdep: %s is empty\n",depfile);
+		close(fd);
+		return;
+	}
+	map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+	if ((long) map == -1) {
+		perror("fixdep: mmap");
+		close(fd);
+		return;
+	}
+
+	parse_dep_file(map, st.st_size);
+
+	munmap(map, st.st_size);
+
+	close(fd);
+}
+
+void traps(void)
+{
+	static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
+
+	if (*(int *)test != INT_CONF) {
+		fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
+			*(int *)test);
+		exit(2);
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	traps();
+
+	if (argc != 4)
+		usage();
+
+	depfile = argv[1];
+	target = argv[2];
+	cmdline = argv[3];
+
+	print_cmdline();
+	print_deps();
+
+	return 0;
+}
diff --git a/kernel/Kbuild b/usr/Kbuild
similarity index 73%
rename from kernel/Kbuild
rename to usr/Kbuild
index 9df200a..daf5e3f 100644
--- a/kernel/Kbuild
+++ b/usr/Kbuild
@@ -2,14 +2,31 @@
 # kbuild file for usr/ - including initramfs image and klibc
 #
 
-obj-y        := initramfs_data.o
-always       := klibc/libc.a
-hostprogs-y  := gen_init_cpio
-clean-files  := initramfs_data.cpio.gz initramfs_list
+# klibc definitions - to be moved to top-level Makefile later
+export KLIBCSRC := $(srctree)/$(src)/klibc
+export KLIBCINC := $(srctree)/$(src)/include
+export KLIBCOBJ := $(objtree)/$(obj)/klibc
+CONFIG_KLIBC := 1
 
-# 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)/dash
+	$(Q)$(MAKE) $(klibc)=$(src)/gzip
+endif
+subdir- := klibc kinit utils dash gzip
+
+
+# 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
@@ -34,7 +51,7 @@
   $(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    $@
@@ -55,8 +72,10 @@
 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
@@ -64,9 +83,10 @@
 
 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/usr/kinit/Kbuild b/usr/kinit/Kbuild
new file mode 100644
index 0000000..a2d899e
--- /dev/null
+++ b/usr/kinit/Kbuild
@@ -0,0 +1,27 @@
+#
+# Kbuild file for kinit
+#
+
+static-y := kinit
+kinit-y  := kinit.o do_mounts.o nfsroot.o getintfile.o initrd.o
+kinit-y  += open.o readfile.o
+
+kinit-y  += ipconfig/
+kinit-y  += nfsmount/
+
+
+# kinit.c include ipconfig header file
+KLIBCCFLAGS_kinit.o   := -I$(srctree)/$(src)/ipconfig
+# So do nfsroot
+KLIBCCFLAGS_nfsroot.o := -I$(srctree)/$(src)/ipconfig -I$(srctree)/$(src)/nfsmount
+
+
+# TODO - stripped image
+
+# Cleaning
+targets := $(static-y) $(shared-y)
+subdir- := ipconfig nfsmount
+
+
+# install binary
+install-y := kinit
diff --git a/kinit/README b/usr/kinit/README
similarity index 100%
rename from kinit/README
rename to usr/kinit/README
diff --git a/kinit/do_mounts.c b/usr/kinit/do_mounts.c
similarity index 100%
rename from kinit/do_mounts.c
rename to usr/kinit/do_mounts.c
diff --git a/kinit/do_mounts.h b/usr/kinit/do_mounts.h
similarity index 100%
rename from kinit/do_mounts.h
rename to usr/kinit/do_mounts.h
diff --git a/kinit/getintfile.c b/usr/kinit/getintfile.c
similarity index 100%
rename from kinit/getintfile.c
rename to usr/kinit/getintfile.c
diff --git a/kinit/initrd.c b/usr/kinit/initrd.c
similarity index 100%
rename from kinit/initrd.c
rename to usr/kinit/initrd.c
diff --git a/usr/kinit/ipconfig/Kbuild b/usr/kinit/ipconfig/Kbuild
new file mode 100644
index 0000000..7f8d181
--- /dev/null
+++ b/usr/kinit/ipconfig/Kbuild
@@ -0,0 +1,31 @@
+#
+# Kbuild file for ipconfig
+#
+
+static-y := static/ipconfig
+shared-y := shared/ipconfig
+
+# common .o files
+objs := main.o netdev.o packet.o
+# dhcp
+objs += dhcp_proto.o
+# bootp
+objs += bootp_proto.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)
+lib-y := $(objs)
+
+# .o files used to built executables
+static/ipconfig-y := $(objs)
+shared/ipconfig-y := $(objs)
+
+# Cleaning
+clean-dirs := static shared
+
+# install binary
+install-y := $(shared-y)
diff --git a/ipconfig/README b/usr/kinit/ipconfig/README
similarity index 100%
rename from ipconfig/README
rename to usr/kinit/ipconfig/README
diff --git a/ipconfig/bootp_packet.h b/usr/kinit/ipconfig/bootp_packet.h
similarity index 100%
rename from ipconfig/bootp_packet.h
rename to usr/kinit/ipconfig/bootp_packet.h
diff --git a/ipconfig/bootp_proto.c b/usr/kinit/ipconfig/bootp_proto.c
similarity index 100%
rename from ipconfig/bootp_proto.c
rename to usr/kinit/ipconfig/bootp_proto.c
diff --git a/ipconfig/bootp_proto.h b/usr/kinit/ipconfig/bootp_proto.h
similarity index 100%
rename from ipconfig/bootp_proto.h
rename to usr/kinit/ipconfig/bootp_proto.h
diff --git a/ipconfig/dhcp_proto.c b/usr/kinit/ipconfig/dhcp_proto.c
similarity index 100%
rename from ipconfig/dhcp_proto.c
rename to usr/kinit/ipconfig/dhcp_proto.c
diff --git a/ipconfig/dhcp_proto.h b/usr/kinit/ipconfig/dhcp_proto.h
similarity index 100%
rename from ipconfig/dhcp_proto.h
rename to usr/kinit/ipconfig/dhcp_proto.h
diff --git a/ipconfig/ipconfig.h b/usr/kinit/ipconfig/ipconfig.h
similarity index 100%
rename from ipconfig/ipconfig.h
rename to usr/kinit/ipconfig/ipconfig.h
diff --git a/ipconfig/main.c b/usr/kinit/ipconfig/main.c
similarity index 100%
rename from ipconfig/main.c
rename to usr/kinit/ipconfig/main.c
diff --git a/ipconfig/netdev.c b/usr/kinit/ipconfig/netdev.c
similarity index 100%
rename from ipconfig/netdev.c
rename to usr/kinit/ipconfig/netdev.c
diff --git a/ipconfig/netdev.h b/usr/kinit/ipconfig/netdev.h
similarity index 100%
rename from ipconfig/netdev.h
rename to usr/kinit/ipconfig/netdev.h
diff --git a/ipconfig/packet.c b/usr/kinit/ipconfig/packet.c
similarity index 100%
rename from ipconfig/packet.c
rename to usr/kinit/ipconfig/packet.c
diff --git a/ipconfig/packet.h b/usr/kinit/ipconfig/packet.h
similarity index 100%
rename from ipconfig/packet.h
rename to usr/kinit/ipconfig/packet.h
diff --git a/kinit/kinit.c b/usr/kinit/kinit.c
similarity index 100%
rename from kinit/kinit.c
rename to usr/kinit/kinit.c
diff --git a/kinit/kinit.h b/usr/kinit/kinit.h
similarity index 100%
rename from kinit/kinit.h
rename to usr/kinit/kinit.h
diff --git a/usr/kinit/nfsmount/Kbuild b/usr/kinit/nfsmount/Kbuild
new file mode 100644
index 0000000..6759ee3
--- /dev/null
+++ b/usr/kinit/nfsmount/Kbuild
@@ -0,0 +1,27 @@
+#
+# kbuild file for nfsmount
+#
+
+static-y := static/nfsmount
+#FIXME - build is broken static-y := dummypmap 
+shared-y := shared/nfsmount
+
+objs := main.o mount.o portmap.o dummypmap.o sunrpc.o
+
+# Create built-in.o with all .o files (used by kinit)
+lib-y := $(objs)
+
+# .o files used for executables
+static/nfsmount-y := $(objs)
+shared/nfsmount-y := $(objs)
+
+# dummypmap uses a single .o file (rename src file?)
+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
+
+# Install binary
+install-y := $(shared-y)
diff --git a/nfsmount/README.locking b/usr/kinit/nfsmount/README.locking
similarity index 100%
rename from nfsmount/README.locking
rename to usr/kinit/nfsmount/README.locking
diff --git a/nfsmount/dummypmap.c b/usr/kinit/nfsmount/dummypmap.c
similarity index 100%
rename from nfsmount/dummypmap.c
rename to usr/kinit/nfsmount/dummypmap.c
diff --git a/nfsmount/dummypmap.h b/usr/kinit/nfsmount/dummypmap.h
similarity index 100%
rename from nfsmount/dummypmap.h
rename to usr/kinit/nfsmount/dummypmap.h
diff --git a/nfsmount/dummypmap_test.c b/usr/kinit/nfsmount/dummypmap_test.c
similarity index 100%
rename from nfsmount/dummypmap_test.c
rename to usr/kinit/nfsmount/dummypmap_test.c
diff --git a/nfsmount/main.c b/usr/kinit/nfsmount/main.c
similarity index 100%
rename from nfsmount/main.c
rename to usr/kinit/nfsmount/main.c
diff --git a/nfsmount/mount.c b/usr/kinit/nfsmount/mount.c
similarity index 100%
rename from nfsmount/mount.c
rename to usr/kinit/nfsmount/mount.c
diff --git a/nfsmount/nfsmount.h b/usr/kinit/nfsmount/nfsmount.h
similarity index 100%
rename from nfsmount/nfsmount.h
rename to usr/kinit/nfsmount/nfsmount.h
diff --git a/nfsmount/portmap.c b/usr/kinit/nfsmount/portmap.c
similarity index 100%
rename from nfsmount/portmap.c
rename to usr/kinit/nfsmount/portmap.c
diff --git a/nfsmount/sunrpc.c b/usr/kinit/nfsmount/sunrpc.c
similarity index 100%
rename from nfsmount/sunrpc.c
rename to usr/kinit/nfsmount/sunrpc.c
diff --git a/nfsmount/sunrpc.h b/usr/kinit/nfsmount/sunrpc.h
similarity index 100%
rename from nfsmount/sunrpc.h
rename to usr/kinit/nfsmount/sunrpc.h
diff --git a/kinit/nfsroot.c b/usr/kinit/nfsroot.c
similarity index 100%
rename from kinit/nfsroot.c
rename to usr/kinit/nfsroot.c
diff --git a/kinit/open.c b/usr/kinit/open.c
similarity index 100%
rename from kinit/open.c
rename to usr/kinit/open.c
diff --git a/kinit/readfile.c b/usr/kinit/readfile.c
similarity index 100%
rename from kinit/readfile.c
rename to usr/kinit/readfile.c
diff --git a/utils/Kbuild b/utils/Kbuild
new file mode 100644
index 0000000..f983325
--- /dev/null
+++ b/utils/Kbuild
@@ -0,0 +1,54 @@
+#
+# Kbuild file for klib utils
+#
+
+progs := chroot dd fstype mkdir mkfifo mount pivot_root umount
+progs += true false sleep ln nuke minips run-init 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/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
+
+# Clean deletes the static and shared dir
+clean-dirs := static shared
+
+# install only install the shared binaries
+install-y := $(shared-y)
diff --git a/utils/Makefile b/utils/Makefile
deleted file mode 100644
index 336e1e9..0000000
--- a/utils/Makefile
+++ /dev/null
@@ -1,57 +0,0 @@
-SRCROOT  = ..
-include ../MCONFIG
-include ../MRULES
-
-MAKEDEPS     = -Wp,-MD,.$(subst /,-,$*).d
-CFLAGS       = $(MAKEDEPS) $(OPTFLAGS) $(REQFLAGS) -W -Wall
-LIBS         = $(KLIBC) $(LIBGCC)
-PROGS       := chroot dd fstype mkdir mkfifo mount pivot_root umount \
-		true false sleep ln nuke minips run-init cat \
-		insmod uname
-STATICPROGS := $(patsubst %,static/%,$(PROGS))
-SHAREDPROGS := $(patsubst %,shared/%,$(PROGS))
-OBJS        := $(patsubst %,%.o,$(PROGS))
-LIBOBJS	     = file_mode.o
-LIBUTILS     = libutils.a
-
-all:	$(STATICPROGS) $(SHAREDPROGS)
-
-.SECONDARY: $(OBJS)
-
-static/%: %.o $(CRT0) $(LIBS) $(LIBUTILS)
-	mkdir -p static static.g
-	$(LD) $(LDFLAGS) -o $@ $(CRT0) $< $(LIBUTILS) $(LIBS)
-	cp -f $@ static.g
-	$(STRIPCMD) $@
-
-shared/%: %.o $(CRTSHARED) $(LIBSHARED) $(LIBUTILS)
-	mkdir -p shared shared.g
-	$(LD) $(LDFLAGS) -o $@ $(EMAIN) $(CRTSHARED) $< $(LIBUTILS) \
-		-R $(LIBSHARED) $(LIBGCC)
-	cp -f $@ shared.g
-	$(STRIPCMD) $@
-
-# Programs that consist of more than one file
-mount.o: mount_main.o mount_opts.o
-	$(LD) $(LDFLAGS) -r -o $@ $^
-
-$(LIBUTILS): $(LIBOBJS)
-	-rm -f $@
-	$(AR) cq $@ $^
-	$(RANLIB) $@
-
-$(CRT0) $(LIBS):
-	@echo '*** error: $@ not up to date' || exit 1
-
-clean:
-	$(RM) *.o core $(LIBUTILS) $(PROGS) .*.d
-	$(RM) -rf static static.g shared shared.g
-
-spotless: clean
-	$(RM) *~
-
-install: all
-	$(INSTALL_EXEC) shared/* $(INSTALLROOT)$(INSTALLDIR)/$(CROSS)bin	
-ifneq ($(wildcard .*.d),)
-include $(wildcard .*.d)
-endif
diff --git a/utils/sleep.c b/utils/sleep.c
index 769b456..0c2ebcb 100644
--- a/utils/sleep.c
+++ b/utils/sleep.c
@@ -1,23 +1,26 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <time.h>
+#include <errno.h>
 
 int main(int argc, char *argv[])
 {
-	unsigned long s;
+	struct timespec ts;
 	char *p;
 
 	if (argc != 2)
 		goto err;
 
-	s = strtoul(argv[1], &p, 10);
+	p = strtotimespec(argv[1], &ts);
 	if ( *p )
 		goto err;
 
-	sleep(s);
+	while ( nanosleep(&ts, &ts) == -1 && errno == EINTR )
+		;
 
 	return 0;
 
 err:
-	fprintf(stderr, "Usage: %s seconds\n", argv[0]);
+	fprintf(stderr, "Usage: %s seconds[.fraction]\n", argv[0]);
 	return 1; 
 }