Index: build/premake/premake4.lua
===================================================================
--- build/premake/premake4.lua	(revision 12041)
+++ build/premake/premake4.lua	(working copy)
@@ -10,6 +10,7 @@
 newoption { trigger = "without-nvtt", description = "Disable use of NVTT" }
 newoption { trigger = "without-tests", description = "Disable generation of test projects" }
 newoption { trigger = "without-pch", description = "Disable generation and usage of precompiled headers" }
+newoption { trigger = "minimal-flags", description = "Only set compiler/linker flags that are really needed" }
 newoption { trigger = "with-system-nvtt", description = "Search standard paths for nvidia-texture-tools library, instead of using bundled copy" }
 newoption { trigger = "with-system-enet", description = "Search standard paths for libenet, instead of using bundled copy" }
 newoption { trigger = "with-system-mozjs185", description = "Search standard paths for libmozjs185, instead of using bundled copy" }
@@ -135,7 +136,7 @@
 function project_set_build_flags()
 
 	flags { "Symbols", "NoEditAndContinue" }
-	if not _OPTIONS["icc"] then
+	if not _OPTIONS["icc"] and not _OPTIONS["minimal-flags"] then
 		-- adds the -Wall compiler flag
 		flags { "ExtraWarnings" } -- this causes far too many warnings/remarks on ICC
 	end
@@ -144,7 +145,9 @@
 		defines { "DEBUG" }
 
 	configuration "Release"
-		flags { "OptimizeSpeed" }
+		if not _OPTIONS["minimal-flags"] then
+			flags { "OptimizeSpeed" }
+		end
 		defines { "NDEBUG", "CONFIG_FINAL=1" }
 
 	configuration { }
@@ -196,41 +199,43 @@
 				linkoptions { "-multiply_defined","suppress" }
 			end
 		else
-			buildoptions {
-				-- enable most of the standard warnings
-				"-Wno-switch",		-- enumeration value not handled in switch (this is sometimes useful, but results in lots of noise)
-				"-Wno-reorder",		-- order of initialization list in constructors (lots of noise)
-				"-Wno-invalid-offsetof",	-- offsetof on non-POD types (see comment in renderer/PatchRData.cpp)
-
-				"-Wextra",
-				"-Wno-missing-field-initializers",	-- (this is common in external headers we can't fix)
-
-				-- add some other useful warnings that need to be enabled explicitly
-				"-Wunused-parameter",
-				"-Wredundant-decls",	-- (useful for finding some multiply-included header files)
-				-- "-Wformat=2",		-- (useful sometimes, but a bit noisy, so skip it by default)
-				-- "-Wcast-qual",		-- (useful for checking const-correctness, but a bit noisy, so skip it by default)
-				"-Wnon-virtual-dtor",	-- (sometimes noisy but finds real bugs)
-				"-Wundef",				-- (useful for finding macro name typos)
-
-				-- enable security features (stack checking etc) that shouldn't have
-				-- a significant effect on performance and can catch bugs
-				"-fstack-protector-all",
-				"-D_FORTIFY_SOURCE=2",
-
-				-- always enable strict aliasing (useful in debug builds because of the warnings)
-				"-fstrict-aliasing",
-
-				-- do something (?) so that ccache can handle compilation with PCH enabled
-				"-fpch-preprocess",
-
-				-- don't omit frame pointers (for now), because performance will be impacted
-				-- negatively by the way this breaks profilers more than it will be impacted
-				-- positively by the optimisation
-				"-fno-omit-frame-pointer"
-			}
+			if not _OPTIONS["minimal-flags"] then
+				buildoptions {
+					-- enable most of the standard warnings
+					"-Wno-switch",		-- enumeration value not handled in switch (this is sometimes useful, but results in lots of noise)
+					"-Wno-reorder",		-- order of initialization list in constructors (lots of noise)
+					"-Wno-invalid-offsetof",	-- offsetof on non-POD types (see comment in renderer/PatchRData.cpp)
+
+					"-Wextra",
+					"-Wno-missing-field-initializers",	-- (this is common in external headers we can't fix)
+
+					-- add some other useful warnings that need to be enabled explicitly
+					"-Wunused-parameter",
+					"-Wredundant-decls",	-- (useful for finding some multiply-included header files)
+					-- "-Wformat=2",		-- (useful sometimes, but a bit noisy, so skip it by default)
+					-- "-Wcast-qual",		-- (useful for checking const-correctness, but a bit noisy, so skip it by default)
+					"-Wnon-virtual-dtor",	-- (sometimes noisy but finds real bugs)
+					"-Wundef",				-- (useful for finding macro name typos)
+
+					-- enable security features (stack checking etc) that shouldn't have
+					-- a significant effect on performance and can catch bugs
+					"-fstack-protector-all",
+					"-D_FORTIFY_SOURCE=2",
+
+					-- always enable strict aliasing (useful in debug builds because of the warnings)
+					"-fstrict-aliasing",
+
+					-- do something (?) so that ccache can handle compilation with PCH enabled
+					"-fpch-preprocess",
+
+					-- don't omit frame pointers (for now), because performance will be impacted
+					-- negatively by the way this breaks profilers more than it will be impacted
+					-- positively by the optimisation
+					"-fno-omit-frame-pointer"
+				}
+			end
 
-			if arch == "x86" or arch == "amd64" then
+			if (arch == "x86" or arch == "amd64") and not _OPTIONS["minimal-flags"] then
 				buildoptions {
 					-- enable SSE intrinsics
 					"-msse"
@@ -245,7 +250,7 @@
 				buildoptions { "-mthumb -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp" }
 			end
 
-			if os.is("linux") or os.is("bsd") then
+			if (os.is("linux") or os.is("bsd")) and not _OPTIONS["minimal-flags"] then
 				linkoptions { "-Wl,--no-undefined", "-Wl,--as-needed" }
 			end
 
@@ -256,7 +261,7 @@
 
 			-- To support intrinsics like __sync_bool_compare_and_swap on x86
 			-- we need to set -march to something that supports them
-			if arch == "x86" then
+			if arch == "x86" and not _OPTIONS["minimal-flags"] then
 				buildoptions { "-march=i686" }
 			end
 
@@ -267,11 +272,13 @@
 			end
 		end
 
-		buildoptions {
-			-- Hide symbols in dynamic shared objects by default, for efficiency and for equivalence with
-			-- Windows - they should be exported explicitly with __attribute__ ((visibility ("default")))
-			"-fvisibility=hidden"
-		}
+		if not _OPTIONS["minimal-flags"] then
+			buildoptions {
+				-- Hide symbols in dynamic shared objects by default, for efficiency and for equivalence with
+				-- Windows - they should be exported explicitly with __attribute__ ((visibility ("default")))
+				"-fvisibility=hidden"
+			}
+		end
 
 		-- X11 includes may be installed in one of a gadzillion of three places
 		-- Famous last words: "You can't include too much! ;-)"
@@ -292,7 +299,8 @@
 			defines { "INSTALLED_LIBDIR=" .. _OPTIONS["libdir"] }
 		end
 
-		if os.is("linux") or os.is("bsd") then
+		-- TODO add "minimal-flags" here too?
+		if (os.is("linux") or os.is("bsd")) and not _OPTIONS["with-system-mozjs185"] then
 			-- To use our local SpiderMonkey library, it needs to be part of the
 			-- runtime dynamic linker path. Add it with -rpath to make sure it gets found.
 			if _OPTIONS["libdir"] then
@@ -325,6 +333,10 @@
 
 	project_set_target(project_name)
 	project_set_build_flags()
+
+	if _OPTIONS["minimal-flags"] then
+		flags { "Symbols" }
+	end
 end
 
 
@@ -841,7 +853,7 @@
 		-- install_name settings aren't really supported yet by premake, but there are plans for the future.
 		-- we currently use this hack to work around some bugs with wrong install_names.
 		if target_type == "SharedLib" then
-			linkoptions { "-install_name @executable_path/lib"..project_name..".dylib" }		
+			linkoptions { "-install_name @executable_path/lib"..project_name..".dylib" }
 		end
 	end
 
@@ -1029,7 +1041,7 @@
 		-- install_name settings aren't really supported yet by premake, but there are plans for the future.
 		-- we currently use this hack to work around some bugs with wrong install_names.
 		if target_type == "SharedLib" then
-			linkoptions { "-install_name @executable_path/lib"..project_name..".dylib" }		
+			linkoptions { "-install_name @executable_path/lib"..project_name..".dylib" }
 		end
 
 		buildoptions { "-fno-strict-aliasing" }
Index: build/workspaces/update-workspaces.sh
===================================================================
--- build/workspaces/update-workspaces.sh	(revision 12041)
+++ build/workspaces/update-workspaces.sh	(working copy)
@@ -82,7 +82,7 @@
 
 # Now build premake and run it to create the makefiles
 cd ../premake/premake4
-# Fix the premake makefile to work on BSDs
+# Fix the premake makefile to work on BSDs/OS X
 case "`uname -s`" in
   "GNU/kFreeBSD" )
     # This needs -ldl as we have a GNU userland and libc
@@ -96,9 +96,10 @@
     sed -e 's/ -ldl/ /g' build/gmake.unix/Premake4.make.bak > build/gmake.unix/Premake4.make
    ;;
   "Darwin" )
-    # Remove the obsolete -s and the unused -rdynamic parameter and
-    # link with the CoreServices framework.
-    sed -e 's/^\([ ]*LDFLAGS[ ]*+=[ ]*\)\(\( [^ ]*\)*\) -s\(\( [^ ]*\)*\)$/\1\2\4/' \
+    # Replace the obsolete -s with -Wl,-x
+    # Remove the unused -rdynamic parameter.
+    # Link with the CoreServices framework.
+    sed -e 's/^\([ ]*LDFLAGS[ ]*+=[ ]*\)\(\( [^ ]*\)*\) -s\(\( [^ ]*\)*\)$/\1\2 -Wl,-x\4/' \
         -e 's/^\([ ]*LDFLAGS[ ]*+=[ ]*\)\(\( [^ ]*\)*\) -rdynamic\(\( [^ ]*\)*\)$/\1\2\4/' \
         -e 's/^\([ ]*LIBS[ ]*+=[ ]*\)\(\( [^ ]*\)*\)$/\1\2 -framework CoreServices /' \
         -i.bak build/gmake.unix/Premake4.make

