2
0

toolchain.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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", "OSX" },
  20. { "ios", "iOS" },
  21. { "qnx-arm", "QNX/Blackberry - ARM" },
  22. }
  23. }
  24. -- Avoid error when invoking premake4 --help.
  25. if (_ACTION == nil) then return end
  26. location (_buildDir .. "projects/" .. _ACTION)
  27. if _ACTION == "clean" then
  28. os.rmdir(BUILD_DIR)
  29. end
  30. if _ACTION == "gmake" then
  31. if nil == _OPTIONS["gcc"] then
  32. print("GCC flavor must be specified!")
  33. os.exit(1)
  34. end
  35. flags {
  36. "ExtraWarnings",
  37. }
  38. if "android-arm" == _OPTIONS["gcc"] then
  39. if not os.getenv("ANDROID_NDK_ARM") or not os.getenv("ANDROID_NDK_ROOT") then
  40. print("Set ANDROID_NDK_ARM and ANDROID_NDK_ROOT envrionment variables.")
  41. end
  42. premake.gcc.cc = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-gcc"
  43. premake.gcc.cxx = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-g++"
  44. premake.gcc.ar = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-ar"
  45. location (_buildDir .. "projects/" .. _ACTION .. "-android-arm")
  46. end
  47. if "emscripten-experimental" == _OPTIONS["gcc"] then
  48. if not os.getenv("EMSCRIPTEN") then
  49. print("Set EMSCRIPTEN enviroment variables.")
  50. end
  51. premake.gcc.cc = "$(EMSCRIPTEN)/emcc"
  52. premake.gcc.cxx = "$(EMSCRIPTEN)/em++"
  53. premake.gcc.ar = "$(EMSCRIPTEN)/emar"
  54. location (_buildDir .. "projects/" .. _ACTION .. "-emscripten")
  55. end
  56. if "linux" == _OPTIONS["gcc"] then
  57. location (_buildDir .. "projects/" .. _ACTION .. "-linux")
  58. end
  59. if "mingw" == _OPTIONS["gcc"] then
  60. premake.gcc.cc = "$(MINGW)/bin/mingw32-gcc"
  61. premake.gcc.cxx = "$(MINGW)/bin/mingw32-g++"
  62. premake.gcc.ar = "$(MINGW)/bin/ar"
  63. location (_buildDir .. "projects/" .. _ACTION .. "-mingw")
  64. end
  65. if "nacl" == _OPTIONS["gcc"] then
  66. if not os.getenv("NACL_SDK_ROOT") then
  67. print("Set NACL_SDK_ROOT enviroment variables.")
  68. end
  69. premake.gcc.cc = "$(NACL_SDK_ROOT)/toolchain/win_x86_newlib/bin/x86_64-nacl-gcc"
  70. premake.gcc.cxx = "$(NACL_SDK_ROOT)/toolchain/win_x86_newlib/bin/x86_64-nacl-g++"
  71. premake.gcc.ar = "$(NACL_SDK_ROOT)/toolchain/win_x86_newlib/bin/x86_64-nacl-ar"
  72. location (_buildDir .. "projects/" .. _ACTION .. "-nacl")
  73. end
  74. if "nacl-arm" == _OPTIONS["gcc"] then
  75. if not os.getenv("NACL_SDK_ROOT") then
  76. print("Set NACL_SDK_ROOT enviroment variables.")
  77. end
  78. premake.gcc.cc = "$(NACL_SDK_ROOT)/toolchain/win_arm_newlib/bin/arm-nacl-gcc"
  79. premake.gcc.cxx = "$(NACL_SDK_ROOT)/toolchain/win_arm_newlib/bin/arm-nacl-g++"
  80. premake.gcc.ar = "$(NACL_SDK_ROOT)/toolchain/win_arm_newlib/bin/arm-nacl-ar"
  81. location (_buildDir .. "projects/" .. _ACTION .. "-nacl-arm")
  82. end
  83. if "pnacl" == _OPTIONS["gcc"] then
  84. if not os.getenv("NACL_SDK_ROOT") then
  85. print("Set NACL_SDK_ROOT enviroment variables.")
  86. end
  87. premake.gcc.cc = "$(NACL_SDK_ROOT)/toolchain/win_x86_pnacl/newlib/bin/pnacl-clang"
  88. premake.gcc.cxx = "$(NACL_SDK_ROOT)/toolchain/win_x86_pnacl/newlib/bin/pnacl-clang++"
  89. premake.gcc.ar = "$(NACL_SDK_ROOT)/toolchain/win_x86_pnacl/newlib/bin/pnacl-ar"
  90. location (_buildDir .. "projects/" .. _ACTION .. "-pnacl")
  91. end
  92. if "osx" == _OPTIONS["gcc"] then
  93. location (_buildDir .. "projects/" .. _ACTION .. "-osx")
  94. end
  95. if "ios" == _OPTIONS["gcc"] then
  96. premake.gcc.cc = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2"
  97. premake.gcc.cxx = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-g++-4.2"
  98. premake.gcc.ar = "ar"
  99. location (_buildDir .. "projects/" .. _ACTION .. "-ios")
  100. end
  101. if "qnx-arm" == _OPTIONS["gcc"] then
  102. if not os.getenv("QNX_HOST") then
  103. print("Set QNX_HOST enviroment variables.")
  104. end
  105. premake.gcc.cc = "$(QNX_HOST)/usr/bin/arm-unknown-nto-qnx8.0.0eabi-gcc"
  106. premake.gcc.cxx = "$(QNX_HOST)/usr/bin/arm-unknown-nto-qnx8.0.0eabi-g++"
  107. premake.gcc.ar = "$(QNX_HOST)/usr/bin/arm-unknown-nto-qnx8.0.0eabi-ar"
  108. location (_buildDir .. "projects/" .. _ACTION .. "-qnx-arm")
  109. end
  110. end
  111. flags {
  112. "StaticRuntime",
  113. "NoMinimalRebuild",
  114. "NoPCH",
  115. "NativeWChar",
  116. "NoRTTI",
  117. "NoExceptions",
  118. "NoEditAndContinue",
  119. "Symbols",
  120. }
  121. defines {
  122. "__STDC_LIMIT_MACROS",
  123. "__STDC_FORMAT_MACROS",
  124. "__STDC_CONSTANT_MACROS",
  125. }
  126. configuration "Debug"
  127. targetsuffix "Debug"
  128. configuration "Release"
  129. flags {
  130. "OptimizeSpeed",
  131. }
  132. targetsuffix "Release"
  133. configuration { "vs*" }
  134. includedirs { bxDir .. "include/compat/msvc" }
  135. defines {
  136. "WIN32",
  137. "_WIN32",
  138. "_HAS_EXCEPTIONS=0",
  139. "_HAS_ITERATOR_DEBUGGING=0",
  140. "_SCL_SECURE=0",
  141. "_SECURE_SCL=0",
  142. "_SCL_SECURE_NO_WARNINGS",
  143. "_CRT_SECURE_NO_WARNINGS",
  144. "_CRT_SECURE_NO_DEPRECATE",
  145. }
  146. buildoptions {
  147. "/Oy-", -- Suppresses creation of frame pointers on the call stack.
  148. "/Ob2", -- The Inline Function Expansion
  149. }
  150. configuration { "x32", "vs*" }
  151. targetdir (_buildDir .. "win32_" .. _ACTION .. "/bin")
  152. objdir (_buildDir .. "win32_" .. _ACTION .. "/obj")
  153. libdirs {
  154. _libDir .. "lib/win32_" .. _ACTION,
  155. "$(DXSDK_DIR)/lib/x86",
  156. }
  157. configuration { "x64", "vs*" }
  158. defines { "_WIN64" }
  159. targetdir (_buildDir .. "win64_" .. _ACTION .. "/bin")
  160. objdir (_buildDir .. "win64_" .. _ACTION .. "/obj")
  161. libdirs {
  162. _libDir .. "lib/win64_" .. _ACTION,
  163. "$(DXSDK_DIR)/lib/x64",
  164. }
  165. configuration { "mingw" }
  166. defines { "WIN32" }
  167. includedirs { bxDir .. "include/compat/mingw" }
  168. buildoptions {
  169. "-std=c++0x",
  170. "-U__STRICT_ANSI__",
  171. "-Wunused-value",
  172. "-fdata-sections",
  173. "-ffunction-sections",
  174. }
  175. linkoptions {
  176. "-Wl,--gc-sections",
  177. }
  178. configuration { "x32", "mingw" }
  179. targetdir (_buildDir .. "win32_mingw" .. "/bin")
  180. objdir (_buildDir .. "win32_mingw" .. "/obj")
  181. libdirs {
  182. _libDir .. "lib/win32_mingw",
  183. "$(DXSDK_DIR)/lib/x86",
  184. }
  185. buildoptions { "-m32" }
  186. configuration { "x64", "mingw" }
  187. targetdir (_buildDir .. "win64_mingw" .. "/bin")
  188. objdir (_buildDir .. "win64_mingw" .. "/obj")
  189. libdirs {
  190. _libDir .. "lib/win64_mingw",
  191. "$(DXSDK_DIR)/lib/x64",
  192. "$(GLES_X64_DIR)",
  193. }
  194. buildoptions { "-m64" }
  195. configuration { "linux" }
  196. buildoptions {
  197. "-std=c++0x",
  198. "-U__STRICT_ANSI__",
  199. "-Wunused-value",
  200. "-mfpmath=sse", -- force SSE to get 32-bit and 64-bit builds deterministic.
  201. "-msse2",
  202. }
  203. links {
  204. "rt",
  205. }
  206. linkoptions {
  207. "-Wl,--gc-sections",
  208. }
  209. configuration { "linux", "x32" }
  210. targetdir (_buildDir .. "linux32_gcc" .. "/bin")
  211. objdir (_buildDir .. "linux32_gcc" .. "/obj")
  212. libdirs { _libDir .. "lib/linux32_gcc" }
  213. buildoptions {
  214. "-m32",
  215. }
  216. configuration { "linux", "x64" }
  217. targetdir (_buildDir .. "linux64_gcc" .. "/bin")
  218. objdir (_buildDir .. "linux64_gcc" .. "/obj")
  219. libdirs { _libDir .. "lib/linux64_gcc" }
  220. buildoptions {
  221. "-m64",
  222. }
  223. configuration { "android-arm" }
  224. targetdir (_buildDir .. "android-arm" .. "/bin")
  225. objdir (_buildDir .. "android-arm" .. "/obj")
  226. flags {
  227. "NoImportLib",
  228. }
  229. libdirs {
  230. _libDir .. "lib/android-arm",
  231. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a",
  232. }
  233. includedirs {
  234. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.7/include",
  235. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include",
  236. "$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
  237. }
  238. linkoptions {
  239. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  240. "-nostdlib",
  241. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtbegin_so.o",
  242. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtend_so.o",
  243. "-march=armv7-a",
  244. -- "-Wl,-shared,-Bsymbolic",
  245. -- "-Wl,--gc-sections",
  246. "-Wl,--fix-cortex-a8",
  247. -- "-Wl,--no-undefined",
  248. "-static-libgcc",
  249. "-no-canonical-prefixes",
  250. "-Wl,--no-undefined",
  251. "-Wl,-z,noexecstack",
  252. "-Wl,-z,relro",
  253. "-Wl,-z,now",
  254. }
  255. links {
  256. "c",
  257. "m",
  258. "android",
  259. "log",
  260. "gnustl_static",
  261. "gcc",
  262. }
  263. buildoptions {
  264. "-std=c++0x",
  265. "-U__STRICT_ANSI__",
  266. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  267. "-fpic",
  268. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  269. "-mthumb",
  270. "-march=armv7-a",
  271. "-mfloat-abi=softfp",
  272. "-mfpu=vfpv3-d16",
  273. }
  274. configuration { "emscripten-experimental" }
  275. targetdir (_buildDir .. "emscripten" .. "/bin")
  276. objdir (_buildDir .. "emscripten" .. "/obj")
  277. libdirs { _libDir .. "lib/emscripten" }
  278. includedirs { "$(EMSCRIPTEN)/system/include" }
  279. buildoptions {
  280. "-pthread",
  281. }
  282. configuration { "nacl or nacl-arm or pnacl" }
  283. includedirs {
  284. "$(NACL_SDK_ROOT)/include",
  285. bxDir .. "include/compat/nacl",
  286. }
  287. configuration { "nacl" }
  288. buildoptions {
  289. "-std=c++0x",
  290. "-U__STRICT_ANSI__",
  291. "-pthread",
  292. "-fno-stack-protector",
  293. "-fdiagnostics-show-option",
  294. "-Wunused-value",
  295. "-fdata-sections",
  296. "-ffunction-sections",
  297. "-mfpmath=sse", -- force SSE to get 32-bit and 64-bit builds deterministic.
  298. "-msse2",
  299. -- "-fmerge-all-constants",
  300. }
  301. linkoptions {
  302. "-Wl,--gc-sections",
  303. }
  304. configuration { "x32", "nacl" }
  305. targetdir (_buildDir .. "nacl-x86" .. "/bin")
  306. objdir (_buildDir .. "nacl-x86" .. "/obj")
  307. libdirs { _libDir .. "lib/nacl-x86" }
  308. linkoptions { "-melf32_nacl" }
  309. configuration { "x64", "nacl" }
  310. targetdir (_buildDir .. "nacl-x64" .. "/bin")
  311. objdir (_buildDir .. "nacl-x64" .. "/obj")
  312. libdirs { _libDir .. "lib/nacl-x64" }
  313. linkoptions { "-melf64_nacl" }
  314. configuration { "nacl-arm" }
  315. buildoptions {
  316. "-std=c++0x",
  317. "-U__STRICT_ANSI__",
  318. "-fno-stack-protector",
  319. "-fdiagnostics-show-option",
  320. "-Wunused-value",
  321. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  322. "-fdata-sections",
  323. "-ffunction-sections",
  324. }
  325. targetdir (_buildDir .. "nacl-arm" .. "/bin")
  326. objdir (_buildDir .. "nacl-arm" .. "/obj")
  327. libdirs { _libDir .. "lib/nacl-arm" }
  328. configuration { "pnacl" }
  329. buildoptions {
  330. "-std=c++0x",
  331. "-U__STRICT_ANSI__",
  332. "-fno-stack-protector",
  333. "-fdiagnostics-show-option",
  334. "-Wunused-value",
  335. "-fdata-sections",
  336. "-ffunction-sections",
  337. }
  338. targetdir (_buildDir .. "pnacl" .. "/bin")
  339. objdir (_buildDir .. "pnacl" .. "/obj")
  340. libdirs { _libDir .. "lib/pnacl" }
  341. includedirs { "$(PNACL)/sysroot/include" }
  342. configuration { "Xbox360" }
  343. targetdir (_buildDir .. "xbox360" .. "/bin")
  344. objdir (_buildDir .. "xbox360" .. "/obj")
  345. includedirs { bxDir .. "include/compat/msvc" }
  346. libdirs { _libDir .. "lib/xbox360" }
  347. defines {
  348. "NOMINMAX",
  349. "_XBOX",
  350. }
  351. configuration { "osx", "x32" }
  352. targetdir (_buildDir .. "osx32_gcc" .. "/bin")
  353. objdir (_buildDir .. "osx32_gcc" .. "/obj")
  354. libdirs { _libDir .. "lib/osx32_gcc" }
  355. buildoptions {
  356. "-m32",
  357. }
  358. configuration { "osx", "x64" }
  359. targetdir (_buildDir .. "osx64_gcc" .. "/bin")
  360. objdir (_buildDir .. "osx64_gcc" .. "/obj")
  361. libdirs { _libDir .. "lib/osx64_gcc" }
  362. buildoptions {
  363. "-m64",
  364. }
  365. configuration { "osx" }
  366. buildoptions {
  367. "-U__STRICT_ANSI__",
  368. "-Wfatal-errors",
  369. "-Wunused-value",
  370. "-msse2",
  371. }
  372. includedirs { bxDir .. "include/compat/osx" }
  373. configuration { "ios" }
  374. targetdir (_buildDir .. "ios-arm" .. "/bin")
  375. objdir (_buildDir .. "ios-arm" .. "/obj")
  376. libdirs { _libDir .. "lib/ios-arm" }
  377. linkoptions {
  378. "--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk",
  379. "-march=armv7-a",
  380. "-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/lib/system",
  381. "-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks",
  382. "-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/PrivateFrameworks",
  383. }
  384. buildoptions {
  385. "--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk",
  386. "-mthumb",
  387. "-march=armv7-a",
  388. "-mfloat-abi=softfp",
  389. "-mfpu=neon",
  390. "-U__STRICT_ANSI__",
  391. "-Wfatal-errors",
  392. "-Wunused-value",
  393. }
  394. includedirs { bxDir .. "include/compat/osx" }
  395. configuration { "qnx-arm" }
  396. targetdir (_buildDir .. "qnx-arm" .. "/bin")
  397. objdir (_buildDir .. "qnx-arm" .. "/obj")
  398. libdirs { _libDir .. "lib/qnx-arm" }
  399. -- includedirs { bxDir .. "include/compat/qnx" }
  400. buildoptions {
  401. "-std=c++0x",
  402. "-U__STRICT_ANSI__",
  403. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  404. }
  405. configuration {} -- reset configuration
  406. end
  407. function strip()
  408. configuration { "android*", "Release" }
  409. postbuildcommands {
  410. "@echo Stripping symbols.",
  411. "@$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-strip -s \"$(TARGET)\""
  412. }
  413. configuration { "linux", "Release" }
  414. postbuildcommands {
  415. "@echo Stripping symbols.",
  416. "@strip -s \"$(TARGET)\""
  417. }
  418. configuration { "mingw", "Release" }
  419. postbuildcommands {
  420. "@echo Stripping symbols.",
  421. "@$(MINGW)/bin/strip -s \"$(TARGET)\""
  422. }
  423. configuration { "nacl", "Release" }
  424. postbuildcommands {
  425. "@echo Stripping symbols.",
  426. "@$(NACL_SDK_ROOT)/toolchain/win_x86_newlib/bin/x86_64-nacl-strip -s \"$(TARGET)\""
  427. }
  428. configuration { "nacl-arm", "Release" }
  429. postbuildcommands {
  430. "@echo Stripping symbols.",
  431. "@$(NACL_SDK_ROOT)/toolchain/win_arm_newlib/bin/arm-nacl-strip -s \"$(TARGET)\""
  432. }
  433. configuration { "pnacl", "Release" }
  434. postbuildcommands {
  435. "@echo Stripping symbols.",
  436. "@$(NACL_SDK_ROOT)/toolchain/win_x86_pnacl/newlib/bin/pnacl-strip -s \"$(TARGET)\""
  437. }
  438. configuration {} -- reset configuration
  439. end