toolchain.lua 11 KB

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