Index: Makefile
===================================================================
--- Makefile	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ Makefile	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -110,5 +110,5 @@
 	@$(MAKE) -C $@ $(MAKECMDGOALS)
 
-$(objects): %.o: %.c
+$(objects): %.o: $(SRCDIR)%.c
 	@echo '*' Compiling $<
 	@$(CC) -c $(CFLAGS) $< -o $@
Index: bitlbee.h
===================================================================
--- bitlbee.h	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ bitlbee.h	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -43,5 +43,5 @@
 
 #if HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
Index: configure
===================================================================
--- configure	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ configure	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -124,4 +124,26 @@
 EOF
 
+srcdir="$(dirname $0)"
+if [ "$srcdir" != "." ]; then
+	echo
+	echo "configure script run from a different directory. Will create some symlinks..."
+	if [ ! -e Makefile -o -L Makefile ]; then
+		mkdir -p $(cd "$srcdir"; find . -type d)
+		find . -name Makefile -type l -print0 | xargs -0 rm 2> /dev/null
+		dst="$PWD"
+		cd "$srcdir"
+		for i in $(find . -name Makefile); do
+			ln -s "$PWD${i#.}" "$dst/$i";
+		done
+		cd "$dst"
+		rm -rf .bzr
+	fi
+	
+	echo "SRCDIR=$srcdir/" >> Makefile.settings
+	CFLAGS="$CFLAGS -I${dst}"
+else
+	srcdir=$PWD
+fi
+
 cat<<EOF>config.h
 /* BitlBee settings, generated by configure
@@ -161,5 +183,5 @@
 
 echo CFLAGS=$CFLAGS >> Makefile.settings
-echo CFLAGS+=-I`pwd` -I`pwd`/lib -I`pwd`/protocols -I. >> Makefile.settings
+echo CFLAGS+=-I${srcdir} -I${srcdir}/lib -I${srcdir}/protocols -I. >> Makefile.settings
 
 echo CFLAGS+=-DHAVE_CONFIG_H >> Makefile.settings
Index: doc/Makefile
===================================================================
--- doc/Makefile	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ doc/Makefile	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -1,3 +1,6 @@
 -include ../Makefile.settings
+ifdef SRCDIR
+SRCDIR := $(SRCDIR)doc/
+endif
 
 all:
Index: doc/user-guide/Makefile
===================================================================
--- doc/user-guide/Makefile	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ doc/user-guide/Makefile	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -1,3 +1,7 @@
 -include ../../Makefile.settings
+ifdef SRCDIR
+SRCDIR := $(SRCDIR)doc/user-guide/
+endif
+
 EXTRAPARANEWLINE = 1
 # EXTRAPARANEWLINE = 0
Index: lib/Makefile
===================================================================
--- lib/Makefile	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ lib/Makefile	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -8,4 +8,7 @@
 
 -include ../Makefile.settings
+ifdef SRCDIR
+SRCDIR := $(SRCDIR)lib/
+endif
 
 # [SH] Program variables
@@ -37,5 +40,5 @@
 $(objects): ../Makefile.settings Makefile
 
-$(objects): %.o: %.c
+$(objects): %.o: $(SRCDIR)%.c
 	@echo '*' Compiling $<
 	@$(CC) -c $(CFLAGS) $< -o $@
Index: protocols/Makefile
===================================================================
--- protocols/Makefile	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ protocols/Makefile	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -8,4 +8,7 @@
 
 -include ../Makefile.settings
+ifdef SRCDIR
+SRCDIR := $(SRCDIR)protocols/
+endif
 
 # [SH] Program variables
@@ -49,5 +52,5 @@
 $(objects): ../Makefile.settings Makefile
 
-$(objects): %.o: %.c
+$(objects): %.o: $(SRCDIR)%.c
 	@echo '*' Compiling $<
 	@$(CC) -c $(CFLAGS) $< -o $@
Index: protocols/jabber/Makefile
===================================================================
--- protocols/jabber/Makefile	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ protocols/jabber/Makefile	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -8,4 +8,7 @@
 
 -include ../../Makefile.settings
+ifdef SRCDIR
+SRCDIR := $(SRCDIR)protocols/jabber/
+endif
 
 # [SH] Program variables
@@ -33,5 +36,5 @@
 $(objects): ../../Makefile.settings Makefile
 
-$(objects): %.o: %.c
+$(objects): %.o: $(SRCDIR)%.c
 	@echo '*' Compiling $<
 	@$(CC) -c $(CFLAGS) $< -o $@
Index: protocols/msn/Makefile
===================================================================
--- protocols/msn/Makefile	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ protocols/msn/Makefile	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -8,4 +8,7 @@
 
 -include ../../Makefile.settings
+ifdef SRCDIR
+SRCDIR := $(SRCDIR)protocols/msn/
+endif
 
 # [SH] Program variables
@@ -33,5 +36,5 @@
 $(objects): ../../Makefile.settings Makefile
 
-$(objects): %.o: %.c
+$(objects): %.o: $(SRCDIR)%.c
 	@echo '*' Compiling $<
 	@$(CC) -c $(CFLAGS) $< -o $@
Index: protocols/oscar/Makefile
===================================================================
--- protocols/oscar/Makefile	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ protocols/oscar/Makefile	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -8,4 +8,8 @@
 
 -include ../../Makefile.settings
+ifdef SRCDIR
+SRCDIR := $(SRCDIR)protocols/oscar/
+CFLAGS += -I$(SRCDIR)
+endif
 
 # [SH] Program variables
@@ -33,5 +37,5 @@
 $(objects): ../../Makefile.settings Makefile
 
-$(objects): %.o: %.c
+$(objects): %.o: $(SRCDIR)%.c
 	@echo '*' Compiling $<
 	@$(CC) -c $(CFLAGS) $< -o $@
Index: protocols/purple/Makefile
===================================================================
--- protocols/purple/Makefile	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ protocols/purple/Makefile	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -8,4 +8,7 @@
 
 -include ../../Makefile.settings
+ifdef SRCDIR
+SRCDIR := $(SRCDIR)protocols/purple/
+endif
 
 # [SH] Program variables
@@ -33,5 +36,5 @@
 $(objects): ../../Makefile.settings Makefile
 
-$(objects): %.o: %.c
+$(objects): %.o: $(SRCDIR)%.c
 	@echo '*' Compiling $<
 	@$(CC) -c $(CFLAGS) $< -o $@
Index: protocols/twitter/Makefile
===================================================================
--- protocols/twitter/Makefile	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ protocols/twitter/Makefile	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -8,4 +8,7 @@
 
 -include ../../Makefile.settings
+ifdef SRCDIR
+SRCDIR := $(SRCDIR)protocols/twitter/
+endif
 
 # [SH] Program variables
@@ -33,5 +36,5 @@
 $(objects): ../../Makefile.settings Makefile
 
-$(objects): %.o: %.c
+$(objects): %.o: $(SRCDIR)%.c
 	@echo '*' Compiling $<
 	@$(CC) -c $(CFLAGS) $< -o $@
Index: protocols/yahoo/Makefile
===================================================================
--- protocols/yahoo/Makefile	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ protocols/yahoo/Makefile	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -8,4 +8,7 @@
 
 -include ../../Makefile.settings
+ifdef SRCDIR
+SRCDIR := $(SRCDIR)protocols/yahoo/
+endif
 
 # [SH] Program variables
@@ -33,5 +36,5 @@
 $(objects): ../../Makefile.settings Makefile
 
-$(objects): %.o: %.c
+$(objects): %.o: $(SRCDIR)%.c
 	@echo '*' Compiling $<
 	@$(CC) -c $(CFLAGS) $< -o $@
Index: tests/Makefile
===================================================================
--- tests/Makefile	(revision 51a799ef9c2a144bf3edc58130bfc1e275cdd53f)
+++ tests/Makefile	(revision f60079b74053a53da3720b992c603fddf75ff1dd)
@@ -1,3 +1,6 @@
 -include ../Makefile.settings
+ifdef SRCDIR
+SRCDIR := $(SRCDIR)tests/
+endif
 
 LFLAGS +=-lcheck
@@ -19,5 +22,5 @@
 	@$(CC) $(CFLAGS) -o $@ $^ $(LFLAGS) $(EFLAGS)
 
-%.o: %.c
+%.o: $(SRCDIR)%.c
 	@echo '*' Compiling $<
 	@$(CC) -c $(CFLAGS) $< -o $@
