toolchain.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. }
  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" }
  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" }
  276. defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600" }
  277. includedirs { bxDir .. "include/compat/nacl" }
  278. buildoptions {
  279. "-std=c++0x",
  280. "-U__STRICT_ANSI__",
  281. "-pthread",
  282. "-fno-stack-protector",
  283. "-fdiagnostics-show-option",
  284. "-Wunused-value",
  285. "-fdata-sections",
  286. "-ffunction-sections",
  287. "-mfpmath=sse", -- force SSE to get 32-bit and 64-bit builds deterministic.
  288. "-msse2",
  289. -- "-fmerge-all-constants",
  290. }
  291. linkoptions {
  292. "-Wl,--gc-sections",
  293. }
  294. configuration { "x32", "nacl" }
  295. targetdir (_buildDir .. "nacl-x86" .. "/bin")
  296. objdir (_buildDir .. "nacl-x86" .. "/obj")
  297. libdirs { _libDir .. "lib/nacl-x86" }
  298. linkoptions { "-melf32_nacl" }
  299. configuration { "x64", "nacl" }
  300. targetdir (_buildDir .. "nacl-x64" .. "/bin")
  301. objdir (_buildDir .. "nacl-x64" .. "/obj")
  302. libdirs { _libDir .. "lib/nacl-x64" }
  303. linkoptions { "-melf64_nacl" }
  304. configuration { "nacl-arm" }
  305. defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600", "__native_client__", "__LITTLE_ENDIAN__" }
  306. includedirs { bxDir .. "include/compat/nacl" }
  307. buildoptions {
  308. "-std=c++0x",
  309. "-U__STRICT_ANSI__",
  310. "-fno-stack-protector",
  311. "-fdiagnostics-show-option",
  312. "-Wunused-value",
  313. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  314. "-fdata-sections",
  315. "-ffunction-sections",
  316. }
  317. targetdir (_buildDir .. "nacl-arm" .. "/bin")
  318. objdir (_buildDir .. "nacl-arm" .. "/obj")
  319. libdirs { _libDir .. "lib/nacl-arm" }
  320. configuration { "pnacl" }
  321. defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600", "__native_client__", "__LITTLE_ENDIAN__" }
  322. includedirs { bxDir .. "include/compat/nacl" }
  323. buildoptions {
  324. "-std=c++0x",
  325. "-U__STRICT_ANSI__",
  326. "-fno-stack-protector",
  327. "-fdiagnostics-show-option",
  328. "-Wunused-value",
  329. "-fdata-sections",
  330. "-ffunction-sections",
  331. }
  332. targetdir (_buildDir .. "pnacl" .. "/bin")
  333. objdir (_buildDir .. "pnacl" .. "/obj")
  334. libdirs { _libDir .. "lib/pnacl" }
  335. includedirs { "$(PNACL)/sysroot/include" }
  336. configuration { "Xbox360" }
  337. targetdir (_buildDir .. "xbox360" .. "/bin")
  338. objdir (_buildDir .. "xbox360" .. "/obj")
  339. includedirs { bxDir .. "include/compat/msvc" }
  340. libdirs { _libDir .. "lib/xbox360" }
  341. defines {
  342. "NOMINMAX",
  343. "_XBOX",
  344. }
  345. configuration { "osx", "x32" }
  346. targetdir (_buildDir .. "osx32_gcc" .. "/bin")
  347. objdir (_buildDir .. "osx32_gcc" .. "/obj")
  348. libdirs { _libDir .. "lib/osx32_gcc" }
  349. buildoptions {
  350. "-m32",
  351. }
  352. configuration { "osx", "x64" }
  353. targetdir (_buildDir .. "osx64_gcc" .. "/bin")
  354. objdir (_buildDir .. "osx64_gcc" .. "/obj")
  355. libdirs { _libDir .. "lib/osx64_gcc" }
  356. buildoptions {
  357. "-m64",
  358. }
  359. configuration { "osx" }
  360. buildoptions {
  361. "-U__STRICT_ANSI__",
  362. "-Wfatal-errors",
  363. "-Wunused-value",
  364. "-msse2",
  365. }
  366. includedirs { bxDir .. "include/compat/osx" }
  367. configuration { "qnx-arm" }
  368. targetdir (_buildDir .. "qnx-arm" .. "/bin")
  369. objdir (_buildDir .. "qnx-arm" .. "/obj")
  370. libdirs { _libDir .. "lib/qnx-arm" }
  371. -- includedirs { bxDir .. "include/compat/qnx" }
  372. buildoptions {
  373. "-std=c++0x",
  374. "-U__STRICT_ANSI__",
  375. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  376. }
  377. configuration {} -- reset configuration
  378. end
  379. function strip()
  380. configuration { "android*", "Release" }
  381. postbuildcommands {
  382. "@echo Stripping symbols.",
  383. "@$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-strip -s \"$(TARGET)\""
  384. }
  385. configuration { "linux", "Release" }
  386. postbuildcommands {
  387. "@echo Stripping symbols.",
  388. "@strip -s \"$(TARGET)\""
  389. }
  390. configuration { "nacl", "Release" }
  391. postbuildcommands {
  392. "@echo Stripping symbols.",
  393. "@$(NACL)/bin/x86_64-nacl-strip -s \"$(TARGET)\""
  394. }
  395. configuration {} -- reset configuration
  396. end