diff --git a/Makefile.in b/Makefile.in
index de01affeb5b9b5d2484945ba3249d5537bc72496..fcaa6f2b041417e291117754d32581554203b0dc 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -10,18 +10,17 @@
 # This makefile is quite evil.
 
 ifndef PROGRAMS
-	PROGRAMS="dropbear dbclient dropbearkey dropbearmulti"
+	PROGRAMS=dropbear dbclient dropbearkey dropbearmulti
 endif
 
 LTC=libtomcrypt/libtomcrypt.a
 LTM=libtommath/libtommath.a
 
-COMMONOBJS=dbutil.o common-session.o packet.o common-algo.o buffer.o \
-		common-kex.o dss.o bignum.o \
-		signkey.o rsa.o random.o common-channel.o \
-		common-chansession.o queue.o termcodes.o  \
-		loginrec.o atomicio.o tcpfwd-direct.o compat.o \
-		tcpfwd-remote.o listener.o process-packet.o common-runopts.o
+COMMONOBJS=dbutil.o buffer.o \
+		dss.o bignum.o \
+		signkey.o rsa.o random.o \
+		queue.o \
+		atomicio.o compat.o 
 
 SVROBJS=svr-kex.o svr-algo.o svr-auth.o sshpty.o \
 		svr-authpasswd.o svr-authpubkey.o svr-session.o svr-service.o \
@@ -30,9 +29,12 @@ SVROBJS=svr-kex.o svr-algo.o svr-auth.o sshpty.o \
 CLIOBJS=cli-algo.o cli-main.o cli-auth.o cli-authpasswd.o cli-kex.o \
 		cli-session.o cli-service.o
 
-DROPBEAROBJS=
+CLISVROBJS=common-session.o packet.o common-algo.o common-kex.o \
+			common-channel.o common-chansession.o termcodes.o loginrec.o \
+			tcpfwd-direct.o tcpfwd-remote.o listener.o process-packet.o \
+			common-runopts.o
 
-DROPBEARKEYOBJS=dropbearkey.o gendss.o genrsa.o
+KEYOBJS=dropbearkey.o gendss.o genrsa.o
 
 CONVERTOBJS=dropbearconvert.o keyimport.o
 
@@ -45,8 +47,8 @@ HEADERS=options.h dbutil.h session.h packet.h algo.h ssh.h buffer.h kex.h \
 		loginrec.h atomicio.h x11fwd.h agentfwd.h tcpfwd-direct.h compat.h \
 		tcpfwd-remote.h listener.h
 
-dropbearobjs=$(COMMONOBJS) $(SVROBJS) 
-dbclientobjs=$(COMMONOBJS) $(CLIOBJS)
+dropbearobjs=$(COMMONOBJS) $(CLISVROBJS) $(SVROBJS) 
+dbclientobjs=$(COMMONOBJS) $(CLISVROBJS) $(CLIOBJS)
 dropbearkeyobjs=$(COMMONOBJS) $(KEYOBJS)
 dropbearconvertobjs=$(COMMONOBJS) $(CONVERTOBJS)
 scpobjs=$(SCPOBJS)
@@ -57,7 +59,7 @@ bindir=${exec_prefix}/bin
 sbindir=${exec_prefix}/sbin
 
 CC=@CC@
-LD=@CC@
+LD=@LD@
 AR=@AR@
 RANLIB=@RANLIB@
 STRIP=@STRIP@
@@ -69,17 +71,15 @@ LDFLAGS=@LDFLAGS@
 EXEEXT=@EXEEXT@
 
 # whether we're building client, server, or both for the common objects.
-space:= $(empty) $(empty)
-CLISVRFLAGS=
 # evilness so we detect 'dropbear' by itself as a word
-ifneq (,$(findstring $(space)dropbear$(space), $(space)$(PROGRAMS)$(space)))
-	CLISVRFLAGS+= -DDROPBEAR_SERVER
+space:= $(empty) $(empty)
+ifneq (,$(strip $(foreach prog, $(PROGRAMS), $(findstring ZdropbearZ, Z$(prog)Z))))
+	CFLAGS+= -DDROPBEAR_SERVER
 endif
-ifneq (,$(findstring $(space)dbclient$(space), $(space)$(PROGRAMS)$(space)))
-	CLISVRFLAGS+= -DDROPBEAR_CLIENT
+ifneq (,$(strip $(foreach prog, $(PROGRAMS), $(findstring ZdbclientZ, Z$(prog)Z))))
+	CFLAGS+= -DDROPBEAR_CLIENT
 endif
 
-CFLAGS+=$(CLISVRFLAGS)
 
 # these are exported so that libtomcrypt's makefile will use them
 export CC
@@ -108,12 +108,15 @@ endif
 #%: $(HEADERS) Makefile
 # TODO
 
+all: $(TARGETS)
 
-strip: $(TARGETS)
-	$(STRIP) $(foreach prog, $(TARGETS), $(SPREFIX)$(prog)$(EXEEXT))
+test:
+	 @echo Z$(sort $(foreach prog, $(PROGRAMS), $($(prog)objs)))Z
 
+strip: $(TARGETS)
+	$(STRIP) $(addsuffix $(EXEEXT), $(addprefix $(SPREFIX), $(TARGETS)))
 
-install: $(foreach prog, $(TARGETS), install$prog)
+install: $(addprefix install, $(TARGETS))
 
 # dropbear should go in sbin, so it needs a seperate rule
 installdropbear: dropbear
@@ -128,33 +131,39 @@ install%: $*
 	-chown root $(DESTDIR)$(sbindir)/$(SPREFIX)$*$(EXEEXT)
 	-chgrp 0 $(DESTDIR)$(sbindir)/$(SPREFIX)$*$(EXEEXT)
 	ifeq ($(MULTI), 1)
+		@echo 
 		@echo "You must manually create links for $*"
 	endif
 
 
 
-# The actual binaries
+# for some reason the rule further down doesn't like $($@objs) as a prereq.
 dropbear: $(dropbearobjs)
+dbclient: $(dbclientobjs)
+dropbearkey: $(dropbearkeyobjs)
+dropbearconvert: $(dropbearconvertobjs)
 
-dropbear dbclient dropbearkey dropbearconvert: $($($@objs)) $(HEADERS) \
-														$(LTC) $(LTM)
-	@echo $(CLISVRFLAGS)
+dropbear dbclient dropbearkey dropbearconvert: $(HEADERS)  $(LTC) $(LTM)
 	$(LD) $(LDFLAGS) -o $(SPREFIX)$@$(EXEEXT) $($@objs) $(LIBS)
 
-
 # scp doesn't use the libs so is special.
 scp: $(SCPOBJS)  $(HEADERS)
 	$(LD) $(LDFLAGS) -o $(SPREFIX)$@$(EXEEXT) $(SCPOBJS)
 
 
-MULTIOBJS=dbmulti.o
+# multi-binary compilation.
+MULTIOBJS=
 ifeq ($(MULTI),1)
-	deftarget=multi
-	MULTIOBJS=$(foreach prog, $(PROGRAMS), $($(prog)objs))
+	MULTIOBJS=dbmulti.o $(sort $(foreach prog, $(PROGRAMS), $($(prog)objs)))
+	CFLAGS+=$(addprefix -DDBMULTI_, $(PROGRAMS)) -DDROPBEAR_MULTI
 endif
 
+testfoo:
+	echo $(MULTIOBJS)
+
 dropbearmulti: $(HEADERS) $(MULTIOBJS) $(LTC) $(LTM)
 	$(LD) $(LDFLAGS) -o $(SPREFIX)$@$(EXEEXT) $(MULTIOBJS) $(LIBS)
+	@echo
 	@echo "You should now create symlinks to the programs you have included"
 	@echo "ie 'ln -s dropbearmulti dropbear'"
 
diff --git a/dbmulti.c b/dbmulti.c
index d82eff0861eb59b5f9584737a85e2d6ce873dfe0..8f39227c55d6eec6e554e1267c89363e840766c8 100644
--- a/dbmulti.c
+++ b/dbmulti.c
@@ -4,6 +4,7 @@
 int dropbear_main(int argc, char ** argv);
 int dropbearkey_main(int argc, char ** argv);
 int dropbearconvert_main(int argc, char ** argv);
+int scp_main(int argc, char ** argv);
 
 int main(int argc, char ** argv) {
 
@@ -13,33 +14,41 @@ int main(int argc, char ** argv) {
 		/* figure which form we're being called as */
 		progname = basename(argv[0]);
 
-#ifdef DBMULTI_DROPBEAR
+#ifdef DBMULTI_dropbear
 		if (strcmp(progname, "dropbear") == 0) {
 			return dropbear_main(argc, argv);
 		}
 #endif
-#ifdef DBMULTI_KEY
+#ifdef DBMULTI_dropbearkey
 		if (strcmp(progname, "dropbearkey") == 0) {
 			return dropbearkey_main(argc, argv);
 		}
 #endif
-#ifdef DBMULTI_CONVERT
+#ifdef DBMULTI_dropbearconvert
 		if (strcmp(progname, "dropbearconvert") == 0) {
 			return dropbearconvert_main(argc, argv);
 		}
+#endif
+#ifdef DBMULTI_scp
+		if (strcmp(progname, "scp") == 0) {
+			return scp_main(argc, argv);
+		}
 #endif
 	}
 
 	fprintf(stderr, "Dropbear multi-purpose version %s\n"
 			"Make a symlink pointing at this binary with one of the following names:\n"
-#ifdef DBMULTI_DROPBEAR
+#ifdef DBMULTI_dropbear
 			"'dropbear' - the Dropbear server\n"
 #endif
-#ifdef DBMULTI_KEY
+#ifdef DBMULTI_dropbearkey
 			"'dropbearkey' - the key generator\n"
 #endif
-#ifdef DBMULTI_CONVERT
+#ifdef DBMULTI_dropbearconvert
 			"'dropbearconvert' - the key converter\n"
+#endif
+#ifdef DBMULTI_scp
+			"'scp' - secure copy\n"
 #endif
 			,
 			DROPBEAR_VERSION);
diff --git a/dropbearconvert.c b/dropbearconvert.c
index 0929ba820bbb488dd86c756ca9d456e1e4303151..3ceccff2abf8aeaac4492f543c657cac3425adab 100644
--- a/dropbearconvert.c
+++ b/dropbearconvert.c
@@ -53,8 +53,8 @@ static void printhelp(char * progname) {
 					"standard input or standard output.\n", progname);
 }
 
-#if defined(DBMULTI_CONVERT) || !defined(DROPBEAR_MULTI)
-#if defined(DBMULTI_CONVERT) && defined(DROPBEAR_MULTI)
+#if defined(DBMULTI_dropbearconvert) || !defined(DROPBEAR_MULTI)
+#if defined(DBMULTI_dropbearconvert) && defined(DROPBEAR_MULTI)
 int dropbearconvert_main(int argc, char ** argv) {
 #else 
 int main(int argc, char ** argv) {
diff --git a/dropbearkey.c b/dropbearkey.c
index bc2b1aecea2ae6c1e17078847d8992899ea0ac2c..eac08231662d368211d87e0b7840446dae7d8328 100644
--- a/dropbearkey.c
+++ b/dropbearkey.c
@@ -80,8 +80,8 @@ static void printhelp(char * progname) {
 					progname);
 }
 
-#if defined(DBMULTI_KEY) || !defined(DROPBEAR_MULTI)
-#if defined(DBMULTI_KEY) && defined(DROPBEAR_MULTI)
+#if defined(DBMULTI_dropbearkey) || !defined(DROPBEAR_MULTI)
+#if defined(DBMULTI_dropbearkey) && defined(DROPBEAR_MULTI)
 int dropbearkey_main(int argc, char ** argv) {
 #else
 int main(int argc, char ** argv) {
diff --git a/main.c b/svr-main.c
similarity index 98%
rename from main.c
rename to svr-main.c
index 0ef1e62a54064df580c576f2e9a9c562dae8fe5a..312e47c7ba09e7e3c00b5035983944da94476732 100644
--- a/main.c
+++ b/svr-main.c
@@ -36,8 +36,8 @@ static void sigintterm_handler(int fish);
 
 static int childpipes[MAX_UNAUTH_CLIENTS];
 
-#if defined(DBMULTI_DROPBEAR) || !defined(DROPBEAR_MULTI)
-#if defined(DBMULTI_DROPBEAR) && defined(DROPBEAR_MULTI)
+#if defined(DBMULTI_dropbear) || !defined(DROPBEAR_MULTI)
+#if defined(DBMULTI_dropbear) && defined(DROPBEAR_MULTI)
 int dropbear_main(int argc, char ** argv)
 #else
 int main(int argc, char ** argv)