More build fixes

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3407 42af7a65-404d-4744-a932-0658087f49c3
diff --git a/ChangeLog.txt b/ChangeLog.txt
index 9d64b5c..681802a 100755
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -10,4 +10,7 @@
 	* Makefile -- Makefile cosmetics (I am slowly adding the Darjeeling JVM)

 	* Make.defs -- New file adds common make definitions for applications.

 	* hello/Makefile -- Now uses new Make.defs definitions.  Added README.txt.

-	* apps/poweroff -- New application to turn off board power.
\ No newline at end of file
+	* apps/poweroff -- New application to turn off board power.
+	* Moved NSH library, netutils, and examples from the nuttx/ directory to
+	  the apps/ directory
+	* Moved exec_nuttapp machinery into the nuttapp/ directory.
diff --git a/Make.defs b/Make.defs
index 5b6cd9a..f459264 100755
--- a/Make.defs
+++ b/Make.defs
@@ -36,6 +36,6 @@
 
 define REGISTER
 	@echo "Register: $1"
-	@echo "{ .name = \"$1\", .priority = $2, .stacksize = $3, .main = $4 }," >> "$(APPDIR)/exec_nuttapp_list.h"
-	@echo "EXTERN int $4(int argc, char *argv[]);" >> "$(APPDIR)/exec_nuttapp_proto.h"
+	@echo "{ .name = \"$1\", .priority = $2, .stacksize = $3, .main = $4 }," >> "$(APPDIR)/nuttapp/exec_nuttapp_list.h"
+	@echo "EXTERN int $4(int argc, char *argv[]);" >> "$(APPDIR)/nuttapp/exec_nuttapp_proto.h"
 endef
diff --git a/Makefile b/Makefile
index 76eeb1e..be7b9f6 100644
--- a/Makefile
+++ b/Makefile
@@ -41,15 +41,16 @@
 # Application Directories
 
 # SUBDIRS is the list of all directories containing Makefiles.  It is used
-# only for cleaning.
+# only for cleaning. nuttapp must always be the first in the list.
 
-SUBDIRS = nshlib netutils examples vsn
+SUBDIRS = nuttapp nshlib netutils examples vsn
 
-# we use a non-existing .built_always to guarantee that Makefile
-# always walks into the sub-directories and asks for build
+# We use a non-existing .built_always to guarantee that Makefile always walks
+# into the sub-directories and asks for build.  NOTE that nuttapp is always
+# in the list of applications to be built
 
-BUILTIN_APPS_BUILT =
-BUILTIN_APPS_DIR =
+BUILTIN_APPS_BUILT = nuttapp/.built_always
+BUILTIN_APPS_DIR = nuttapp
 
 ifeq ($(CONFIG_BUILTIN_APPS),y)
 
@@ -89,69 +90,44 @@
 
 endif
 
-# Source and object files
+# The final build target
 
-ASRCS		=
-CSRCS		= exec_nuttapp.c
+BIN		= libapps$(LIBEXT)
 
-AOBJS		= $(ASRCS:.S=$(OBJEXT))
-COBJS		= $(CSRCS:.c=$(OBJEXT))
+# Build targets
 
-SRCS		= $(ASRCS) $(CSRCS)
-OBJS		= $(AOBJS) $(COBJS)
+all: $(BIN)
+.PHONY: $(BUILTIN_APPS_BUILT) .depend depend clean distclean
 
-BIN	    	= libapps$(LIBEXT)
-
-ROOTDEPPATH	= --dep-path .
-VPATH		= 
-
-all:	$(BIN)
-.PHONY: .depend depend clean distclean 
-
-$(AOBJS): %$(OBJEXT): %.S
-	$(call ASSEMBLE, $<, $@)
-
-$(COBJS): %$(OBJEXT): %.c
-	$(call COMPILE, $<, $@)
-	
 $(BUILTIN_APPS_BUILT):
 	@for dir in $(BUILTIN_APPS_DIR) ; do \
 		$(MAKE) -C $$dir TOPDIR="$(TOPDIR)" APPDIR=$(APPDIR); \
 	done
 
-$(BIN):	$(OBJS) $(BUILTIN_APPS_BUILT)
+$(BIN):	$(BUILTIN_APPS_BUILT)
 	@( for obj in $(OBJS) ; do \
 		$(call ARCHIVE, $@, $${obj}); \
 	done ; )
 
 .depend: Makefile $(SRCS)
-	@echo "/* List of application requirements, generated during make depend. */" > exec_nuttapp_list.h
-	@echo "/* List of application entry points, generated during make depend. */" > exec_nuttapp_proto.h
-	@$(MKDEP) $(ROOTDEPPATH) \
-	  $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
-	@touch $@
 	@for dir in $(BUILTIN_APPS_DIR) ; do \
 		rm -f $$dir/.depend ; \
 		$(MAKE) -C $$dir TOPDIR="$(TOPDIR)"  APPDIR=$(APPDIR) depend ; \
 	done
+	@touch $@
 
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *~ .*.swp *.o libapps.a
-	$(call CLEAN)
 	@for dir in $(SUBDIRS) ; do \
 		$(MAKE) -C $$dir clean TOPDIR="$(TOPDIR)" APPDIR=$(APPDIR); \
 	done
+	@rm -f $(BIN) *~ .*.swp *.o
+	$(call CLEAN)
 
 distclean: clean
-	@rm -f .config
-	@rm -f Make.dep .depend
-	@rm -f exec_nuttapp_list.h
-	@rm -f exec_nuttapp_proto.h
 	@for dir in $(SUBDIRS) ; do \
 		$(MAKE) -C $$dir distclean TOPDIR="$(TOPDIR)" APPDIR=$(APPDIR); \
 	done
-
--include Make.dep
+	@rm -f .config .depend
 
diff --git a/examples/dhcpd/Makefile b/examples/dhcpd/Makefile
index d3ebff9..d4f03f7 100644
--- a/examples/dhcpd/Makefile
+++ b/examples/dhcpd/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/hello/Makefile b/examples/hello/Makefile
index 73430c5..c856f14 100644
--- a/examples/hello/Makefile
+++ b/examples/hello/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/helloxx/Makefile b/examples/helloxx/Makefile
index 69c4e08..5cbf55e 100755
--- a/examples/helloxx/Makefile
+++ b/examples/helloxx/Makefile
@@ -50,7 +50,7 @@
 SRCS		= $(ASRCS) $(CSRCS) $(CXXSRCS)
 OBJS		= $(AOBJS) $(COBJS) $(CXXOBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -98,7 +98,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/hidkbd/Makefile b/examples/hidkbd/Makefile
index c0c21d6..48b0c90 100644
--- a/examples/hidkbd/Makefile
+++ b/examples/hidkbd/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/igmp/Makefile b/examples/igmp/Makefile
index 9997146..d1362f0 100755
--- a/examples/igmp/Makefile
+++ b/examples/igmp/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/mm/Makefile b/examples/mm/Makefile
index c9ef6f9..747a1a1 100644
--- a/examples/mm/Makefile
+++ b/examples/mm/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/mount/Makefile b/examples/mount/Makefile
index 46a8c05..04d2d21 100644
--- a/examples/mount/Makefile
+++ b/examples/mount/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/nettest/Makefile b/examples/nettest/Makefile
index 37d0091..52e205f 100644
--- a/examples/nettest/Makefile
+++ b/examples/nettest/Makefile
@@ -54,7 +54,7 @@
 TARG_SRCS	= $(TARG_ASRCS) $(TARG_CSRCS)
 TARG_OBJS	= $(TARG_AOBJS) $(TARG_COBJS)
 
-TARG_BIN	= ../../libapps$(LIBEXT)
+TARG_BIN	= $(APPDIR)/libapps$(LIBEXT)
 
 HOSTCFLAGS	+= -DCONFIG_EXAMPLE_NETTEST_HOST=1
 ifeq ($(CONFIG_EXAMPLE_NETTEST_SERVER),y)
diff --git a/examples/nsh/Makefile b/examples/nsh/Makefile
index 92fd8e1..1887d3b 100644
--- a/examples/nsh/Makefile
+++ b/examples/nsh/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/null/Makefile b/examples/null/Makefile
index 2b4171e..9d84263 100644
--- a/examples/null/Makefile
+++ b/examples/null/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/nx/Makefile b/examples/nx/Makefile
index bfb0d47..72ba191 100644
--- a/examples/nx/Makefile
+++ b/examples/nx/Makefile
@@ -51,7 +51,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -84,7 +84,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/nxflat/Makefile b/examples/nxflat/Makefile
index b5f3e2d..73a5a95 100644
--- a/examples/nxflat/Makefile
+++ b/examples/nxflat/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -86,7 +86,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/ostest/Makefile b/examples/ostest/Makefile
index 0e50db4..469fe03 100644
--- a/examples/ostest/Makefile
+++ b/examples/ostest/Makefile
@@ -88,7 +88,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -121,7 +121,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/pashello/Makefile b/examples/pashello/Makefile
index 501ac2d..6e25791 100644
--- a/examples/pashello/Makefile
+++ b/examples/pashello/Makefile
@@ -55,7 +55,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -88,7 +88,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/pipe/Makefile b/examples/pipe/Makefile
index 886409f..e46bbdd 100644
--- a/examples/pipe/Makefile
+++ b/examples/pipe/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/poll/Makefile b/examples/poll/Makefile
index 0bfc97e..e33e493 100644
--- a/examples/poll/Makefile
+++ b/examples/poll/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/romfs/Makefile b/examples/romfs/Makefile
index 70b5e86..7e12866 100644
--- a/examples/romfs/Makefile
+++ b/examples/romfs/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -97,7 +97,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/sendmail/Makefile b/examples/sendmail/Makefile
index def1798..81aed5c 100644
--- a/examples/sendmail/Makefile
+++ b/examples/sendmail/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 	@make -f Makefile.host clean TOPDIR=$(TOPDIR) APPDIR=$(APPDIR)
 
diff --git a/examples/serloop/Makefile b/examples/serloop/Makefile
index 99b1aab..c3c0274 100644
--- a/examples/serloop/Makefile
+++ b/examples/serloop/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/thttpd/Makefile b/examples/thttpd/Makefile
index acc49d9..91c8c19 100644
--- a/examples/thttpd/Makefile
+++ b/examples/thttpd/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -84,7 +84,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	@make -C content clean TOPDIR=$(TOPDIR) APPDIR=$(APPDIR) CROSSDEV=$(CROSSDEV)
 	$(call CLEAN)
 
diff --git a/examples/udp/Makefile b/examples/udp/Makefile
index e0789ed..ddffda7 100644
--- a/examples/udp/Makefile
+++ b/examples/udp/Makefile
@@ -54,7 +54,7 @@
 TARG_SRCS	= $(TARG_ASRCS) $(TARG_CSRCS)
 TARG_OBJS	= $(TARG_AOBJS) $(TARG_COBJS)
 
-TARG_BIN	= ../../libapps$(LIBEXT)
+TARG_BIN	= $(APPDIR)/libapps$(LIBEXT)
 
 HOSTCFLAGS	+= -DCONFIG_EXAMPLE_UDP_HOST=1
 ifeq ($(CONFIG_EXAMPLE_UDP_SERVER),y)
diff --git a/examples/uip/Makefile b/examples/uip/Makefile
index 2dd209d..08abe15 100644
--- a/examples/uip/Makefile
+++ b/examples/uip/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/usbserial/Makefile b/examples/usbserial/Makefile
index 61fba52..2ac0cb0 100644
--- a/examples/usbserial/Makefile
+++ b/examples/usbserial/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,9 +81,9 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
-	@(MAKE) -f Makefile.host clean TOPDIR=$(TOPDIR) APPDIR=$(APPDIR)
+	@$(MAKE) -f Makefile.host clean TOPDIR=$(TOPDIR) APPDIR=$(APPDIR)
 
 distclean: clean
 	@rm -f Make.dep .depend
diff --git a/examples/usbserial/Makefile.host b/examples/usbserial/Makefile.host
index 8c8884b..cd9319a 100644
--- a/examples/usbserial/Makefile.host
+++ b/examples/usbserial/Makefile.host
@@ -39,7 +39,7 @@
 -include $(TOPDIR)/Make.defs
 
 SRC	= host.c
-BIN	= host
+BIN	= host$(EXEEXT)
 
 DEFINES	=
 ifeq ($(CONFIG_EXAMPLES_USBSERIAL_INONLY),y)
@@ -55,12 +55,13 @@
 DEFINES	+= -DCONFIG_EXAMPLES_USBSERIAL_ONLYBIG=1
 endif
 
-all: $(BIN)$(EXEEXT)
+all: $(BIN)
 
-$(BIN)$(EXEEXT): $(SRC)
+$(BIN): $(SRC)
 	@$(HOSTCC) $(HOSTCFLAGS) $(DEFINES) $^ -o $@
 
 clean:
 	@rm -f $(BIN) *~ .*.swp *.o
 	$(call CLEAN)
 
+
diff --git a/examples/usbstorage/Makefile b/examples/usbstorage/Makefile
index 7f777df..5e8983f 100644
--- a/examples/usbstorage/Makefile
+++ b/examples/usbstorage/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/examples/wget/Makefile b/examples/wget/Makefile
index e39d5f6..b9cc155 100644
--- a/examples/wget/Makefile
+++ b/examples/wget/Makefile
@@ -48,7 +48,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -81,7 +81,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 	@make -f Makefile.host clean TOPDIR=$(TOPDIR) APPDIR=$(APPDIR)
 
diff --git a/examples/wlan/Makefile b/examples/wlan/Makefile
index 53f8715..7563895 100755
--- a/examples/wlan/Makefile
+++ b/examples/wlan/Makefile
@@ -49,7 +49,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -82,7 +82,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/netutils/dhcpc/Makefile b/netutils/dhcpc/Makefile
index f127340..26f9c9e 100644
--- a/netutils/dhcpc/Makefile
+++ b/netutils/dhcpc/Makefile
@@ -52,7 +52,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -86,7 +86,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/netutils/dhcpd/Makefile b/netutils/dhcpd/Makefile
index cf9762d..5731d55 100644
--- a/netutils/dhcpd/Makefile
+++ b/netutils/dhcpd/Makefile
@@ -52,7 +52,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -86,7 +86,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/netutils/resolv/Makefile b/netutils/resolv/Makefile
index e4f49e4..07b68b9 100644
--- a/netutils/resolv/Makefile
+++ b/netutils/resolv/Makefile
@@ -52,7 +52,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -86,7 +86,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/netutils/smtp/Makefile b/netutils/smtp/Makefile
index c4d2383..75a929b 100644
--- a/netutils/smtp/Makefile
+++ b/netutils/smtp/Makefile
@@ -52,7 +52,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -86,7 +86,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/netutils/telnetd/Makefile b/netutils/telnetd/Makefile
index 0917b64..3d53a69 100644
--- a/netutils/telnetd/Makefile
+++ b/netutils/telnetd/Makefile
@@ -52,7 +52,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -86,7 +86,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/netutils/tftpc/Makefile b/netutils/tftpc/Makefile
index be9abac..c3f49c9 100644
--- a/netutils/tftpc/Makefile
+++ b/netutils/tftpc/Makefile
@@ -54,7 +54,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -88,7 +88,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/netutils/thttpd/Makefile b/netutils/thttpd/Makefile
index b47fe3a..133139a 100644
--- a/netutils/thttpd/Makefile
+++ b/netutils/thttpd/Makefile
@@ -52,7 +52,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -113,7 +113,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/netutils/uiplib/Makefile b/netutils/uiplib/Makefile
index 49949a1..84708a6 100644
--- a/netutils/uiplib/Makefile
+++ b/netutils/uiplib/Makefile
@@ -61,7 +61,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -93,7 +93,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/netutils/webclient/Makefile b/netutils/webclient/Makefile
index 2fdb192..a59eaca 100644
--- a/netutils/webclient/Makefile
+++ b/netutils/webclient/Makefile
@@ -52,7 +52,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -86,7 +86,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/netutils/webserver/Makefile b/netutils/webserver/Makefile
index 553d527..8d7a747 100644
--- a/netutils/webserver/Makefile
+++ b/netutils/webserver/Makefile
@@ -52,7 +52,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -86,7 +86,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/nshlib/Makefile b/nshlib/Makefile
index 943fc87..ecd2e55 100644
--- a/nshlib/Makefile
+++ b/nshlib/Makefile
@@ -73,7 +73,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -102,14 +102,14 @@
 	  $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
 	@touch $@
 
-# Register application
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
 	@rm -f Make.dep .depend
 
 -include Make.dep
+
diff --git a/nuttapp/Makefile b/nuttapp/Makefile
new file mode 100644
index 0000000..0922360
--- /dev/null
+++ b/nuttapp/Makefile
@@ -0,0 +1,95 @@
+############################################################################
+# apps/nshlib/Makefile
+#
+#   Copyright (C) 2011 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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 NuttX 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 COPYRIGHT HOLDERS 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
+# COPYRIGHT OWNER 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.
+#
+############################################################################
+
+-include $(TOPDIR)/.config
+-include $(TOPDIR)/Make.defs
+include $(APPDIR)/Make.defs
+
+# NSH Library
+
+# Source and object files
+
+ASRCS		=
+CSRCS		= exec_nuttapp.c
+
+AOBJS		= $(ASRCS:.S=$(OBJEXT))
+COBJS		= $(CSRCS:.c=$(OBJEXT))
+
+SRCS		= $(ASRCS) $(CSRCS)
+OBJS		= $(AOBJS) $(COBJS)
+
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
+
+ROOTDEPPATH	= --dep-path .
+VPATH		= 
+
+# Build Targets
+
+all:	.built
+.PHONY: depend .depend clean distclean
+
+$(AOBJS): %$(OBJEXT): %.S
+	$(call ASSEMBLE, $<, $@)
+
+$(COBJS): %$(OBJEXT): %.c
+	$(call COMPILE, $<, $@)
+
+$(BIN):	$(OBJS)
+	@( for obj in $(OBJS) ; do \
+		$(call ARCHIVE, $@, $${obj}); \
+	done ; )
+	@touch .built
+	
+.built: $(BIN)
+
+.depend: Makefile $(SRCS)
+	@echo "/* List of application requirements, generated during make depend. */" > exec_nuttapp_list.h
+	@echo "/* List of application entry points, generated during make depend. */" > exec_nuttapp_proto.h
+	@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+	@touch $@
+
+depend: .depend
+
+clean:
+	@rm -f *.o *~ .*.swp .built
+	$(call CLEAN)
+
+distclean: clean
+	@rm -f Make.dep .depend
+	@rm -f exec_nuttapp_list.h
+	@rm -f exec_nuttapp_proto.h
+
+-include Make.dep
+
diff --git a/exec_nuttapp.c b/nuttapp/exec_nuttapp.c
similarity index 100%
rename from exec_nuttapp.c
rename to nuttapp/exec_nuttapp.c
diff --git a/vsn/Makefile b/vsn/Makefile
index 29b4f1b..b3fed59 100644
--- a/vsn/Makefile
+++ b/vsn/Makefile
@@ -33,6 +33,8 @@
 #
 ############################################################################
 
+-include $(TOPDIR)/.config	# Current configuration
+
 # Sub-directories
 
 SUBDIRS = free hello poweroff ramtron sdcard
@@ -42,17 +44,20 @@
 
 nothing:
 
-define DOMAKE
-	@(MAKE) -C $1 $2 TOPDIR="$(TOPDIR) APPDIR=$(APPDIR)"
-endef
-
 depend:
-	$(foreach DIR, $(SUBDIRS), $(eval $(call DOMAKE,$(DIR),depend)))
+	@for dir in $(SUBDIRS) ; do \
+		$(MAKE) -C $$dir depend TOPDIR="$(TOPDIR)" APPDIR=$(APPDIR); \
+	done
 
 clean:
-	$(foreach DIR, $(SUBDIRS), $(eval $(call DOMAKE,$(DIR),clean)))
+	@for dir in $(SUBDIRS) ; do \
+		$(MAKE) -C $$dir clean TOPDIR="$(TOPDIR)" APPDIR=$(APPDIR); \
+	done
 
 distclean: clean
-	$(foreach DIR, $(SUBDIRS), $(eval $(call DOMAKE,$(DIR),distclean)))
+	@for dir in $(SUBDIRS) ; do \
+		$(MAKE) -C $$dir distclean TOPDIR="$(TOPDIR)" APPDIR=$(APPDIR); \
+	done
 
 -include Make.dep
+
diff --git a/vsn/free/Makefile b/vsn/free/Makefile
index 421544f..01545d0 100644
--- a/vsn/free/Makefile
+++ b/vsn/free/Makefile
@@ -61,7 +61,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -95,7 +95,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/vsn/hello/Makefile b/vsn/hello/Makefile
index 3f4115e..45f60e9 100644
--- a/vsn/hello/Makefile
+++ b/vsn/hello/Makefile
@@ -61,7 +61,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -95,7 +95,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/vsn/poweroff/Makefile b/vsn/poweroff/Makefile
index 80bde85..d4fc2ed 100644
--- a/vsn/poweroff/Makefile
+++ b/vsn/poweroff/Makefile
@@ -61,7 +61,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -95,7 +95,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/vsn/ramtron/Makefile b/vsn/ramtron/Makefile
index 5803f1f..c9aeae6 100644
--- a/vsn/ramtron/Makefile
+++ b/vsn/ramtron/Makefile
@@ -61,7 +61,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -95,7 +95,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean
diff --git a/vsn/sdcard/Makefile b/vsn/sdcard/Makefile
index b19ebde..ea0f51f 100644
--- a/vsn/sdcard/Makefile
+++ b/vsn/sdcard/Makefile
@@ -61,7 +61,7 @@
 SRCS		= $(ASRCS) $(CSRCS)
 OBJS		= $(AOBJS) $(COBJS)
 
-BIN	    	= ../../libapps$(LIBEXT)
+BIN	    	= $(APPDIR)/libapps$(LIBEXT)
 
 ROOTDEPPATH	= --dep-path .
 
@@ -95,7 +95,7 @@
 depend: .depend
 
 clean:
-	@rm -f $(BIN) *.o *~ .*.swp .built
+	@rm -f *.o *~ .*.swp .built
 	$(call CLEAN)
 
 distclean: clean