toolchain.lua 9.4 KB

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