toolchain.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. --
  2. -- Copyright 2010-2012 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. { "emscripten", "Emscripten" },
  13. { "linux", "Linux" },
  14. { "mingw", "MinGW" },
  15. { "nacl", "Native Client" },
  16. { "pnacl", "Native Client - PNaCl" },
  17. }
  18. }
  19. -- Avoid error when invoking premake4 --help.
  20. if (_ACTION == nil) then return end
  21. local XEDK = os.getenv("XEDK")
  22. if not XEDK then XEDK = "<you must install XBOX SDK>" end
  23. location (_buildDir .. "projects/" .. _ACTION)
  24. if _ACTION == "clean" then
  25. os.rmdir(BUILD_DIR)
  26. end
  27. if _ACTION == "gmake" then
  28. if nil == _OPTIONS["gcc"] then
  29. print("GCC flavor must be specified!")
  30. os.exit(1)
  31. end
  32. flags {
  33. "ExtraWarnings",
  34. }
  35. if "emscripten" == _OPTIONS["gcc"] then
  36. if not os.getenv("EMSCRIPTEN") then
  37. print("Set EMSCRIPTEN enviroment variables.")
  38. end
  39. premake.gcc.cc = "$(EMSCRIPTEN)/emcc"
  40. premake.gcc.cxx = "$(EMSCRIPTEN)/em++"
  41. premake.gcc.ar = "$(EMSCRIPTEN)/emar"
  42. location (_buildDir .. "projects/" .. _ACTION .. "-emscripten")
  43. end
  44. if "linux" == _OPTIONS["gcc"] then
  45. location (_buildDir .. "projects/" .. _ACTION .. "-linux")
  46. end
  47. if "mingw" == _OPTIONS["gcc"] then
  48. premake.gcc.cc = "$(MINGW)/bin/mingw32-gcc"
  49. premake.gcc.cxx = "$(MINGW)/bin/mingw32-g++"
  50. premake.gcc.ar = "$(MINGW)/bin/ar"
  51. location (_buildDir .. "projects/" .. _ACTION .. "-mingw")
  52. end
  53. if "nacl" == _OPTIONS["gcc"] then
  54. if not os.getenv("NACL") then
  55. print("Set NACL enviroment variables.")
  56. end
  57. premake.gcc.cc = "$(NACL)/bin/x86_64-nacl-gcc"
  58. premake.gcc.cxx = "$(NACL)/bin/x86_64-nacl-g++"
  59. premake.gcc.ar = "$(NACL)/bin/x86_64-nacl-ar"
  60. location (_buildDir .. "projects/" .. _ACTION .. "-nacl")
  61. end
  62. if "pnacl" == _OPTIONS["gcc"] then
  63. if not os.getenv("PNACL") then
  64. print("Set PNACL enviroment variables.")
  65. end
  66. premake.gcc.cc = "$(PNACL)/bin/pnacl-clang"
  67. premake.gcc.cxx = "$(PNACL)/bin/pnacl-clang++"
  68. premake.gcc.ar = "$(PNACL)/bin/pnacl-ar"
  69. location (_buildDir .. "projects/" .. _ACTION .. "-pnacl")
  70. end
  71. end
  72. flags {
  73. "StaticRuntime",
  74. "NoMinimalRebuild",
  75. "NoPCH",
  76. "NativeWChar",
  77. "NoRTTI",
  78. "NoExceptions",
  79. "NoEditAndContinue",
  80. "Symbols",
  81. }
  82. defines {
  83. "__STDC_LIMIT_MACROS",
  84. "__STDC_FORMAT_MACROS",
  85. "__STDC_CONSTANT_MACROS",
  86. }
  87. configuration "Debug"
  88. targetsuffix "Debug"
  89. configuration "Release"
  90. flags {
  91. "OptimizeSpeed",
  92. }
  93. targetsuffix "Release"
  94. configuration { "vs*" }
  95. includedirs { bxDir .. "include/compat/msvc" }
  96. defines {
  97. "WIN32",
  98. "_WIN32",
  99. "_HAS_EXCEPTIONS=0",
  100. "_HAS_ITERATOR_DEBUGGING=0",
  101. "_SCL_SECURE=0",
  102. "_SECURE_SCL=0",
  103. "_SCL_SECURE_NO_WARNINGS",
  104. "_CRT_SECURE_NO_WARNINGS",
  105. "_CRT_SECURE_NO_DEPRECATE",
  106. }
  107. buildoptions {
  108. "/Oy-", -- Suppresses creation of frame pointers on the call stack.
  109. "/Ob2", -- The Inline Function Expansion
  110. }
  111. configuration { "x32", "vs*" }
  112. targetdir (_buildDir .. "win32_" .. _ACTION .. "/bin")
  113. objdir (_buildDir .. "win32_" .. _ACTION .. "/obj")
  114. libdirs {
  115. _libDir .. "lib/win32_" .. _ACTION,
  116. "$(DXSDK_DIR)/lib/x86",
  117. }
  118. configuration { "x64", "vs*" }
  119. defines { "_WIN64" }
  120. targetdir (_buildDir .. "win64_" .. _ACTION .. "/bin")
  121. objdir (_buildDir .. "win64_" .. _ACTION .. "/obj")
  122. libdirs {
  123. _libDir .. "lib/win64_" .. _ACTION,
  124. "$(DXSDK_DIR)/lib/x64",
  125. }
  126. configuration { "mingw" }
  127. defines { "WIN32" }
  128. includedirs { bxDir .. "include/compat/mingw" }
  129. buildoptions {
  130. "-std=c++0x",
  131. "-U__STRICT_ANSI__",
  132. "-Wunused-value",
  133. "-fdata-sections",
  134. "-ffunction-sections",
  135. }
  136. linkoptions {
  137. "-Wl,--gc-sections",
  138. }
  139. configuration { "x32", "mingw" }
  140. targetdir (_buildDir .. "win32_mingw" .. "/bin")
  141. objdir (_buildDir .. "win32_mingw" .. "/obj")
  142. libdirs {
  143. _libDir .. "lib/win32_mingw",
  144. "$(DXSDK_DIR)/lib/x86",
  145. }
  146. buildoptions { "-m32" }
  147. configuration { "x64", "mingw" }
  148. targetdir (_buildDir .. "win64_mingw" .. "/bin")
  149. objdir (_buildDir .. "win64_mingw" .. "/obj")
  150. libdirs {
  151. _libDir .. "lib/win64_mingw",
  152. "$(DXSDK_DIR)/lib/x64",
  153. }
  154. buildoptions { "-m64" }
  155. configuration { "linux" }
  156. buildoptions {
  157. "-std=c++0x",
  158. "-U__STRICT_ANSI__",
  159. "-Wunused-value",
  160. "-mfpmath=sse", -- force SSE to get 32-bit and 64-bit builds deterministic.
  161. "-msse2",
  162. }
  163. links {
  164. "rt",
  165. }
  166. linkoptions {
  167. "-Wl,--gc-sections",
  168. }
  169. configuration { "linux", "x32" }
  170. targetdir (_buildDir .. "linux32_gcc" .. "/bin")
  171. objdir (_buildDir .. "linux32_gcc" .. "/obj")
  172. libdirs { _libDir .. "lib/linux32_gcc" }
  173. buildoptions {
  174. "-m32",
  175. }
  176. configuration { "linux", "x64" }
  177. targetdir (_buildDir .. "linux64_gcc" .. "/bin")
  178. objdir (_buildDir .. "linux64_gcc" .. "/obj")
  179. libdirs { _libDir .. "lib/linux64_gcc" }
  180. buildoptions {
  181. "-m64",
  182. }
  183. configuration { "emscripten" }
  184. targetdir (_buildDir .. "emscripten" .. "/bin")
  185. objdir (_buildDir .. "emscripten" .. "/obj")
  186. libdirs { _libDir .. "lib/emscripten" }
  187. includedirs { "$(EMSCRIPTEN)/system/include" }
  188. buildoptions {
  189. "-pthread",
  190. }
  191. configuration { "nacl" }
  192. defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600" }
  193. includedirs { bxDir .. "include/compat/nacl" }
  194. buildoptions {
  195. "-std=c++0x",
  196. "-U__STRICT_ANSI__",
  197. "-pthread",
  198. "-fno-stack-protector",
  199. "-fdiagnostics-show-option",
  200. "-Wunused-value",
  201. "-fdata-sections",
  202. "-ffunction-sections",
  203. "-mfpmath=sse", -- force SSE to get 32-bit and 64-bit builds deterministic.
  204. "-msse2",
  205. -- "-fmerge-all-constants",
  206. }
  207. linkoptions {
  208. "-Wl,--gc-sections",
  209. }
  210. configuration { "x32", "nacl" }
  211. targetdir (_buildDir .. "nacl-x86" .. "/bin")
  212. objdir (_buildDir .. "nacl-x86" .. "/obj")
  213. libdirs { _libDir .. "lib/nacl-x86" }
  214. linkoptions { "-melf32_nacl" }
  215. configuration { "x64", "nacl" }
  216. targetdir (_buildDir .. "nacl-x64" .. "/bin")
  217. objdir (_buildDir .. "nacl-x64" .. "/obj")
  218. libdirs { _libDir .. "lib/nacl-x64" }
  219. linkoptions { "-melf64_nacl" }
  220. configuration { "pnacl" }
  221. defines { "_BSD_SOURCE=1", "_POSIX_C_SOURCE=199506", "_XOPEN_SOURCE=600", "__native_client__", "__LITTLE_ENDIAN__" }
  222. includedirs { bxDir .. "include/compat/nacl" }
  223. buildoptions {
  224. "-std=c++0x",
  225. "-U__STRICT_ANSI__",
  226. "-fno-stack-protector",
  227. "-fdiagnostics-show-option",
  228. "-Wunused-value",
  229. "-fdata-sections",
  230. "-ffunction-sections",
  231. }
  232. targetdir (_buildDir .. "pnacl" .. "/bin")
  233. objdir (_buildDir .. "pnacl" .. "/obj")
  234. libdirs { _libDir .. "lib/pnacl" }
  235. includedirs { "$(PNACL)/sysroot/include" }
  236. configuration { "Xbox360" }
  237. targetdir (_buildDir .. "xbox360" .. "/bin")
  238. objdir (_buildDir .. "xbox360" .. "/obj")
  239. includedirs { bxDir .. "include/compat/msvc" }
  240. libdirs { _libDir .. "lib/xbox360" }
  241. defines {
  242. "NOMINMAX",
  243. "_XBOX",
  244. }
  245. configuration { "macosx" }
  246. buildoptions {
  247. "-U__STRICT_ANSI__",
  248. "-Wunused-value",
  249. "-msse2",
  250. }
  251. includedirs { bxDir .. "include/compat/osx" }
  252. targetdir (_buildDir .. "osx" .. "/bin")
  253. objdir (_buildDir .. "osx" .. "/obj")
  254. libdirs { _libDir .. "lib/osx" }
  255. configuration {} -- reset configuration
  256. end