toolchain.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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-experimental", "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-experimental" == _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_SDK_ROOT") then
  66. print("Set NACL_SDK_ROOT enviroment variables.")
  67. end
  68. premake.gcc.cc = "$(NACL_SDK_ROOT)/toolchain/win_x86_newlib/bin/x86_64-nacl-gcc"
  69. premake.gcc.cxx = "$(NACL_SDK_ROOT)/toolchain/win_x86_newlib/bin/x86_64-nacl-g++"
  70. premake.gcc.ar = "$(NACL_SDK_ROOT)/toolchain/win_x86_newlib/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_SDK_ROOT") then
  75. print("Set NACL_SDK_ROOT enviroment variables.")
  76. end
  77. premake.gcc.cc = "$(NACL_SDK_ROOT)/toolchain/win_arm_newlib/bin/arm-nacl-gcc"
  78. premake.gcc.cxx = "$(NACL_SDK_ROOT)/toolchain/win_arm_newlib/bin/arm-nacl-g++"
  79. premake.gcc.ar = "$(NACL_SDK_ROOT)/toolchain/win_arm_newlib/bin/arm-nacl-ar"
  80. location (_buildDir .. "projects/" .. _ACTION .. "-nacl-arm")
  81. end
  82. if "pnacl" == _OPTIONS["gcc"] then
  83. if not os.getenv("NACL_SDK_ROOT") then
  84. print("Set NACL_SDK_ROOT enviroment variables.")
  85. end
  86. premake.gcc.cc = "$(NACL_SDK_ROOT)/toolchain/win_x86_pnacl/newlib/bin/pnacl-clang"
  87. premake.gcc.cxx = "$(NACL_SDK_ROOT)/toolchain/win_x86_pnacl/newlib/bin/pnacl-clang++"
  88. premake.gcc.ar = "$(NACL_SDK_ROOT)/toolchain/win_x86_pnacl/newlib/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. }
  150. configuration { "x64", "vs*" }
  151. defines { "_WIN64" }
  152. targetdir (_buildDir .. "win64_" .. _ACTION .. "/bin")
  153. objdir (_buildDir .. "win64_" .. _ACTION .. "/obj")
  154. libdirs {
  155. _libDir .. "lib/win64_" .. _ACTION,
  156. "$(DXSDK_DIR)/lib/x64",
  157. }
  158. configuration { "mingw" }
  159. defines { "WIN32" }
  160. includedirs { bxDir .. "include/compat/mingw" }
  161. buildoptions {
  162. "-std=c++0x",
  163. "-U__STRICT_ANSI__",
  164. "-Wunused-value",
  165. "-fdata-sections",
  166. "-ffunction-sections",
  167. }
  168. linkoptions {
  169. "-Wl,--gc-sections",
  170. }
  171. configuration { "x32", "mingw" }
  172. targetdir (_buildDir .. "win32_mingw" .. "/bin")
  173. objdir (_buildDir .. "win32_mingw" .. "/obj")
  174. libdirs {
  175. _libDir .. "lib/win32_mingw",
  176. "$(DXSDK_DIR)/lib/x86",
  177. }
  178. buildoptions { "-m32" }
  179. configuration { "x64", "mingw" }
  180. targetdir (_buildDir .. "win64_mingw" .. "/bin")
  181. objdir (_buildDir .. "win64_mingw" .. "/obj")
  182. libdirs {
  183. _libDir .. "lib/win64_mingw",
  184. "$(DXSDK_DIR)/lib/x64",
  185. "$(GLES_X64_DIR)",
  186. }
  187. buildoptions { "-m64" }
  188. configuration { "linux" }
  189. buildoptions {
  190. "-std=c++0x",
  191. "-U__STRICT_ANSI__",
  192. "-Wunused-value",
  193. "-mfpmath=sse", -- force SSE to get 32-bit and 64-bit builds deterministic.
  194. "-msse2",
  195. }
  196. links {
  197. "rt",
  198. }
  199. linkoptions {
  200. "-Wl,--gc-sections",
  201. }
  202. configuration { "linux", "x32" }
  203. targetdir (_buildDir .. "linux32_gcc" .. "/bin")
  204. objdir (_buildDir .. "linux32_gcc" .. "/obj")
  205. libdirs { _libDir .. "lib/linux32_gcc" }
  206. buildoptions {
  207. "-m32",
  208. }
  209. configuration { "linux", "x64" }
  210. targetdir (_buildDir .. "linux64_gcc" .. "/bin")
  211. objdir (_buildDir .. "linux64_gcc" .. "/obj")
  212. libdirs { _libDir .. "lib/linux64_gcc" }
  213. buildoptions {
  214. "-m64",
  215. }
  216. configuration { "android-arm" }
  217. targetdir (_buildDir .. "android-arm" .. "/bin")
  218. objdir (_buildDir .. "android-arm" .. "/obj")
  219. flags {
  220. "NoImportLib",
  221. }
  222. libdirs {
  223. _libDir .. "lib/android-arm",
  224. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a",
  225. }
  226. includedirs {
  227. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.7/include",
  228. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include",
  229. "$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
  230. }
  231. linkoptions {
  232. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  233. "-nostdlib",
  234. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtbegin_so.o",
  235. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtend_so.o",
  236. "-march=armv7-a",
  237. -- "-Wl,-shared,-Bsymbolic",
  238. -- "-Wl,--gc-sections",
  239. "-Wl,--fix-cortex-a8",
  240. -- "-Wl,--no-undefined",
  241. "-static-libgcc",
  242. "-no-canonical-prefixes",
  243. "-Wl,--no-undefined",
  244. "-Wl,-z,noexecstack",
  245. "-Wl,-z,relro",
  246. "-Wl,-z,now",
  247. }
  248. links {
  249. "c",
  250. "m",
  251. "android",
  252. "log",
  253. "gnustl_static",
  254. "gcc",
  255. }
  256. buildoptions {
  257. "-std=c++0x",
  258. "-U__STRICT_ANSI__",
  259. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  260. "-fpic",
  261. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  262. "-mthumb",
  263. "-march=armv7-a",
  264. "-mfloat-abi=softfp",
  265. "-mfpu=vfpv3-d16",
  266. }
  267. configuration { "emscripten-experimental" }
  268. targetdir (_buildDir .. "emscripten" .. "/bin")
  269. objdir (_buildDir .. "emscripten" .. "/obj")
  270. libdirs { _libDir .. "lib/emscripten" }
  271. includedirs { "$(EMSCRIPTEN)/system/include" }
  272. buildoptions {
  273. "-pthread",
  274. }
  275. configuration { "nacl or nacl-arm or pnacl" }
  276. includedirs {
  277. "$(NACL_SDK_ROOT)/include",
  278. bxDir .. "include/compat/nacl",
  279. }
  280. configuration { "nacl" }
  281. buildoptions {
  282. "-std=c++0x",
  283. "-U__STRICT_ANSI__",
  284. "-pthread",
  285. "-fno-stack-protector",
  286. "-fdiagnostics-show-option",
  287. "-Wunused-value",
  288. "-fdata-sections",
  289. "-ffunction-sections",
  290. "-mfpmath=sse", -- force SSE to get 32-bit and 64-bit builds deterministic.
  291. "-msse2",
  292. -- "-fmerge-all-constants",
  293. }
  294. linkoptions {
  295. "-Wl,--gc-sections",
  296. }
  297. configuration { "x32", "nacl" }
  298. targetdir (_buildDir .. "nacl-x86" .. "/bin")
  299. objdir (_buildDir .. "nacl-x86" .. "/obj")
  300. libdirs { _libDir .. "lib/nacl-x86" }
  301. linkoptions { "-melf32_nacl" }
  302. configuration { "x64", "nacl" }
  303. targetdir (_buildDir .. "nacl-x64" .. "/bin")
  304. objdir (_buildDir .. "nacl-x64" .. "/obj")
  305. libdirs { _libDir .. "lib/nacl-x64" }
  306. linkoptions { "-melf64_nacl" }
  307. configuration { "nacl-arm" }
  308. buildoptions {
  309. "-std=c++0x",
  310. "-U__STRICT_ANSI__",
  311. "-fno-stack-protector",
  312. "-fdiagnostics-show-option",
  313. "-Wunused-value",
  314. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  315. "-fdata-sections",
  316. "-ffunction-sections",
  317. }
  318. targetdir (_buildDir .. "nacl-arm" .. "/bin")
  319. objdir (_buildDir .. "nacl-arm" .. "/obj")
  320. libdirs { _libDir .. "lib/nacl-arm" }
  321. configuration { "pnacl" }
  322. buildoptions {
  323. "-std=c++0x",
  324. "-U__STRICT_ANSI__",
  325. "-fno-stack-protector",
  326. "-fdiagnostics-show-option",
  327. "-Wunused-value",
  328. "-fdata-sections",
  329. "-ffunction-sections",
  330. }
  331. targetdir (_buildDir .. "pnacl" .. "/bin")
  332. objdir (_buildDir .. "pnacl" .. "/obj")
  333. libdirs { _libDir .. "lib/pnacl" }
  334. includedirs { "$(PNACL)/sysroot/include" }
  335. configuration { "Xbox360" }
  336. targetdir (_buildDir .. "xbox360" .. "/bin")
  337. objdir (_buildDir .. "xbox360" .. "/obj")
  338. includedirs { bxDir .. "include/compat/msvc" }
  339. libdirs { _libDir .. "lib/xbox360" }
  340. defines {
  341. "NOMINMAX",
  342. "_XBOX",
  343. }
  344. configuration { "osx", "x32" }
  345. targetdir (_buildDir .. "osx32_gcc" .. "/bin")
  346. objdir (_buildDir .. "osx32_gcc" .. "/obj")
  347. libdirs { _libDir .. "lib/osx32_gcc" }
  348. buildoptions {
  349. "-m32",
  350. }
  351. configuration { "osx", "x64" }
  352. targetdir (_buildDir .. "osx64_gcc" .. "/bin")
  353. objdir (_buildDir .. "osx64_gcc" .. "/obj")
  354. libdirs { _libDir .. "lib/osx64_gcc" }
  355. buildoptions {
  356. "-m64",
  357. }
  358. configuration { "osx" }
  359. buildoptions {
  360. "-U__STRICT_ANSI__",
  361. "-Wfatal-errors",
  362. "-Wunused-value",
  363. "-msse2",
  364. }
  365. includedirs { bxDir .. "include/compat/osx" }
  366. configuration { "qnx-arm" }
  367. targetdir (_buildDir .. "qnx-arm" .. "/bin")
  368. objdir (_buildDir .. "qnx-arm" .. "/obj")
  369. libdirs { _libDir .. "lib/qnx-arm" }
  370. -- includedirs { bxDir .. "include/compat/qnx" }
  371. buildoptions {
  372. "-std=c++0x",
  373. "-U__STRICT_ANSI__",
  374. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  375. }
  376. configuration {} -- reset configuration
  377. end
  378. function strip()
  379. configuration { "android*", "Release" }
  380. postbuildcommands {
  381. "@echo Stripping symbols.",
  382. "@$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-strip -s \"$(TARGET)\""
  383. }
  384. configuration { "linux", "Release" }
  385. postbuildcommands {
  386. "@echo Stripping symbols.",
  387. "@strip -s \"$(TARGET)\""
  388. }
  389. configuration { "nacl", "Release" }
  390. postbuildcommands {
  391. "@echo Stripping symbols.",
  392. "@$(NACL_SDK_ROOT)/toolchain/win_x86_newlib/bin/x86_64-nacl-strip -s \"$(TARGET)\""
  393. }
  394. configuration { "nacl-arm", "Release" }
  395. postbuildcommands {
  396. "@echo Stripping symbols.",
  397. "@$(NACL_SDK_ROOT)/toolchain/win_arm_newlib/bin/arm-nacl-strip -s \"$(TARGET)\""
  398. }
  399. configuration { "pnacl", "Release" }
  400. postbuildcommands {
  401. "@echo Stripping symbols.",
  402. "@$(NACL_SDK_ROOT)/toolchain/win_x86_pnacl/newlib/bin/pnacl-strip -s \"$(TARGET)\""
  403. }
  404. configuration {} -- reset configuration
  405. end