Index: build/premake/extern_libs4.lua
===================================================================
--- build/premake/extern_libs4.lua	(revision 15792)
+++ build/premake/extern_libs4.lua	(working copy)
@@ -235,7 +235,8 @@
 				-- Suppress all the Boost warnings on OS X by including it as a system directory
 				buildoptions { "-isystem../" .. libraries_dir .. "boost/include" }
 			end
-			if os.getversion().description == "OpenBSD" then
+			-- TODO: This actually applies to most libraries we use on BSDs, make this a global setting.
+			if os.is("bsd") then
 				includedirs { "/usr/local/include" }
 			end
 		end,
@@ -347,6 +348,8 @@
 			elseif os.is("macosx") then
 				add_default_include_paths("iconv")
 				defines { "LIBICONV_STATIC" }
+			elseif os.getversion().description == "FreeBSD" then
+				defines { "HAVE_ICONV_CONST" }
 			end
 		end,
 		link_settings = function()
@@ -355,10 +358,18 @@
 			end
 			add_default_links({
 				win_names  = { "libiconv" },
-				-- TODO: glibc provides symbols for this, so we should only include that (and depend on libiconv) on non-glibc unix
 				osx_names = { "iconv" },
 				dbg_suffix = "",
 			})
+			-- glibc (used on Linux and GNU/kFreeBSD) has iconv
+			-- FreeBSD 10+ has iconv as a part of libc
+			if os.is("bsd")
+			   and not (os.getversion().description == "FreeBSD" and os.getversion().majorversion >= 10
+			            or os.getversion().description == "GNU/kFreeBSD") then
+				add_default_links({
+					bsd_names = { "iconv" },
+				})
+			end
 		end,
 	},
 	icu = {
Index: build/premake/premake4.lua
===================================================================
--- build/premake/premake4.lua	(revision 15792)
+++ build/premake/premake4.lua	(working copy)
@@ -38,6 +38,33 @@
 
 dofile("extern_libs4.lua")
 
+-- detect compiler for non-Windows
+if os.is("macosx") then
+	cc = "clang"
+elseif os.is("linux") and _OPTIONS["icc"] then
+	cc = "icc"
+elseif not os.is("windows") then
+	cc = os.getenv("CC")
+	if cc == nil or cc == "" then
+		local hasgcc = os.execute("which gcc > .gccpath")
+		local f = io.open(".gccpath", "r")
+		local gccpath = f:read("*line")
+		f:close()
+		os.execute("rm .gccpath")
+		if gccpath == nil then
+			cc = "clang"
+		else
+			cc = "gcc"
+		end
+	end
+end
+
+-- TODO: proper clang support
+if cc == "clang" then
+	premake.gcc.cc  = "clang"
+	premake.gcc.cxx = "clang++"
+end
+
 -- detect CPU architecture (simplistic, currently only supports x86, amd64 and ARM)
 arch = "x86"
 if _OPTIONS["android"] then
@@ -51,7 +78,7 @@
 	if arch == "x86_64" or arch == "amd64" then
 		arch = "amd64"
 	else
-		os.execute("gcc -dumpmachine > .gccmachine.tmp")
+		os.execute(cc .. " -dumpmachine > .gccmachine.tmp")
 		local f = io.open(".gccmachine.tmp", "r")
 		local machine = f:read("*line")
 		f:close()
@@ -67,13 +94,6 @@
 	end
 end
 
--- Hack to force clang as default compiler on OS X
--- TODO: proper clang support
-if os.is("macosx") then
-	premake.gcc.cc  = "clang"
-	premake.gcc.cxx = "clang++"
-end
-
 -- Set up the Solution
 solution "pyrogenesis"
 targetdir(rootdir.."/binaries/system")
@@ -109,7 +129,7 @@
 	-- It's too late to do this test by the time we start compiling the PCH file, so
 	-- do the test in this build script instead (which is kind of ugly - please fix if
 	-- you have a better idea)
-	if not _OPTIONS["icc"] then
+	if cc == "gcc" then
 		os.execute("gcc -dumpversion > .gccver.tmp")
 		local f = io.open(".gccver.tmp", "r")
 		major, dot, minor = f:read(1, 1, 1)
@@ -158,7 +178,7 @@
 function project_set_build_flags()
 
 	flags { "Symbols", "NoEditAndContinue" }
-	if not _OPTIONS["icc"] and (os.is("windows") or not _OPTIONS["minimal-flags"]) then
+	if cc ~= "icc" and (os.is("windows") or not _OPTIONS["minimal-flags"]) then
 		-- adds the -Wall compiler flag
 		flags { "ExtraWarnings" } -- this causes far too many warnings/remarks on ICC
 	end
@@ -218,7 +238,7 @@
 		end
 
 	else	-- *nix
-		if _OPTIONS["icc"] and not _OPTIONS["minimal-flags"] then
+		if cc == "icc" and not _OPTIONS["minimal-flags"] then
 			buildoptions {
 				"-w1",
 				-- "-Wabi",
@@ -391,11 +411,13 @@
 -- bundled libs
 function project_add_x11_dirs()
 	if not os.is("windows") and not os.is("macosx") then
-		-- X11 includes may be installed in one of a gadzillion of three places
+		-- X11 includes may be installed in one of a gadzillion of five places
 		-- Famous last words: "You can't include too much! ;-)"
 		includedirs {
 			"/usr/X11R6/include/X11",
 			"/usr/X11R6/include",
+			"/usr/local/include/X11",
+			"/usr/local/include",
 			"/usr/include/X11"
 		}
 		libdirs { "/usr/X11R6/lib" }
Index: libraries/source/fcollada/src/Makefile
===================================================================
--- libraries/source/fcollada/src/Makefile	(revision 15792)
+++ libraries/source/fcollada/src/Makefile	(working copy)
@@ -7,6 +7,12 @@
 	PIC_FLAGS ?= -fpic
 endif
 
+ifeq ($(OS_ARCH),FreeBSD)
+	DIRS_SH=csh
+else
+	DIRS_SH=sh
+endif
+
 CXX ?= g++
 CXXFLAGS += -fvisibility=hidden -W -Wall -Wno-unused-parameter -Wno-unused-function $(OS_DEFINE) $(PIC_FLAGS) $(CPPFLAGS)
 CXXFLAGS_DEBUG := -O0 -g -D_DEBUG -DRETAIL
@@ -227,7 +233,7 @@
 all: output_dirs output/libFColladaSD.a output/libFColladaSR.a install
 
 output_dirs:
-	bash -c 'mkdir -p output/{debug,release,test}/{FCollada/{FCDocument,FMath,FUtils,FColladaTest/{FCTestAssetManagement,FCTestExportImport,FCTestXRef}},FColladaPlugins/FArchiveXML}'
+	$(DIRS_SH) -c 'mkdir -p output/{debug,release,test}/{FCollada/{FCDocument,FMath,FUtils,FColladaTest/{FCTestAssetManagement,FCTestExportImport,FCTestXRef}},FColladaPlugins/FArchiveXML}'
 
 test: FCollada/FColladaTest/ output/FColladaTest
 	( cd FCollada/FColladaTest/ ; ../../output/FColladaTest )
Index: libraries/source/spidermonkey/build.sh
===================================================================
--- libraries/source/spidermonkey/build.sh	(revision 15792)
+++ libraries/source/spidermonkey/build.sh	(working copy)
@@ -103,6 +103,13 @@
   LIB_PREFIX=lib
   LIB_SRC_SUFFIX=.so
   LIB_DST_SUFFIX=.so
+  if [ "`uname -s`" = "OpenBSD" ]
+  then
+    DLL_SRC_SUFFIX=.so.1.0
+    DLL_DST_SUFFIX=.so.1.0
+    LIB_SRC_SUFFIX=.so.1.0
+    LIB_DST_SUFFIX=:so.1.0
+  fi
 fi
 
 # Copy files into the necessary locations for building and running the game
Index: source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp
===================================================================
--- source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp	(revision 15792)
+++ source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp	(working copy)
@@ -158,7 +158,7 @@
 					wxString x(xmlData->GetNodeContent());
 					unsigned long xTmp = 0;
 					x.ToULong(&xTmp);
-					wxASSERT(xTmp <= (unsigned long)UINT32_MAX);
+					wxASSERT(xTmp <= (unsigned long)std::numeric_limits<unsigned int>::max());
 					actorSeed = xTmp;
 				}
 
