New loading scheme for Winelib apps, makes them behave like builtin
dlls and takes load order into account. Install them in dlldir.
Improved MODULE_GetBinaryType to recognize ELF binaries.
Added a wrapper script to setup the environment when running directly
from inside the source tree.

diff --git a/programs/Makefile.in b/programs/Makefile.in
index 76fe18e..acaccfe 100644
--- a/programs/Makefile.in
+++ b/programs/Makefile.in
@@ -4,54 +4,106 @@
 VPATH     = @srcdir@
 MODULE    = none
 
-INSTALLSUBDIRS = \
+SUBDIRS = \
+	$(TOPOBJDIR)/debugger \
+	avitools \
+	clock \
+	cmdlgtst \
 	control \
 	expand \
 	notepad \
+	osversioncheck \
+	progman \
+	regapi \
+	regedit \
+	regsvr32 \
+	regtest \
+	uninstaller \
+	view \
+	wcmd \
+	wineconsole \
+	winemine \
+	winepath \
+	winetest \
+	winhelp \
+	winver
+
+# Programs to install in bin directory
+# We don't install everything to avoid polluting /usr/bin too much
+INSTALLPROGS = \
+	expand \
+	notepad \
 	progman \
 	regedit \
 	regsvr32 \
 	uninstaller \
 	wcmd \
 	wineconsole \
+	winedbg \
 	winemine \
 	winepath \
-	winhelp \
-	winver
+	winhelp
 
-# Programs that are not generally useful and don't get installed
-# Use 'make everything' to build them
-OTHERSUBDIRS = \
-	avitools \
-	clock \
-	cmdlgtst \
-	osversioncheck \
-	regapi \
-	regtest \
-	view \
-	winetest
-
-SUBDIRS = $(INSTALLSUBDIRS) $(OTHERSUBDIRS)
-
-all: $(INSTALLSUBDIRS)
+# Symlinks to apps that we want to run from inside the source tree
+SYMLINKS = \
+	wineconsole.exe \
+	winedbg.exe \
+	winetest.exe
 
 @MAKE_RULES@
 
-everything: $(SUBDIRS)
+all: wineapploader $(SUBDIRS) $(SYMLINKS:%=%$(DLLEXT))
 
-install-everything: $(SUBDIRS:%=%/__install__)
+wineapploader: wineapploader.in
+	sed -e 's,@bindir\@,$(bindir),g' $(SRCDIR)/wineapploader.in >$@ || $(RM) $@
 
-uninstall-everything: $(SUBDIRS:%=%/__uninstall__)
+# Rules for installation
 
-install:: $(INSTALLSUBDIRS:%=%/__install__)
+.PHONY: install-apploader install-progs install-progs.so $(INSTALLPROGS:%=%/__installprog__)
 
-uninstall:: $(INSTALLSUBDIRS:%=%/__uninstall__)
+install-apploader: wineapploader dummy
+	$(MKINSTALLDIRS) $(bindir)
+	$(INSTALL_SCRIPT) wineapploader $(bindir)/wineapploader
+
+$(INSTALLPROGS:%=%/__installprog__): install-apploader
+	$(RM) $(bindir)/`dirname $@` && $(LN) $(bindir)/wineapploader $(bindir)/`dirname $@`
+
+install-progs.so: $(INSTALLPROGS:%=%/__installprog__)
+	$(RM) $(bindir)/wineapploader
+
+install-progs: # nothing to do here
+
+install:: $(SUBDIRS:%=%/__install__) install-progs$(DLLEXT)
+
+uninstall:: $(SUBDIRS:%=%/__uninstall__)
+	$(RM) $(bindir)/wineapploader $(INSTALLPROGS:%=$(bindir)/%)
+	-rmdir $(dlldir)
+
+clean::
+	$(RM) wineapploader $(SYMLINKS)
+
+# Rules for testing
 
 $(SUBDIRS:%=%/__checklink__): dummy
 	@cd `dirname $@` && $(MAKE) checklink
 
+checklink:: $(SUBDIRS:%=%/__checklink__)
+
 check test:: $(SUBDIRS:%=%/__test__)
 
-checklink:: $(SUBDIRS:%=%/__checklink__)
+# Rules for symlinks
+
+wineconsole.exe$(DLLEXT): wineconsole/wineconsole.exe$(DLLEXT)
+	$(RM) $@ && $(LN_S) wineconsole/wineconsole.exe$(DLLEXT) $@
+
+winedbg.exe$(DLLEXT): $(TOPOBJDIR)/debugger/winedbg.exe$(DLLEXT)
+	$(RM) $@ && $(LN_S) $(TOPOBJDIR)/debugger/winedbg.exe$(DLLEXT) $@
+
+winetest.exe$(DLLEXT): winetest/winetest.exe$(DLLEXT)
+	$(RM) $@ && $(LN_S) winetest/winetest.exe$(DLLEXT) $@
+
+wineconsole/wineconsole.exe$(DLLEXT): wineconsole
+$(TOPOBJDIR)/debugger/winedbg.exe$(DLLEXT): $(TOPOBJDIR)/debugger
+winetest/winetest.exe$(DLLEXT): winetest
 
 ### Dependencies: