Index: src/date.cpp
===================================================================
--- src/date.cpp	(revision 12967)
+++ src/date.cpp	(working copy)
@@ -6,6 +6,7 @@
 #include "openttd.h"
 #include "variables.h"
 #include "settings_type.h"
+#include "vehicle_base.h"
 #include "network/network.h"
 #include "network/network_data.h"
 #include "network/network_server.h"
@@ -13,7 +14,6 @@
 #include "window_func.h"
 #include "functions.h"
 #include "date_func.h"
-#include "vehicle_base.h"
 #include "debug.h"
 #include "rail_gui.h"
 #ifdef DEBUG_DUMP_COMMANDS
Index: src/network/core/os_abstraction.h
===================================================================
--- src/network/core/os_abstraction.h	(revision 12967)
+++ src/network/core/os_abstraction.h	(working copy)
@@ -35,7 +35,7 @@
 #if defined(UNIX) && !defined(__OS2__)
 #	define SOCKET int
 #	define INVALID_SOCKET -1
-#	if !defined(__MORPHOS__) && !defined(__AMIGA__)
+#	if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(__DJGPP__)
 #		define ioctlsocket ioctl
 #	if !defined(BEOS_NET_SERVER)
 #		define closesocket close
@@ -48,6 +48,12 @@
 /* Includes needed for UNIX-like systems */
 #	include <unistd.h>
 #	include <sys/ioctl.h>
+
+#	if defined(__DJGPP__)
+#		define ioctl(x, y, z) ioctlsocket(x, y, (char *) z)
+#		define GET_LAST_ERROR() (errno)
+#	endif
+
 #	if defined(__BEOS__) && defined(BEOS_NET_SERVER)
 #		include <be/net/socket.h>
 #		include <be/kernel/OS.h> // snooze()
@@ -61,7 +67,7 @@
 #		include <arpa/inet.h>
 #		include <net/if.h>
 /* According to glibc/NEWS, <ifaddrs.h> appeared in glibc-2.3. */
-#		if !defined(__sgi__) && !defined(SUNOS) && !defined(__MORPHOS__) && !defined(__BEOS__) && !defined(__INNOTEK_LIBC__) \
+#		if !defined(__sgi__) && !defined(SUNOS) && !defined(__MORPHOS__) && !defined(__BEOS__) && !defined(__INNOTEK_LIBC__) && !defined(__DJGPP__) \
 		   && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) && !defined(HPUX)
 /* If for any reason ifaddrs.h does not exist on your system, comment out
  *   the following two lines and an alternative way will be used to fetch
@@ -78,7 +84,7 @@
 #		endif
 #	endif /* BEOS_NET_SERVER */
 
-#	if !defined(__BEOS__) && defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 1)
+#	if defined(__DJGPP) || (!defined(__BEOS__) && defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 1))
 		typedef uint32_t in_addr_t;
 #	endif
 
@@ -87,7 +93,7 @@
 #	include <netdb.h>
 #endif // UNIX
 
-#ifdef __BEOS__
+#if defined(__BEOS__) || defined(__DJGPP__)
 	typedef int socklen_t;
 #endif
 
@@ -181,8 +187,12 @@
 #ifdef WIN32
 	u_long nonblocking = 1;
 #else
+#ifdef __DJGPP__
+	char nonblocking = 1;
+#else
 	int nonblocking = 1;
 #endif
+#endif
 #if (defined(__BEOS__) && defined(BEOS_NET_SERVER)) || defined(PSP)
 	return setsockopt(d, SOL_SOCKET, SO_NONBLOCK, &nonblocking, sizeof(nonblocking)) == 0;
 #else
Index: src/network/network_server.cpp
===================================================================
--- src/network/network_server.cpp	(revision 12967)
+++ src/network/network_server.cpp	(working copy)
@@ -6,13 +6,9 @@
 #include "../openttd.h" // XXX StringID
 #include "../debug.h"
 #include "../strings_func.h"
-#include "network_data.h"
-#include "core/tcp.h"
 #include "../vehicle_base.h"
 #include "../vehicle_func.h"
 #include "../date_func.h"
-#include "network_server.h"
-#include "network_udp.h"
 #include "../console.h"
 #include "../command_func.h"
 #include "../saveload.h"
@@ -26,6 +22,10 @@
 #include "../player_func.h"
 #include "../player_gui.h"
 #include "../settings_type.h"
+#include "network_data.h"
+#include "core/tcp.h"
+#include "network_server.h"
+#include "network_udp.h"
 
 #include "table/strings.h"
 
Index: src/network/network_client.cpp
===================================================================
--- src/network/network_client.cpp	(revision 12967)
+++ src/network/network_client.cpp	(working copy)
@@ -5,11 +5,6 @@
 #include "../stdafx.h"
 #include "../debug.h"
 #include "../openttd.h"
-#include "network_data.h"
-#include "core/tcp.h"
-#include "network_client.h"
-#include "network_gamelist.h"
-#include "network_gui.h"
 #include "../saveload.h"
 #include "../command_func.h"
 #include "../console.h"
@@ -26,6 +21,12 @@
 #include "../player_gui.h"
 #include "../rev.h"
 
+#include "network_data.h"
+#include "core/tcp.h"
+#include "network_client.h"
+#include "network_gamelist.h"
+#include "network_gui.h"
+
 #include "table/strings.h"
 
 // This file handles all the client-commands
Index: src/network/network.cpp
===================================================================
--- src/network/network.cpp	(revision 12967)
+++ src/network/network.cpp	(working copy)
@@ -1,7 +1,6 @@
 /* $Id$ */
 
 #include "../stdafx.h"
-#include "network_data.h"
 
 #ifdef ENABLE_NETWORK
 
@@ -13,14 +12,6 @@
 #include "../variables.h"
 #include "../date_func.h"
 #include "../newgrf_config.h"
-#include "network_client.h"
-#include "network_server.h"
-#include "network_udp.h"
-#include "network_gamelist.h"
-#include "core/udp.h"
-#include "core/tcp.h"
-#include "core/core.h"
-#include "network_gui.h"
 #include "../console.h" /* IConsoleCmdExec */
 #include <stdarg.h> /* va_list */
 #include "../md5.h"
@@ -32,6 +23,17 @@
 #include "../player_func.h"
 #include "../settings_type.h"
 #include "../rev.h"
+
+#include "network_data.h"
+#include "network_client.h"
+#include "network_server.h"
+#include "network_udp.h"
+#include "network_gamelist.h"
+#include "core/udp.h"
+#include "core/tcp.h"
+#include "core/core.h"
+#include "network_gui.h"
+
 #ifdef DEBUG_DUMP_COMMANDS
 	#include "../core/alloc_func.hpp"
 #endif /* DEBUG_DUMP_COMMANDS */
@@ -478,7 +480,7 @@
 	}
 #else
 	ifconf.ifc_len = sizeof(buf);
-	ifconf.ifc_buf = buf;
+	ifconf.ifc_buf = (caddr_t) buf;
 	if (ioctl(sock, SIOCGIFCONF, &ifconf) == -1) {
 		closesocket(sock);
 		return;
@@ -503,7 +505,7 @@
 		}
 
 		p += sizeof(struct ifreq);
-#if defined(AF_LINK) && !defined(SUNOS)
+#if defined(AF_LINK) && !defined(SUNOS) && !defined(__DJGPP__)
 		p += req->ifr_addr.sa_len - sizeof(struct sockaddr);
 #endif
 	}
Index: src/stdafx.h
===================================================================
--- src/stdafx.h	(revision 12967)
+++ src/stdafx.h	(working copy)
@@ -260,7 +260,7 @@
 typedef unsigned char byte;
 
 /* This is already defined in unix, but not in QNX Neutrino (6.x)*/
-#if (!defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) && !defined(__MORPHOS__)) || defined(__QNXNTO__)
+#if (!defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) && !defined(__MORPHOS__)) || defined(__QNXNTO__) || defined(__DJGPP__)
 	typedef unsigned int uint;
 #endif
 
@@ -312,7 +312,7 @@
 void NORETURN CDECL error(const char *str, ...);
 #define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
 
-#if defined(MORPHOS) || defined(__NDS__)
+#if defined(MORPHOS) || defined(__NDS__) || defined(__DJGPP__)
 	/* MorphOS and NDS don't have C++ conformant _stricmp... */
 	#define _stricmp stricmp
 #elif defined(OPENBSD)
@@ -320,7 +320,8 @@
 	#define _stricmp strcasecmp
 #endif
 
-#if !defined(MORPHOS) && !defined(OPENBSD) && !defined(__NDS__)
+// TODO: DJGPP should know wchar, maybe?
+#if !defined(MORPHOS) && !defined(OPENBSD) && !defined(__NDS__) && !defined(__DJGPP__)
 	/* NDS, MorphOS & OpenBSD don't know wchars, the rest does :( */
 	#define HAS_WCHAR
 #endif /* !defined(MORPHOS) && !defined(OPENBSD) && !defined(__NDS__) */
@@ -329,6 +330,12 @@
 	#define MAX_PATH 260
 #endif
 
+#ifdef __DJGPP__
+	#include <glib.h>
+	#define snprintf		g_snprintf
+	#define vsnprintf		g_vsnprintf
+#endif
+
 /**
  * The largest value that can be entered in a variable
  * @param type the type of the variable
Index: Makefile.src.in
===================================================================
--- Makefile.src.in	(revision 12967)
+++ Makefile.src.in	(working copy)
@@ -246,6 +246,7 @@
 ifeq ($(GCC295), 1)
 	$(Q)$(CXX_HOST) -E $(CFLAGS) $< | $(GCC295_FIX) | $(GCC295_FIX_2) | $(CXX_HOST) $(CFLAGS) -c -o $@ -x c++ -
 else
+	$(E) '$(Q)$(CXX_HOST) $(CFLAGS) -c -o $@ $<'
 	$(Q)$(CXX_HOST) $(CFLAGS) -c -o $@ $<
 endif
 
@@ -268,6 +269,7 @@
 	#  CC to link OpenTTD for PSP
 	$(Q)$(CC_HOST) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
 else
+	$(E) $(Q)$(CXX_HOST) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
 	$(Q)$(CXX_HOST) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
 endif
 ifdef STRIP
Index: config.lib
===================================================================
--- config.lib	(revision 12967)
+++ config.lib	(working copy)
@@ -60,6 +60,7 @@
 	with_midi_arg=""
 	with_libtimidity="1"
 	with_freetype="1"
+	with_alleg="1"
 	with_fontconfig="1"
 	with_psp_config="1"
 	with_threads="1"
@@ -106,6 +107,7 @@
 		with_osx_sysroot
 		with_application_bundle
 		with_sdl
+		with_alleg
 		with_cocoa
 		with_zlib
 		with_png
@@ -247,6 +249,10 @@
 			--without-sdl)                with_sdl="0";;
 			--with-sdl=*)                 with_sdl="$optarg";;
 
+			--with-alleg)                 with_alleg="2";;
+			--without-alleg)              with_alleg="0";;
+			--with-alleg=*)               with_alleg="$optarg";;
+
 			--with-cocoa)                 with_cocoa="2";;
 			--without-cocoa)              with_cocoa="0";;
 			--with-cocoa=*)               with_cocoa="$optarg";;
@@ -392,9 +398,9 @@
 		exit 1
 	fi
 	# OS only allows DETECT, UNIX, OSX, FREEBSD, OPENBSD, MORPHOS, BEOS, SUNOS, CYGWIN, MINGW, OS2, WINCE, and PSP
-	if [ -z "`echo $os | egrep '^(DETECT|UNIX|OSX|FREEBSD|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|SUNOS|CYGWIN|MINGW|OS2|WINCE|PSP)$'`" ]; then
+	if [ -z "`echo $os | egrep '^(DETECT|UNIX|OSX|FREEBSD|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|SUNOS|CYGWIN|MINGW|OS2|WINCE|PSP|DJGPP)$'`" ]; then
 		echo "configure: error: invalid option --os=$os"
-		echo " Available options are: --os=[DETECT|UNIX|OSX|FREEBSD|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|SUNOS|CYGWIN|MINGW|OS2|WINCE|PSP]"
+		echo " Available options are: --os=[DETECT|UNIX|OSX|FREEBSD|OPENBSD|NETBSD|HPUX|MORPHOS|BEOS|SUNOS|CYGWIN|MINGW|OS2|WINCE|PSP|DJGPP]"
 		exit 1
 	fi
 	# cpu_type can be either 32 or 64
@@ -511,6 +517,7 @@
 	fi
 
 	detect_sdl
+	detect_alleg
 	detect_cocoa
 
 	if [ "$enable_dedicated" != "0" ]; then
@@ -528,7 +535,7 @@
 			log 1 "checking GDI video driver... not Windows, skipping"
 		fi
 
-		if [ -z "$sdl_config" ] && [ "$with_cocoa" = 0 ] && [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
+		if [ -z "$sdl_config" ] && [ "$with_alleg" = 0 ] && [ "$with_cocoa" = 0 ] && [ "$os" != "MINGW" ] && [ "$os" != "CYGWIN" ] && [ "$os" != "WINCE" ]; then
 			log 1 "WARNING: no video driver found, building dedicated only"
 			enable_dedicated="1"
 			sleep 1
@@ -972,12 +979,12 @@
 		fi
 	fi
 
-	if [ "$os" != "CYGWIN" ] && [ "$os" != "FREEBSD" ] && [ "$os" != "OPENBSD" ] && [ "$os" != "MINGW" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "OSX" ] && [ "$os" != "WINCE" ] && [ "$os" != "PSP" ] && [ "$os" != "OS2" ]; then
+	if [ "$os" != "CYGWIN" ] && [ "$os" != "FREEBSD" ] && [ "$os" != "OPENBSD" ] && [ "$os" != "MINGW" ] && [ "$os" != "MORPHOS" ] && [ "$os" != "OSX" ] && [ "$os" != "WINCE" ] && [ "$os" != "PSP" ] && [ "$os" != "OS2" ] && [ "$os" != "DJGPP" ]; then
 		LIBS="$LIBS -lpthread"
 		LIBS="$LIBS -lrt"
 	fi
 
-	if [ "$os" != "CYGWIN" ] && [ "$os" != "MINGW" ] && [ "$os" != "WINCE" ]; then
+	if [ "$os" != "CYGWIN" ] && [ "$os" != "MINGW" ] && [ "$os" != "WINCE" ] && [ "$os" != "DJGPP" ]; then
 		LIBS="$LIBS -lc"
 	fi
 	if [ "$os" = "WINCE" ]; then
@@ -1015,8 +1022,12 @@
 		LIBS="$LIBS -lmidi -lbe"
 	fi
 
+	if [ "$os" = "DJGPP" ]; then
+		LIBS="$LIBS -lglib"
+	fi
+
 	# Most targets act like UNIX, just with some additions
-	if [ "$os" = "BEOS" ] || [ "$os" = "OSX" ] || [ "$os" = "MORPHOS" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ] || [ "$os" = "OS2" ]; then
+	if [ "$os" = "BEOS" ] || [ "$os" = "OSX" ] || [ "$os" = "MORPHOS" ] || [ "$os" = "FREEBSD" ] || [ "$os" = "OPENBSD" ] || [ "$os" = "NETBSD" ] || [ "$os" = "HPUX" ] || [ "$os" = "SUNOS" ] || [ "$os" = "OS2" ] || [ "$os" = "DJGPP" ]; then
 		CFLAGS="$CFLAGS -DUNIX"
 	fi
 	# And others like Windows
@@ -1036,6 +1047,15 @@
 		fi
 	fi
 
+	if [ "$with_alleg" != "0" ]; then
+		if [ "$enable_static" != "0" ] && [ "$os" != "OSX" ]; then
+			LIBS="$LIBS $alleg"
+		else
+			LIBS="$LIBS -lalleg"
+		fi
+		CFLAGS="$CFLAGS -DWITH_ALLEGRO"
+	fi
+		
 	if [ "$with_cocoa" != "0" ]; then
 		CFLAGS="$CFLAGS -DWITH_COCOA"
 		LIBS="$LIBS -F/System/Library/Frameworks -framework Cocoa -framework Carbon -framework AudioUnit"
@@ -1164,6 +1184,10 @@
 		if [ "$os" = "SUNOS" ]; then
 			LDFLAGS="$LDFLAGS -lnsl -lsocket"
 		fi
+
+		if [ "$os" = "DJGPP" ]; then
+			LIBS="$LIBS -lwatt"
+		fi
 	fi
 
 	if [ "$enable_static" != "0" ]; then
@@ -1543,6 +1567,7 @@
 					/os2/          { print "OS2";     exit}
 					/wince/        { print "WINCE";   exit}
 					/psp/          { print "PSP";     exit}
+					/djgpp/        { print "DJGPP";   exit}
 		'`
 
 		if [ -z "$os" ]; then
@@ -1559,13 +1584,14 @@
 					/cygwin/       { print "CYGWIN";  exit}
 					/mingw/        { print "MINGW";   exit}
 					/os\/2/        { print "OS2";     exit}
+					/djgpp/        { print "DJGPP";   exit}
 			'`
 		fi
 
 		if [ -z "$os" ]; then
 			log 1 "detecting OS... none detected"
 			log 1 "I couldn't detect your OS. Please use --os=OS to force one"
-			log 1 "Allowed values are: UNIX, OSX, FREEBSD, OPENBSD, NETBSD, MORPHOS, HPUX, BEOS, SUNOS, CYGWIN, MINGW, OS2, WINCE, and PSP"
+			log 1 "Allowed values are: UNIX, OSX, FREEBSD, OPENBSD, NETBSD, MORPHOS, HPUX, BEOS, SUNOS, CYGWIN, MINGW, OS2, WINCE, PSP and DJGPP"
 			exit 1
 		fi
 
@@ -1780,6 +1806,10 @@
 	log 1 "checking $2... found"
 }
 
+detect_alleg() {
+	detect_library "$with_alleg" "alleg" "liballeg.a" "allegro.h"
+}
+
 detect_zlib() {
 	detect_library "$with_zlib" "zlib" "libz.a" "zlib.h"
 }
@@ -2315,7 +2345,7 @@
 	echo "  --os=OS                        the OS we are compiling for [DETECT]"
 	echo "                                 DETECT/UNIX/OSX/FREEBSD/OPENBSD/NETBSD/"
 	echo "                                 MORPHOS/HPUX/BEOS/SUNOS/CYGWIN/MINGW/OS2/"
-	echo "                                 WINCE/PSP"
+	echo "                                 WINCE/PSP/DJGPP"
 	echo "  --endian=ENDIAN                set the endian of the HOST (AUTO/LE/BE)"
 	echo "  --revision=rXXXX               overwrite the revision detection."
 	echo "                                 Use with care!"
Index: source.list
===================================================================
--- source.list	(revision 12967)
+++ source.list	(working copy)
@@ -570,6 +570,9 @@
 #if SDL
 	video/sdl_v.cpp
 #end
+#if ALLEG
+	video/alleg_v.cpp
+#end
 #if WIN32
 	video/win32_v.cpp
 #end
@@ -599,9 +602,15 @@
 #if LIBTIMIDITY
 	music/libtimidity.cpp
 #end
+#if ALLEG
+	music/alleg_m.cpp
+#end
 
 # Sound
 sound/null_s.cpp
+#if ALLEG
+	sound/alleg_s.cpp
+#end
 #if SDL
 	sound/sdl_s.cpp
 #end
