Index: binaries/data/config/default.cfg
===================================================================
--- binaries/data/config/default.cfg	(revision 11962)
+++ binaries/data/config/default.cfg	(working copy)
@@ -5,11 +5,15 @@
 ; * create a text file called "local.cfg" instead, and copy    *
 ; * the lines from this file that you want to change.          *
 ; *                                                            *
-; * On Linux / OS X, create:                                   *
-; *   ~/.config/0ad/config/local.cfg                           *
+; * On Linux, create:                                          *
+; *   $XDG_CONFIG_HOME/0ad/config/local.cfg                    *
+; *   (Note: $XDG_CONFIG_HOME defaults to ~/.config)           *
+; *                                                            *
+; * On OS X, create:                                           *
+; *   ~/Library/Application\ Support/0ad/config/local.cfg      *
 ; *                                                            *
 ; * On Windows, create:                                        *
-; *   %appdata%/0ad/config/local.cfg                           *
+; *   %appdata%\0ad\config\local.cfg                           *
 ; *                                                            *
 ; **************************************************************
 
Index: build/premake/extern_libs4.lua
===================================================================
--- build/premake/extern_libs4.lua	(revision 11962)
+++ build/premake/extern_libs4.lua	(working copy)
@@ -211,6 +211,9 @@
 			if os.is("windows") then
 				add_default_include_paths("boost")
 			end
+			if os.typeis("OpenBSD") then
+				includedirs { "/usr/local/include" }
+			end
 		end,
 		link_settings = function()
 			if os.is("windows") then
@@ -356,6 +359,9 @@
 			if os.is("windows") then
 				add_default_include_paths("libpng")
 			end
+			if os.typeis("OpenBSD") then
+				includedirs { "/usr/local/include/libpng" }
+			end
 		end,
 		link_settings = function()
 			if os.is("windows") then
@@ -539,6 +545,12 @@
 			if os.is("windows") then
 				add_default_lib_paths("vorbis")
 			end
+			if os.typeis("OpenBSD") then
+				add_default_links({
+					unix_names = { "ogg",
+						"vorbis" },
+				})
+			end
 			add_default_links({
 				win_names  = { "vorbisfile" },
 				unix_names = { "vorbisfile" },
Index: build/premake/premake4.lua
===================================================================
--- build/premake/premake4.lua	(revision 11962)
+++ build/premake/premake4.lua	(working copy)
@@ -307,7 +307,7 @@
 				if _ACTION == "gmake" then
 					linkoptions { "-Wl,-rpath,'$$ORIGIN'" } 
 				elseif _ACTION == "codeblocks" then
-					linkoptions { "-Wl,-R\\\\$$ORIGIN" }				
+					linkoptions { "-Wl,-R\\\\$$ORIGIN" }
 				end
 			end
 		end
@@ -338,7 +338,7 @@
 	elseif os.is("macosx") then
 		return "ConsoleApp"
 	else
-		return "WindowedApp"		
+		return "WindowedApp"
 	end
 end
 
@@ -609,7 +609,7 @@
 		"cxxtest",
 	}
 
-        if not _OPTIONS["without-audio"] then
+	if not _OPTIONS["without-audio"] then
 		table.insert(extern_libs, "openal")
 		table.insert(extern_libs, "vorbis")
 	end
@@ -765,7 +765,8 @@
 			links { "fam" }
 		end
 
-		if not _OPTIONS["android"] then
+		-- TODO pyrogenesis/test on OpenBSD link vorbis and ogg too (not only vorbisfile)
+		if not _OPTIONS["android"] and not os.typeis("OpenBSD") then
 			links { "rt" }
 		end
 
@@ -774,14 +775,14 @@
 			linkoptions { "-Wl,--fix-cortex-a8" }
 		end
 
-		if os.is("linux") then
+		if os.is("linux") or os.typeis("GNU/kFreeBSD") then
 			links {
 				-- Dynamic libraries (needed for linking for gold)
 				"dl",
 			}
 		elseif os.is("bsd") then
 			links {
-				-- Needed for backtrace* on FreeBSD
+				-- Needed for backtrace* on BSDs
 				"execinfo",
 			}
 		end
@@ -1014,7 +1015,9 @@
 		linkoptions { "-rdynamic" }
 
 	elseif os.is("bsd") then
-		-- define BSD-something?
+		if os.typeis("OpenBSD") then
+			links { "c", }
+		end
 
 		buildoptions { "-fno-strict-aliasing" }
 
@@ -1180,7 +1183,7 @@
 			links { "fam" }
 		end
 
-		if not _OPTIONS["android"] then
+		if not _OPTIONS["android"] and not os.typeis("OpenBSD") then
 			links { "rt" }
 		end
 
@@ -1189,14 +1192,14 @@
 			linkoptions { "-Wl,--fix-cortex-a8" }
 		end
 
-		if os.is("linux") then
+		if os.is("linux") or os.typeis("GNU/kFreeBSD") then
 			links {
 				-- Dynamic libraries (needed for linking for gold)
 				"dl",
 			}
 		elseif os.is("bsd") then
 			links {
-				-- Needed for backtrace* on FreeBSD
+				-- Needed for backtrace* on BSDs
 				"execinfo",
 			}
 		end
Index: build/premake/premake4/src/base/os.lua
===================================================================
--- build/premake/premake4/src/base/os.lua	(revision 11962)
+++ build/premake/premake4/src/base/os.lua	(working copy)
@@ -65,7 +65,6 @@
 	end
 	
 
-	
 --
 -- Check the current operating system; may be set with the /os command line flag.
 --
@@ -73,8 +72,16 @@
 	function os.is(id)
 		return (os.get():lower() == id:lower())
 	end
-	
-	
+
+	function os.typeget()
+		return _OS_TYPE
+	end
+--
+-- Check the current operating system type (currently only which BSD variation)
+--
+	function os.typeis(t)
+		return (os.typeget():lower() == t:lower())
+	end
 
 --
 -- The os.matchdirs() and os.matchfiles() functions
Index: build/premake/premake4/src/host/premake.c
===================================================================
--- build/premake/premake4/src/host/premake.c	(revision 11962)
+++ build/premake/premake4/src/host/premake.c	(working copy)
@@ -87,6 +87,10 @@
 	lua_pushstring(L, PLATFORM_STRING);
 	lua_setglobal(L, "_OS");
 
+	/* set the OS platform type */
+	lua_pushstring(L, PLATFORM_OS_TYPE);
+	lua_setglobal(L, "_OS_TYPE");
+
 	/* Parse the command line arguments */
 	if (z == OKAY)  z = process_arguments(L, argc, argv);
 
Index: build/premake/premake4/src/host/premake.h
===================================================================
--- build/premake/premake4/src/host/premake.h	(revision 11962)
+++ build/premake/premake4/src/host/premake.h	(working copy)
@@ -18,6 +18,15 @@
 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD_kernel__)
 #define PLATFORM_BSD      (1)
 #define PLATFORM_STRING   "bsd"
+# if defined(__FreeBSD_kernel__) && !defined(__FreeBSD__)
+#  define PLATFORM_OS_TYPE "GNU/kFreeBSD"
+# elif defined(__FreeBSD__)
+#  define PLATFORM_OS_TYPE "FreeBSD"
+# elif defined(__NetBSD__)
+#  define PLATFORM_OS_TYPE "NetBSD"
+# elif defined(__OpenBSD__)
+#  define PLATFORM_OS_TYPE "OpenBSD"
+# endif
 #elif defined(__APPLE__) && defined(__MACH__)
 #define PLATFORM_MACOSX   (1)
 #define PLATFORM_STRING   "macosx"
@@ -29,6 +38,10 @@
 #define PLATFORM_STRING   "windows"
 #endif
 
+#ifndef PLATFORM_OS_TYPE
+# define PLATFORM_OS_TYPE ""
+#endif
+
 
 /* Pull in platform-specific headers required by built-in functions */
 #if PLATFORM_WINDOWS
Index: build/premake/premake4/src/host/scripts.c
===================================================================
--- build/premake/premake4/src/host/scripts.c	(revision 11962)
+++ build/premake/premake4/src/host/scripts.c	(working copy)
@@ -4,7 +4,7 @@
 
 const char* builtin_scripts[] = {
 	/* base/os.lua */
-	"function os.executef(cmd, ...)\ncmd = string.format(cmd, unpack(arg))\nreturn os.execute(cmd)\nend\nfunction os.findlib(libname)\nlocal path, formats\nif os.is(\"windows\") then\nformats = { \"%s.dll\", \"%s\" }\npath = os.getenv(\"PATH\")\nelse\nif os.is(\"macosx\") then\nformats = { \"lib%s.dylib\", \"%s.dylib\" }\npath = os.getenv(\"DYLD_LIBRARY_PATH\")\nelse\nformats = { \"lib%s.so\", \"%s.so\" }\npath = os.getenv(\"LD_LIBRARY_PATH\") or \"\"\nio.input(\"/etc/ld.so.conf\")\nif io.input() then\nfor line in io.lines() do\npath = path .. \":\" .. line\nend\nio.input():close()\nend\nend\ntable.insert(formats, \"%s\")\npath = (path or \"\") .. \":/lib:/usr/lib:/usr/local/lib\"\nend\nfor _, fmt in ipairs(formats) do\nlocal name = string.format(fmt, libname)\nlocal result = os.pathsearch(name, path)\nif result then return result end\nend\nend\nfunction os.get()\nreturn _OPTIONS.os or _OS\nend\nfunction os.is(id)\nreturn (os.get():lower() == id:lower())\nend\nlocal function domatch(result, mask, wantfiles)\nif mas"
+	"function os.executef(cmd, ...)\ncmd = string.format(cmd, unpack(arg))\nreturn os.execute(cmd)\nend\nfunction os.findlib(libname)\nlocal path, formats\nif os.is(\"windows\") then\nformats = { \"%s.dll\", \"%s\" }\npath = os.getenv(\"PATH\")\nelse\nif os.is(\"macosx\") then\nformats = { \"lib%s.dylib\", \"%s.dylib\" }\npath = os.getenv(\"DYLD_LIBRARY_PATH\")\nelse\nformats = { \"lib%s.so\", \"%s.so\" }\npath = os.getenv(\"LD_LIBRARY_PATH\") or \"\"\nio.input(\"/etc/ld.so.conf\")\nif io.input() then\nfor line in io.lines() do\npath = path .. \":\" .. line\nend\nio.input():close()\nend\nend\ntable.insert(formats, \"%s\")\npath = (path or \"\") .. \":/lib:/usr/lib:/usr/local/lib\"\nend\nfor _, fmt in ipairs(formats) do\nlocal name = string.format(fmt, libname)\nlocal result = os.pathsearch(name, path)\nif result then return result end\nend\nend\nfunction os.get()\nreturn _OPTIONS.os or _OS\nend\nfunction os.is(id)\nreturn (os.get():lower() == id:lower())\nend\nfunction os.typeget()\nreturn _OS_TYPE\nend\nfunction os.typeis(t)\nreturn (os.typeget():lower() == t:lower())\nend\nlocal function domatch(result, mask, wantfiles)\nif mas"
 	"k:startswith(\"./\") then\nmask = mask:sub(3)\nend\nlocal basedir = mask\nlocal starpos = mask:find(\"%*\")\nif starpos then\nbasedir = basedir:sub(1, starpos - 1)\nend\nbasedir = path.getdirectory(basedir)\nif (basedir == \".\") then basedir = \"\" end\nlocal recurse = mask:find(\"**\", nil, true)\nmask = path.wildcards(mask)\nlocal function matchwalker(basedir)\nlocal wildcard = path.join(basedir, \"*\")\nlocal m = os.matchstart(wildcard)\nwhile (os.matchnext(m)) do\nlocal isfile = os.matchisfile(m)\nif ((wantfiles and isfile) or (not wantfiles and not isfile)) then\nlocal fname = path.join(basedir, os.matchname(m))\nif fname:match(mask) == fname then\ntable.insert(result, fname)\nend\nend\nend\nos.matchdone(m)\nif recurse then\nm = os.matchstart(wildcard)\nwhile (os.matchnext(m)) do\nif not os.matchisfile(m) then\nlocal dirname = os.matchname(m)\nmatchwalker(path.join(basedir, dirname))\nend\nend\nos.matchdone(m)\nend\nend\nmatchwalker(basedir)\nend\nfunction os.matchdirs(...)\nlocal result = { }\nfor _, ma"
 	"sk in ipairs(arg) do\ndomatch(result, mask, false)\nend\nreturn result\nend\nfunction os.matchfiles(...)\nlocal result = { }\nfor _, mask in ipairs(arg) do\ndomatch(result, mask, true)\nend\nreturn result\nend\nlocal builtin_mkdir = os.mkdir\nfunction os.mkdir(p)\nlocal dir = iif(p:startswith(\"/\"), \"/\", \"\")\nfor part in p:gmatch(\"[^/]+\") do\ndir = dir .. part\nif (part ~= \"\" and not path.isabsolute(part) and not os.isdir(dir)) then\nlocal ok, err = builtin_mkdir(dir)\nif (not ok) then\nreturn nil, err\nend\nend\ndir = dir .. \"/\"\nend\nreturn true\nend\nlocal builtin_rmdir = os.rmdir\nfunction os.rmdir(p)\nlocal dirs = os.matchdirs(p .. \"/*\")\nfor _, dname in ipairs(dirs) do\nos.rmdir(dname)\nend\nlocal files = os.matchfiles(p .. \"/*\")\nfor _, fname in ipairs(files) do\nos.remove(fname)\nend\nbuiltin_rmdir(p)\nend\n",
 
Index: source/lib/config2.h
===================================================================
--- source/lib/config2.h	(revision 11962)
+++ source/lib/config2.h	(working copy)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 Wildfire Games
+/* Copyright (c) 2012 Wildfire Games
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -73,7 +73,8 @@
 #ifndef CONFIG2_FILE_ENABLE_AIO
 // work around a bug introduced in Linux 2.6.38
 // (http://www.wildfiregames.com/forum/index.php?showtopic=14561&view=findpost&p=217710)
-# if OS_LINUX
+// OpenBSD doesn't provide aio.h so we disable its use
+# if OS_LINUX || OS_OPENBSD
 #  define CONFIG2_FILE_ENABLE_AIO 0
 # else
 #  define CONFIG2_FILE_ENABLE_AIO 1
Index: source/lib/posix/posix_aio.h
===================================================================
--- source/lib/posix/posix_aio.h	(revision 11962)
+++ source/lib/posix/posix_aio.h	(working copy)
@@ -30,10 +30,22 @@
 
 #if OS_WIN
 # include "lib/sysdep/os/win/wposix/waio.h"
-#elif OS_ANDROID
+#elif OS_ANDROID || OS_OPENBSD
 // Android doesn't provide aio.h. We don't actually use aio on Linuxes (see
 // CONFIG2_FILE_ENABLE_AIO) but we use its symbols and structs, so define
 // them here
+# if OS_OPENBSD
+// OpenBSD 5.1 (latest version at time of writing) has no struct sigevent defined,
+// so we do this here.
+struct sigevent
+{
+	int sigev_notify;
+	int sigev_signo;
+	union sigval sigev_value;
+	void (*sigev_notify_function)(union sigval);
+	pthread_attr_t *sigev_notify_attributes;
+};
+# endif
 # define LIO_READ 0
 # define LIO_WRITE 1
 # define LIO_NOP 2
Index: source/lib/posix/posix_mman.h
===================================================================
--- source/lib/posix/posix_mman.h	(revision 11962)
+++ source/lib/posix/posix_mman.h	(working copy)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 Wildfire Games
+/* Copyright (c) 2012 Wildfire Games
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -20,6 +20,9 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#ifndef INCLUDED_POSIX_MMAN
+#define INCLUDED_POSIX_MMAN
+
 #if OS_WIN
 # include "lib/sysdep/os/win/wposix/wmman.h"
 #else
@@ -27,3 +30,5 @@
 #endif
 
 #include "lib/posix/posix_errno.h"	// for user convenience
+
+#endif	// #ifndef INCLUDED_POSIX_MMAN
Index: source/lib/secure_crt.cpp
===================================================================
--- source/lib/secure_crt.cpp	(revision 11962)
+++ source/lib/secure_crt.cpp	(working copy)
@@ -106,7 +106,7 @@
 // self-test and the t* defines (needed for test).
 #if EMULATE_SECURE_CRT
 
-#if !OS_UNIX || OS_MACOSX
+#if !OS_UNIX || OS_MACOSX || OS_OPENBSD
 // return length [in characters] of a string, not including the trailing
 // null character. to protect against access violations, only the
 // first <max_len> characters are examined; if the null character is
Index: source/lib/secure_crt.h
===================================================================
--- source/lib/secure_crt.h	(revision 11962)
+++ source/lib/secure_crt.h	(working copy)
@@ -47,12 +47,15 @@
 #if EMULATE_SECURE_CRT
 
 // (conflicts with glibc definitions)
-#if !OS_UNIX || OS_MACOSX
+#if !OS_UNIX || OS_MACOSX || OS_OPENBSD
 // return length [in characters] of a string, not including the trailing
 // null character. to protect against access violations, only the
 // first <max_len> characters are examined; if the null character is
 // not encountered by then, <max_len> is returned.
+// strnlen is available on OpenBSD
+#if !OS_OPENBSD
 extern size_t strnlen(const char* str, size_t max_len);
+#endif
 extern size_t wcsnlen(const wchar_t* str, size_t max_len);
 #endif
 
Index: source/lib/sysdep/os.h
===================================================================
--- source/lib/sysdep/os.h	(revision 11962)
+++ source/lib/sysdep/os.h	(working copy)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 Wildfire Games
+/* Copyright (c) 2012 Wildfire Games
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -68,9 +68,16 @@
 // BSD
 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD_kernel__)
 # define OS_BSD 1
+// OpenBSD has no aio.h so and we need a way to disable it for it only
+# if defined(__OpenBSD__)
+#  define OS_OPENBSD 1
+# endif
 #else
 # define OS_BSD 0
 #endif
+#ifndef OS_OPENBSD
+# define OS_OPENBSD 0
+#endif
 // Solaris
 #if defined(sun) || defined(__sun)
 # define OS_SOLARIS 1
Index: source/lib/sysdep/os/bsd/bcpu.cpp
===================================================================
--- source/lib/sysdep/os/bsd/bcpu.cpp	(revision 11962)
+++ source/lib/sysdep/os/bsd/bcpu.cpp	(working copy)
@@ -28,6 +28,7 @@
 #include "lib/module_init.h"
 
 #include "valgrind.h"
+#include <sys/param.h>
 #include <sys/sysctl.h>
 
 size_t os_cpu_NumProcessors()
Index: source/maths/Brush.cpp
===================================================================
--- source/maths/Brush.cpp	(revision 11962)
+++ source/maths/Brush.cpp	(working copy)
@@ -413,4 +413,4 @@
 
 		faceStartIdx = j + 1;
 	}
-}
\ No newline at end of file
+}
Index: source/ps/CStrIntern.h
===================================================================
--- source/ps/CStrIntern.h	(revision 11962)
+++ source/ps/CStrIntern.h	(working copy)
@@ -83,4 +83,4 @@
 	CStrInternInternals* m;
 };
 
-#endif // INCLUDED_CSTRINTERN
\ No newline at end of file
+#endif // INCLUDED_CSTRINTERN
Index: source/ps/Font.cpp
===================================================================
--- source/ps/Font.cpp	(revision 11962)
+++ source/ps/Font.cpp	(working copy)
@@ -81,4 +81,4 @@
 Handle CFont::GetTexture()
 {
 	return unifont_get_texture(h);
-}
\ No newline at end of file
+}
Index: source/ps/PreprocessorWrapper.cpp
===================================================================
--- source/ps/PreprocessorWrapper.cpp	(revision 11962)
+++ source/ps/PreprocessorWrapper.cpp	(working copy)
@@ -83,4 +83,4 @@
 		free(output);
 
 	return ret;
-}
\ No newline at end of file
+}
Index: source/ps/PreprocessorWrapper.h
===================================================================
--- source/ps/PreprocessorWrapper.h	(revision 11962)
+++ source/ps/PreprocessorWrapper.h	(working copy)
@@ -41,4 +41,4 @@
 	CPreprocessor m_Preprocessor;
 };
 
-#endif // INCLUDED_PREPROCESSORWRAPPER
\ No newline at end of file
+#endif // INCLUDED_PREPROCESSORWRAPPER
Index: source/ps/Profiler2GPU.cpp
===================================================================
--- source/ps/Profiler2GPU.cpp	(revision 11962)
+++ source/ps/Profiler2GPU.cpp	(working copy)
@@ -871,4 +871,4 @@
 void CProfiler2GPU::RegionEnter(const char* UNUSED(id)) { }
 void CProfiler2GPU::RegionLeave(const char* UNUSED(id)) { }
 
-#endif
\ No newline at end of file
+#endif
Index: source/renderer/OverlayRenderer.cpp
===================================================================
--- source/renderer/OverlayRenderer.cpp	(revision 11962)
+++ source/renderer/OverlayRenderer.cpp	(working copy)
@@ -606,4 +606,4 @@
 	glDisable(GL_BLEND);
 	glDisable(GL_TEXTURE_2D);
 #endif
-}
\ No newline at end of file
+}
Index: source/renderer/TexturedLineRData.h
===================================================================
--- source/renderer/TexturedLineRData.h	(revision 11962)
+++ source/renderer/TexturedLineRData.h	(working copy)
@@ -85,4 +85,4 @@
 	CVertexBuffer::VBChunk* m_VBIndices;
 };
 
-#endif // INCLUDED_TEXTUREDLINERDATA
\ No newline at end of file
+#endif // INCLUDED_TEXTUREDLINERDATA
Index: source/simulation2/components/tests/test_ObstructionManager.h
===================================================================
--- source/simulation2/components/tests/test_ObstructionManager.h	(revision 11962)
+++ source/simulation2/components/tests/test_ObstructionManager.h	(working copy)
@@ -474,4 +474,4 @@
 		TS_ASSERT_EQUALS(obSquare3.u, CFixedVector2D(fixed::FromInt(1), fixed::FromInt(0)));
 		TS_ASSERT_EQUALS(obSquare3.v, CFixedVector2D(fixed::FromInt(0), fixed::FromInt(1)));
 	}
-};
\ No newline at end of file
+};
Index: source/simulation2/helpers/Render.cpp
===================================================================
--- source/simulation2/helpers/Render.cpp	(revision 11962)
+++ source/simulation2/helpers/Render.cpp	(working copy)
@@ -567,4 +567,4 @@
 	}
 
 	points.swap(newPoints);
-}
\ No newline at end of file
+}

