about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--default.bam198
-rw-r--r--src/engine/client/ec_gfx.c2
-rw-r--r--src/engine/client/ec_inp.c2
-rw-r--r--src/engine/client/ec_snd.c2
-rw-r--r--src/engine/e_datafile.c2
-rw-r--r--src/engine/e_system.c10
-rw-r--r--src/engine/external/portaudio/src/hostapi/oss/recplay.c114
7 files changed, 141 insertions, 189 deletions
diff --git a/default.bam b/default.bam
index d76d5cfd..1bf44415 100644
--- a/default.bam
+++ b/default.bam
@@ -1,3 +1,25 @@
+--- Setup Config --------
+config = NewConfig()
+config:add(OptFindCompiler())
+config:add(OptTestCompileC("stackprotector", "int main(){return 0;}", "-fstack-protector -fstack-protector-all"))
+config:add(OptFindLibrary("zlib", "zlib.h", false))
+config:add(OptFindLibrary("glfw", "glfw.h", false))
+config:add(OptFindLibrary("portaudio", "portaudio.h_FAIL", false))
+
+config:add(OptFindLibrary("coreaudio", "AudioUnit/AudioUnit.h", false))
+config:add(OptFindLibrary("alsa", "alsa/asoundlib.h", false))
+config:add(OptFindLibrary("oss_sys", "sys/soundcard.h", false))
+config:add(OptFindLibrary("oss_linux", "linux/soundcard.h", false))
+config:add(OptFindLibrary("oss_machine", "machine/soundcard.h", false))
+config:add(OptFindLibrary("dsound", "dsound.h", true))
+
+--- Auto detect ------
+if not config:load("config.bam") then
+	print("--- Auto Configuration ---")
+	config:autodetect()
+	config:save("config.bam")
+	print("--- ")
+end
 
 -- data compiler
 dc_compiler = "python scripts/compiler.py"
@@ -191,19 +213,10 @@ nethash = CHash(
 	"src/game/g_game.cpp", networkdata.header)
 
 client_link_other = {}
-if family == "windows" then
+if config.compiler.value == "cl" then
 	client_link_other = {ResCompile("other/icons/teeworlds.rc")}
 end
 
-
--- [TODO: Should be in C]
-function file_ext(s)
-	for ext in string.gfind(s, "%.%a+$") do
-		return string.sub(ext, 2)
-	end
-	return ""
-end
-
 function intermediate_output_func(dir, input, extension)
 	if not (dir == "") then
 		return Path(dir .. "/" .. PathBase(PathFilename(input)) .. extension)
@@ -215,80 +228,131 @@ function build(settings)
 	settings.objdir = Path("objs")
 	settings.cc.output = intermediate_output_func
 
-	if family == "windows" then
+	if config.compiler.value == "cl" then
 		settings.cc.flags = "/wd4244"
 	else
-		if platform == "macosx" then
-			settings.cc.flags = "-Wall -fno-exceptions"
-		else
-			settings.cc.flags = "-Wall -fstack-protector -fstack-protector-all -fno-exceptions"
+		settings.cc.flags = "-Wall -fno-exceptions "
+		if config.stackprotector.value == 1 then
+			settings.cc.flags = settings.cc.flags .. "-fstack-protector -fstack-protector-all"
 		end
 		settings.linker.flags = ""
 	end
 
 	-- set some platform specific settings
 	settings.cc.includes:add("src")
-	settings.cc.includes:add("src/external/zlib")
 
 	if family == "unix" then
    		if platform == "macosx" then
 			glfw_platform = "macosx"
 			pa_platform = "mac_osx"
-			pa_hostapi = "coreaudio"
 		else
 			glfw_platform = "x11"
 			pa_platform = "unix"
-			
-			if platform == "linux" then
-				pa_hostapi = "alsa"
-			else
-				pa_hostapi = "oss"
-			end
-			
 			settings.linker.libs:add("pthread")
 		end
 	elseif family == "windows" then
 		glfw_platform = "win32"
 		pa_platform = "win"
-		pa_hostapi = "dsound"
-		settings.linker.libs:add("gdi32.lib")
-		settings.linker.libs:add("user32.lib")
-		settings.linker.libs:add("ws2_32.lib")
-		settings.linker.libs:add("ole32.lib")
-		settings.linker.libs:add("shell32.lib")
+		settings.linker.libs:add("gdi32")
+		settings.linker.libs:add("user32")
+		settings.linker.libs:add("ws2_32")
+		settings.linker.libs:add("ole32")
+		settings.linker.libs:add("shell32")
 	end
 	
-	-- build glfw
-	glfw_settings = settings:copy()
-	glfw_settings.cc.includes:add("src/external/glfw/include")
-	glfw_settings.cc.includes:add("src/engine/external/glfw/lib")
-	glfw_settings.cc.includes:add("src/engine/external/glfw/lib/" .. glfw_platform)
-
-	glfw = Compile(glfw_settings, Collect(
-		"src/engine/external/glfw/lib/*.c",
-		"src/engine/external/glfw/lib/" .. glfw_platform .. "/*.c"))
+	-- build glfw if needed (not tested)
+	if config.glfw.value == 1 then
+		settings.linker.libs:add("glfw")
+		if config.glfw.include_path then
+			settings.cc.includes:add(config.glfw.include_path)
+		end
+		glfw = {}
+	else
+		glfw_settings = settings:copy()
+		glfw_settings.cc.includes:add("src/external/glfw/include")
+		glfw_settings.cc.includes:add("src/engine/external/glfw/lib")
+		glfw_settings.cc.includes:add("src/engine/external/glfw/lib/" .. glfw_platform)
+
+		glfw = Compile(glfw_settings, Collect(
+			"src/engine/external/glfw/lib/*.c",
+			"src/engine/external/glfw/lib/" .. glfw_platform .. "/*.c"))
+		
+		settings.cc.includes:add("src/engine/external/glfw/include")
+	end
 		
 	-- build portaudio
-	pa_settings = settings:copy()
-	pa_settings.cc.defines:add("PA_USE_" .. string.upper(pa_hostapi))
-	pa_settings.cc.defines:add("PA_NO_WMME")
-	pa_settings.cc.defines:add("PA_NO_ASIO")
-	pa_settings.cc.includes:add("src/engine/external/portaudio/include")
-	pa_settings.cc.includes:add("src/engine/external/portaudio/src/common")
-	pa_settings.cc.includes:add("src/engine/external/portaudio/src/os/" .. pa_platform)
+	if config.portaudio.value == 1 then
+		settings.linker.libs:add("portaudio")
+		if config.portaudio.include_path then
+			settings.cc.includes:add(config.portaudio.include_path)
+		end
+		portaudio = {}
+	else
+		pa_settings = settings:copy()
+
+		pa_hostapis = {}		
+		if config.alsa.value == 1 then pa_hostapis["alsa"] = 1 end
+		if config.dsound.value == 1 then
+			pa_hostapis["dsound"] = 1
+		else
+			pa_settings.cc.defines:add("PA_NO_DS")
+		end
+		if config.coreaudio.value == 1 then pa_hostapis["coreaudio"] = 1 end
+		
+		if config.oss_sys.value == 1 then
+			pa_hostapis["oss"] = 1
+			pa_settings.cc.defines:add("HAVE_SYS_SOUNDCARD_H")
+		elseif config.oss_linux.value == 1 then
+			pa_hostapis["oss"] = 1
+			pa_settings.cc.defines:add("HAVE_LINUX_SOUNDCARD_H")
+		elseif config.oss_machine.value == 1 then
+			pa_hostapis["oss"] = 1
+			pa_settings.cc.defines:add("HAVE_MACHINE_SOUNDCARD_H")
+		end
+		
+		pa_settings.cc.defines:add("PA_NO_WMME")
+		pa_settings.cc.defines:add("PA_NO_ASIO")
+		pa_settings.cc.includes:add("src/engine/external/portaudio/include")
+		pa_settings.cc.includes:add("src/engine/external/portaudio/src/common")
+		pa_settings.cc.includes:add("src/engine/external/portaudio/src/os/" .. pa_platform)
+		
+		pa_api_files = {}
+		for api,v in pa_hostapis do
+			pa_settings.cc.defines:add("PA_USE_"..string.upper(api))
+			pa_api_files[api] = Collect("src/engine/external/portaudio/src/hostapi/" .. api .. "/*.c")
+		end
+		
+		portaudio = Compile(pa_settings,
+			Collect("src/engine/external/portaudio/src/common/*.c"),
+			Collect("src/engine/external/portaudio/src/os/" .. pa_platform .. "/*.c"),
+			pa_api_files)
+		
+		settings.cc.includes:add("src/engine/external/portaudio/include")
+	end
 	
-	portaudio = Compile(pa_settings,
-		Collect("src/engine/external/portaudio/src/common/*.c"),
-		Collect("src/engine/external/portaudio/src/os/" .. pa_platform .. "/*.c"),
-		Collect("src/engine/external/portaudio/src/hostapi/" .. pa_hostapi .. "/*.c"))
+	-- compile zlib if needed
+	if config.zlib.value == 1 then
+		settings.linker.libs:add("z")
+		if config.zlib.include_path then
+			settings.cc.includes:add(config.zlib.include_path)
+		end
+		zlib = {}
+	else
+		zlib = Compile(settings, Collect("src/engine/external/zlib/*.c"))
+		settings.cc.includes:add("src/engine/external/zlib")
+	end
+
+	-- build the small libraries
+	wavpack = Compile(settings, Collect("src/engine/external/wavpack/*.c"))
+	pnglite = Compile(settings, Collect("src/engine/external/pnglite/*.c"))
 	
 	-- build game components
 	engine_settings = settings:copy()
 	
-	if family == "windows" then
+	if config.compiler.value == "cl" then
 		engine_settings.cc.flags = "/wd4244"
 	else
-   		if platform == "macosx" then
+   		if platform == "macosx"  or family == "windows" then
 			engine_settings.cc.flags = "-Wall"
 		else
 			engine_settings.cc.flags = "-Wall -pedantic-errors"
@@ -301,7 +365,6 @@ function build(settings)
 
 	-- client
 	client_settings = engine_settings:copy()
-	client_settings.cc.includes:add("src/external/glfw/include")
 
 	if family == "unix" then
    		if platform == "macosx" then
@@ -309,25 +372,30 @@ function build(settings)
             client_settings.linker.frameworks:add("AGL")
             client_settings.linker.frameworks:add("Carbon")
             client_settings.linker.frameworks:add("Cocoa")
-			client_settings.linker.frameworks:add("CoreAudio")
-			client_settings.linker.frameworks:add("AudioToolbox")
-			client_settings.linker.frameworks:add("AudioUnit")
+
+			if config.coreaudio.value == 1 then
+				client_settings.linker.frameworks:add("CoreAudio")
+				client_settings.linker.frameworks:add("AudioToolbox")
+				client_settings.linker.frameworks:add("AudioUnit")
+			end
 		else
-            client_settings.linker.libs:add("asound")
+			if config.alsa.value == 1 then
+            	client_settings.linker.libs:add("asound")
+            end
+            
 			client_settings.linker.libs:add("X11")
 			client_settings.linker.libs:add("GL")
 			client_settings.linker.libs:add("GLU")
 		end
 	elseif family == "windows" then
-		client_settings.linker.libs:add("opengl32.lib")
-		client_settings.linker.libs:add("glu32.lib")
-		client_settings.linker.libs:add("dsound.lib")
-	end
+		client_settings.linker.libs:add("opengl32")
+		client_settings.linker.libs:add("glu32")
+		client_settings.linker.libs:add("winmm")
 
-	external_settings = settings:copy()
-	zlib = Compile(external_settings, Collect("src/engine/external/zlib/*.c"))
-	wavpack = Compile(external_settings, Collect("src/engine/external/wavpack/*.c"))
-	pnglite = Compile(external_settings, Collect("src/engine/external/pnglite/*.c"))
+		if config.dsound.value == 1 then
+			client_settings.linker.libs:add("dsound")
+		end
+	end
 
 	engine = Compile(engine_settings, Collect("src/engine/*.c"))
 	client = Compile(client_settings, Collect("src/engine/client/*.c"))
diff --git a/src/engine/client/ec_gfx.c b/src/engine/client/ec_gfx.c
index 3a9f11d1..f3488196 100644
--- a/src/engine/client/ec_gfx.c
+++ b/src/engine/client/ec_gfx.c
@@ -1,5 +1,5 @@
 /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
-#include <engine/external/glfw/include/GL/glfw.h>
+#include <GL/glfw.h>
 #include <engine/external/pnglite/pnglite.h>
 
 #include <engine/e_system.h>
diff --git a/src/engine/client/ec_inp.c b/src/engine/client/ec_inp.c
index 88942959..56b5fd1f 100644
--- a/src/engine/client/ec_inp.c
+++ b/src/engine/client/ec_inp.c
@@ -1,6 +1,6 @@
 /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
 #include <string.h>
-#include <engine/external/glfw/include/GL/glfw.h>
+#include <GL/glfw.h>
 
 #include <engine/e_system.h>
 #include <engine/e_client_interface.h>
diff --git a/src/engine/client/ec_snd.c b/src/engine/client/ec_snd.c
index 269019d8..a3b687a7 100644
--- a/src/engine/client/ec_snd.c
+++ b/src/engine/client/ec_snd.c
@@ -3,8 +3,8 @@
 #include <engine/e_client_interface.h>
 #include <engine/e_config.h>
 
-#include <engine/external/portaudio/include/portaudio.h>
 #include <engine/external/wavpack/wavpack.h>
+#include <portaudio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
diff --git a/src/engine/e_datafile.c b/src/engine/e_datafile.c
index 6a74de95..59858eda 100644
--- a/src/engine/e_datafile.c
+++ b/src/engine/e_datafile.c
@@ -1,7 +1,7 @@
 /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
 #include "e_system.h"
 #include "e_datafile.h"
-#include "external/zlib/zlib.h"
+#include <zlib.h>
 
 static const int DEBUG=0;
 
diff --git a/src/engine/e_system.c b/src/engine/e_system.c
index f87fd6f3..c0d3595c 100644
--- a/src/engine/e_system.c
+++ b/src/engine/e_system.c
@@ -29,11 +29,10 @@
 	#include <unistd.h>
 #elif defined(CONF_FAMILY_WINDOWS)
 	#define WIN32_LEAN_AND_MEAN 
-	#define _WIN32_WINNT 0x0400
+	#define _WIN32_WINNT 0x0501 /* required for mingw to get getaddrinfo to work */
 	#include <windows.h>
 	#include <winsock2.h>
 	#include <ws2tcpip.h>
-	#include <shlobj.h> /* for SHGetFolderPathAndSubDir */
 	#include <fcntl.h>
 	#include <direct.h>
 	#include <errno.h>
@@ -761,10 +760,9 @@ int fs_storage_path(const char *appname, char *path, int max)
 {
 #if defined(CONF_FAMILY_WINDOWS)
 	HRESULT r;
-	char home[MAX_PATH];
-	r = SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, home);
-	if(r != 0)
-			return 1;
+	char *home = getenv("APPDATA");
+	if(!home)
+		return 1;
 	_snprintf(path, max, "%s/%s", home, appname);
 	return 0;
 #else
diff --git a/src/engine/external/portaudio/src/hostapi/oss/recplay.c b/src/engine/external/portaudio/src/hostapi/oss/recplay.c
deleted file mode 100644
index 9d4c78cf..00000000
--- a/src/engine/external/portaudio/src/hostapi/oss/recplay.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * recplay.c
- * Phil Burk
- * Minimal record and playback test.
- * 
- */
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#ifndef __STDC__
-/* #include <getopt.h> */
-#endif /* __STDC__ */
-#include <fcntl.h>
-#ifdef __STDC__
-#include <string.h>
-#else /* __STDC__ */
-#include <strings.h>
-#endif /* __STDC__ */
-#include <sys/soundcard.h>
-
-#define NUM_BYTES   (64*1024)
-#define BLOCK_SIZE   (4*1024)
-
-#define AUDIO "/dev/dsp"
-
-char buffer[NUM_BYTES];
-
-int audioDev = 0;
-
-main (int argc, char *argv[])
-{
-    int   numLeft;
-    char *ptr;
-    int   num;
-    int   samplesize;
-
-    /********** RECORD ********************/
-    /* Open audio device. */
-    audioDev = open (AUDIO, O_RDONLY, 0);
-    if (audioDev == -1)
-    {
-        perror (AUDIO);
-        exit (-1);
-    }
-
-    /* Set to 16 bit samples. */
-    samplesize = 16;
-    ioctl(audioDev, SNDCTL_DSP_SAMPLESIZE, &samplesize);
-    if (samplesize != 16)
-    {
-        perror("Unable to set the sample size.");
-        exit(-1);
-    }
-
-    /* Record in blocks */
-    printf("Begin recording.\n");
-    numLeft = NUM_BYTES;
-    ptr = buffer;
-    while( numLeft >= BLOCK_SIZE )
-    {
-        if ( (num = read (audioDev, ptr, BLOCK_SIZE)) < 0 )
-        {
-            perror (AUDIO);
-            exit (-1);
-        }
-        else
-        {
-            printf("Read %d bytes\n", num);
-            ptr += num;
-            numLeft -= num;
-        }
-    }
-
-    close( audioDev );
-
-    /********** PLAYBACK ********************/
-    /* Open audio device for writing. */
-    audioDev = open (AUDIO, O_WRONLY, 0);
-    if (audioDev == -1)
-    {
-        perror (AUDIO);
-        exit (-1);
-    }
-
-    /* Set to 16 bit samples. */
-    samplesize = 16;
-    ioctl(audioDev, SNDCTL_DSP_SAMPLESIZE, &samplesize);
-    if (samplesize != 16)
-    {
-        perror("Unable to set the sample size.");
-        exit(-1);
-    }
-
-    /* Play in blocks */
-    printf("Begin playing.\n");
-    numLeft = NUM_BYTES;
-    ptr = buffer;
-    while( numLeft >= BLOCK_SIZE )
-    {
-        if ( (num = write (audioDev, ptr, BLOCK_SIZE)) < 0 )
-        {
-            perror (AUDIO);
-            exit (-1);
-        }
-        else
-        {
-            printf("Wrote %d bytes\n", num);
-            ptr += num;
-            numLeft -= num;
-        }
-    }
-
-    close( audioDev );
-}