toolchain.lua 8.6 KB

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