toolchain.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. --
  2. -- Copyright 2010-2012 Branimir Karadzic. All rights reserved.
  3. -- License: http://www.opensource.org/licenses/BSD-2-Clause
  4. --
  5. local bxDir = (path.getabsolute("..") .. "/")
  6. function toolchain(_buildDir, _libDir)
  7. newoption {
  8. trigger = "gcc",
  9. value = "GCC",
  10. description = "Choose GCC flavor",
  11. allowed = {
  12. { "emscripten", "Emscripten" },
  13. { "linux", "Linux" },
  14. { "mingw", "MinGW" },
  15. { "nacl", "Native Client" },
  16. { "pnacl", "Native Client - PNaCl" },
  17. { "osx", "OS X" },
  18. }
  19. }
  20. -- Avoid error when invoking premake4 --help.
  21. if (_ACTION == nil) then return end
  22. local XEDK = os.getenv("XEDK")
  23. if not XEDK then XEDK = "<you must install XBOX SDK>" end
  24. location (_buildDir .. "projects/" .. _ACTION)
  25. if _ACTION == "clean" then
  26. os.rmdir(BUILD_DIR)
  27. end
  28. if _ACTION == "gmake" then
  29. if nil == _OPTIONS["gcc"] then
  30. print("GCC flavor must be specified!")
  31. os.exit(1)
  32. end
  33. flags {
  34. "ExtraWarnings",
  35. }
  36. if "emscripten" == _OPTIONS["gcc"] then
  37. if not os.getenv("EMSCRIPTEN") then
  38. print("Set EMSCRIPTEN enviroment variables.")
  39. end
  40. premake.gcc.cc = "$(EMSCRIPTEN)/emcc"
  41. premake.gcc.cxx = "$(EMSCRIPTEN)/em++"
  42. premake.gcc.ar = "$(EMSCRIPTEN)/emar"
  43. location (_buildDir .. "projects/" .. _ACTION .. "-emscripten")
  44. end
  45. if "linux" == _OPTIONS["gcc"] then
  46. location (_buildDir .. "projects/" .. _ACTION .. "-linux")
  47. end
  48. if "mingw" == _OPTIONS["gcc"] then
  49. premake.gcc.cc = "$(MINGW)/bin/mingw32-gcc"
  50. premake.gcc.cxx = "$(MINGW)/bin/mingw32-g++"
  51. premake.gcc.ar = "$(MINGW)/bin/ar"
  52. location (_buildDir .. "projects/" .. _ACTION .. "-mingw")
  53. end
  54. if "nacl" == _OPTIONS["gcc"] then
  55. if not os.getenv("NACL") then
  56. print("Set NACL enviroment variables.")
  57. end
  58. premake.gcc.cc = "$(NACL)/bin/x86_64-nacl-gcc"
  59. premake.gcc.cxx = "$(NACL)/bin/x86_64-nacl-g++"
  60. premake.gcc.ar = "$(NACL)/bin/x86_64-nacl-ar"
  61. location (_buildDir .. "projects/" .. _ACTION .. "-nacl")
  62. end
  63. if "pnacl" == _OPTIONS["gcc"] then
  64. if not os.getenv("PNACL") then
  65. print("Set PNACL enviroment variables.")
  66. end
  67. premake.gcc.cc = "$(PNACL)/bin/pnacl-clang"
  68. premake.gcc.cxx = "$(PNACL)/bin/pnacl-clang++"
  69. premake.gcc.ar = "$(PNACL)/bin/pnacl-ar"
  70. location (_buildDir .. "projects/" .. _ACTION .. "-pnacl")
  71. end
  72. if "osx" == _OPTIONS["gcc"] then
  73. location (_buildDir .. "projects/" .. _ACTION .. "-osx")
  74. end
  75. end
  76. flags {
  77. "StaticRuntime",
  78. "NoMinimalRebuild",
  79. "NoPCH",
  80. "NativeWChar",
  81. "NoRTTI",
  82. "NoExceptions",
  83. "NoEditAndContinue",
  84. "Symbols",
  85. }
  86. defines {
  87. "__STDC_LIMIT_MACROS",
  88. "__STDC_FORMAT_MACROS",
  89. "__STDC_CONSTANT_MACROS",
  90. }
  91. configuration "Debug"
  92. targetsuffix "Debug"
  93. configuration "Release"
  94. flags {
  95. "OptimizeSpeed",
  96. }
  97. targetsuffix "Release"
  98. configuration { "vs*" }
  99. includedirs { bxDir .. "include/compat/msvc" }
  100. defines {
  101. "WIN32",
  102. "_WIN32",
  103. "_HAS_EXCEPTIONS=0",
  104. "_HAS_ITERATOR_DEBUGGING=0",
  105. "_SCL_SECURE=0",
  106. "_SECURE_SCL=0",
  107. "_SCL_SECURE_NO_WARNINGS",
  108. "_CRT_SECURE_NO_WARNINGS",
  109. "_CRT_SECURE_NO_DEPRECATE",
  110. }
  111. buildoptions {
  112. "/Oy-", -- Suppresses creation of frame pointers on the call stack.
  113. "/Ob2", -- The Inline Function Expansion
  114. }
  115. configuration { "x32", "vs*" }
  116. targetdir (_buildDir .. "win32_" .. _ACTION .. "/bin")
  117. objdir (_buildDir .. "win32_" .. _ACTION .. "/obj")
  118. libdirs {
  119. _libDir .. "lib/win32_" .. _ACTION,
  120. "$(DXSDK_DIR)/lib/x86",
  121. "$(GLES_X86_DIR)",
  122. }
  123. configuration { "x64", "vs*" }
  124. defines { "_WIN64" }
  125. targetdir (_buildDir .. "win64_" .. _ACTION .. "/bin")
  126. objdir (_buildDir .. "win64_" .. _ACTION .. "/obj")
  127. libdirs {
  128. _libDir .. "lib/win64_" .. _ACTION,
  129. "$(DXSDK_DIR)/lib/x64",
  130. "$(GLES_X64_DIR)",
  131. }
  132. configuration { "mingw" }
  133. defines { "WIN32" }
  134. includedirs { bxDir .. "include/compat/mingw" }
  135. buildoptions {
  136. "-std=c++0x",
  137. "-U__STRICT_ANSI__",
  138. "-Wunused-value",
  139. "-fdata-sections",
  140. "-ffunction-sections",
  141. }
  142. linkoptions {
  143. "-Wl,--gc-sections",
  144. }
  145. configuration { "x32", "mingw" }
  146. targetdir (_buildDir .. "win32_mingw" .. "/bin")
  147. objdir (_buildDir .. "win32_mingw" .. "/obj")
  148. libdirs {
  149. _libDir .. "lib/win32_mingw",
  150. "$(DXSDK_DIR)/lib/x86",
  151. "$(GLES_X86_DIR)",
  152. }
  153. buildoptions { "-m32" }
  154. configuration { "x64", "mingw" }
  155. targetdir (_buildDir .. "win64_mingw" .. "/bin")
  156. objdir (_buildDir .. "win64_mingw" .. "/obj")
  157. libdirs {
  158. _libDir .. "lib/win64_mingw",
  159. "$(DXSDK_DIR)/lib/x64",
  160. "$(GLES_X64_DIR)",
  161. }
  162. buildoptions { "-m64" }
  163. configuration { "linux" }
  164. buildoptions {
  165. "-std=c++0x",
  166. "-U__STRICT_ANSI__",
  167. "-Wunused-value",
  168. "-mfpmath=sse", -- force SSE to get 32-bit and 64-bit builds deterministic.
  169. "-msse2",
  170. }
  171. links {
  172. "rt",
  173. }
  174. linkoptions {
  175. "-Wl,--gc-sections",
  176. }
  177. configuration { "linux", "x32" }
  178. targetdir (_buildDir .. "linux32_gcc" .. "/bin")
  179. objdir (_buildDir .. "linux32_gcc" .. "/obj")
  180. libdirs { _libDir .. "lib/linux32_gcc" }
  181. buildoptions {
  182. "-m32",
  183. }
  184. configuration { "linux", "x64" }
  185. targetdir (_buildDir .. "linux64_gcc" .. "/bin")
  186. objdir (_buildDir .. "linux64_gcc" .. "/obj")
  187. libdirs { _libDir .. "lib/linux64_gcc" }
  188. buildoptions {
  189. "-m64",
  190. }
  191. configuration { "emscripten" }
  192. targetdir (_buildDir .. "emscripten" .. "/bin")
  193. objdir (_buildDir .. "emscripten" .. "/obj")
  194. libdirs { _libDir .. "lib/emscripten" }
  195. includedirs { "$(EMSCRIPTEN)/system/include" }
  196. buildoptions {
  197. "-pthread",
  198. }
  199. configuration { "nacl" }
  200. defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600" }
  201. includedirs { bxDir .. "include/compat/nacl" }
  202. buildoptions {
  203. "-std=c++0x",
  204. "-U__STRICT_ANSI__",
  205. "-pthread",
  206. "-fno-stack-protector",
  207. "-fdiagnostics-show-option",
  208. "-Wunused-value",
  209. "-fdata-sections",
  210. "-ffunction-sections",
  211. "-mfpmath=sse", -- force SSE to get 32-bit and 64-bit builds deterministic.
  212. "-msse2",
  213. -- "-fmerge-all-constants",
  214. }
  215. linkoptions {
  216. "-Wl,--gc-sections",
  217. }
  218. configuration { "x32", "nacl" }
  219. targetdir (_buildDir .. "nacl-x86" .. "/bin")
  220. objdir (_buildDir .. "nacl-x86" .. "/obj")
  221. libdirs { _libDir .. "lib/nacl-x86" }
  222. linkoptions { "-melf32_nacl" }
  223. configuration { "x64", "nacl" }
  224. targetdir (_buildDir .. "nacl-x64" .. "/bin")
  225. objdir (_buildDir .. "nacl-x64" .. "/obj")
  226. libdirs { _libDir .. "lib/nacl-x64" }
  227. linkoptions { "-melf64_nacl" }
  228. configuration { "pnacl" }
  229. defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600", "__native_client__", "__LITTLE_ENDIAN__" }
  230. includedirs { bxDir .. "include/compat/nacl" }
  231. buildoptions {
  232. "-std=c++0x",
  233. "-U__STRICT_ANSI__",
  234. "-fno-stack-protector",
  235. "-fdiagnostics-show-option",
  236. "-Wunused-value",
  237. "-fdata-sections",
  238. "-ffunction-sections",
  239. }
  240. targetdir (_buildDir .. "pnacl" .. "/bin")
  241. objdir (_buildDir .. "pnacl" .. "/obj")
  242. libdirs { _libDir .. "lib/pnacl" }
  243. includedirs { "$(PNACL)/sysroot/include" }
  244. configuration { "Xbox360" }
  245. targetdir (_buildDir .. "xbox360" .. "/bin")
  246. objdir (_buildDir .. "xbox360" .. "/obj")
  247. includedirs { bxDir .. "include/compat/msvc" }
  248. libdirs { _libDir .. "lib/xbox360" }
  249. defines {
  250. "NOMINMAX",
  251. "_XBOX",
  252. }
  253. configuration { "macosx", "x32" }
  254. targetdir (_buildDir .. "osx32_gcc" .. "/bin")
  255. objdir (_buildDir .. "osx32_gcc" .. "/obj")
  256. libdirs { _libDir .. "lib/osx32_gcc" }
  257. buildoptions {
  258. "-m32",
  259. }
  260. configuration { "macosx", "x64" }
  261. targetdir (_buildDir .. "osx64_gcc" .. "/bin")
  262. objdir (_buildDir .. "osx64_gcc" .. "/obj")
  263. libdirs { _libDir .. "lib/osx64_gcc" }
  264. buildoptions {
  265. "-m64",
  266. }
  267. configuration { "macosx" }
  268. buildoptions {
  269. "-U__STRICT_ANSI__",
  270. "-Wfatal-errors",
  271. "-Wunused-value",
  272. "-msse2",
  273. }
  274. includedirs { bxDir .. "include/compat/osx" }
  275. configuration {} -- reset configuration
  276. end