toolchain.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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)/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a",
  228. }
  229. includedirs {
  230. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.7/include",
  231. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include",
  232. "$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
  233. }
  234. linkoptions {
  235. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  236. "-nostdlib",
  237. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtbegin_so.o",
  238. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtend_so.o",
  239. "-march=armv7-a",
  240. "-Wl,-shared,-Bsymbolic",
  241. "-Wl,--gc-sections",
  242. "-Wl,--fix-cortex-a8",
  243. "-static-libgcc",
  244. }
  245. links {
  246. "c",
  247. "m",
  248. "android",
  249. "gnustl_static",
  250. }
  251. buildoptions {
  252. "-std=c++0x",
  253. "-U__STRICT_ANSI__",
  254. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  255. "-fPIC",
  256. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  257. "-mthumb",
  258. "-march=armv7-a",
  259. "-mfloat-abi=softfp",
  260. "-mfpu=vfpv3-d16",
  261. }
  262. configuration { "emscripten" }
  263. targetdir (_buildDir .. "emscripten" .. "/bin")
  264. objdir (_buildDir .. "emscripten" .. "/obj")
  265. libdirs { _libDir .. "lib/emscripten" }
  266. includedirs { "$(EMSCRIPTEN)/system/include" }
  267. buildoptions {
  268. "-pthread",
  269. }
  270. configuration { "nacl" }
  271. defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600" }
  272. includedirs { bxDir .. "include/compat/nacl" }
  273. buildoptions {
  274. "-std=c++0x",
  275. "-U__STRICT_ANSI__",
  276. "-pthread",
  277. "-fno-stack-protector",
  278. "-fdiagnostics-show-option",
  279. "-Wunused-value",
  280. "-fdata-sections",
  281. "-ffunction-sections",
  282. "-mfpmath=sse", -- force SSE to get 32-bit and 64-bit builds deterministic.
  283. "-msse2",
  284. -- "-fmerge-all-constants",
  285. }
  286. linkoptions {
  287. "-Wl,--gc-sections",
  288. }
  289. configuration { "x32", "nacl" }
  290. targetdir (_buildDir .. "nacl-x86" .. "/bin")
  291. objdir (_buildDir .. "nacl-x86" .. "/obj")
  292. libdirs { _libDir .. "lib/nacl-x86" }
  293. linkoptions { "-melf32_nacl" }
  294. configuration { "x64", "nacl" }
  295. targetdir (_buildDir .. "nacl-x64" .. "/bin")
  296. objdir (_buildDir .. "nacl-x64" .. "/obj")
  297. libdirs { _libDir .. "lib/nacl-x64" }
  298. linkoptions { "-melf64_nacl" }
  299. configuration { "nacl-arm" }
  300. defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600", "__native_client__", "__LITTLE_ENDIAN__" }
  301. includedirs { bxDir .. "include/compat/nacl" }
  302. buildoptions {
  303. "-std=c++0x",
  304. "-U__STRICT_ANSI__",
  305. "-fno-stack-protector",
  306. "-fdiagnostics-show-option",
  307. "-Wunused-value",
  308. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  309. "-fdata-sections",
  310. "-ffunction-sections",
  311. }
  312. targetdir (_buildDir .. "nacl-arm" .. "/bin")
  313. objdir (_buildDir .. "nacl-arm" .. "/obj")
  314. libdirs { _libDir .. "lib/nacl-arm" }
  315. configuration { "pnacl" }
  316. defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600", "__native_client__", "__LITTLE_ENDIAN__" }
  317. includedirs { bxDir .. "include/compat/nacl" }
  318. buildoptions {
  319. "-std=c++0x",
  320. "-U__STRICT_ANSI__",
  321. "-fno-stack-protector",
  322. "-fdiagnostics-show-option",
  323. "-Wunused-value",
  324. "-fdata-sections",
  325. "-ffunction-sections",
  326. }
  327. targetdir (_buildDir .. "pnacl" .. "/bin")
  328. objdir (_buildDir .. "pnacl" .. "/obj")
  329. libdirs { _libDir .. "lib/pnacl" }
  330. includedirs { "$(PNACL)/sysroot/include" }
  331. configuration { "Xbox360" }
  332. targetdir (_buildDir .. "xbox360" .. "/bin")
  333. objdir (_buildDir .. "xbox360" .. "/obj")
  334. includedirs { bxDir .. "include/compat/msvc" }
  335. libdirs { _libDir .. "lib/xbox360" }
  336. defines {
  337. "NOMINMAX",
  338. "_XBOX",
  339. }
  340. configuration { "osx", "x32" }
  341. targetdir (_buildDir .. "osx32_gcc" .. "/bin")
  342. objdir (_buildDir .. "osx32_gcc" .. "/obj")
  343. libdirs { _libDir .. "lib/osx32_gcc" }
  344. buildoptions {
  345. "-m32",
  346. }
  347. configuration { "osx", "x64" }
  348. targetdir (_buildDir .. "osx64_gcc" .. "/bin")
  349. objdir (_buildDir .. "osx64_gcc" .. "/obj")
  350. libdirs { _libDir .. "lib/osx64_gcc" }
  351. buildoptions {
  352. "-m64",
  353. }
  354. configuration { "osx" }
  355. buildoptions {
  356. "-U__STRICT_ANSI__",
  357. "-Wfatal-errors",
  358. "-Wunused-value",
  359. "-msse2",
  360. }
  361. includedirs { bxDir .. "include/compat/osx" }
  362. configuration { "qnx-arm" }
  363. targetdir (_buildDir .. "qnx-arm" .. "/bin")
  364. objdir (_buildDir .. "qnx-arm" .. "/obj")
  365. libdirs { _libDir .. "lib/qnx-arm" }
  366. -- includedirs { bxDir .. "include/compat/qnx" }
  367. buildoptions {
  368. "-std=c++0x",
  369. "-U__STRICT_ANSI__",
  370. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  371. }
  372. configuration {} -- reset configuration
  373. end