toolchain.lua 11 KB

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