toolchain.lua 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. --
  2. -- Copyright (c) 2012-2014 Daniele Bartolini and individual contributors.
  3. -- License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. --
  5. function toolchain(build_dir, lib_dir)
  6. newoption
  7. {
  8. trigger = "install-dir",
  9. value = "DIR",
  10. description = "Output directory"
  11. }
  12. newoption
  13. {
  14. trigger = "compiler",
  15. value = "COMPILER",
  16. description = "Choose compiler",
  17. allowed =
  18. {
  19. { "android-arm", "Android - ARM" },
  20. { "linux-gcc", "Linux (GCC compiler)" }
  21. }
  22. }
  23. if (_ACTION == nil) then return end
  24. location (build_dir .. "projects/" .. _ACTION)
  25. if _ACTION == "clean" then
  26. os.rmdir(BUILD_DIR)
  27. end
  28. if _ACTION == "gmake" then
  29. if nil == _OPTIONS["compiler"] then
  30. print("Choose a compiler!")
  31. os.exit(1)
  32. end
  33. if "linux-gcc" == _OPTIONS["compiler"] then
  34. if not os.is("linux") then print("Action not valid in current OS.") end
  35. if not os.getenv("PHYSX_SDK_LINUX") then
  36. print("Set PHYSX_SDK_LINUX environment variable.")
  37. end
  38. location(build_dir .. "projects/" .. "linux")
  39. end
  40. if "android-arm" == _OPTIONS["compiler"] then
  41. if not os.getenv("ANDROID_NDK_ROOT") then
  42. print("Set ANDROID_NDK_ROOT environment variable.")
  43. end
  44. if not os.getenv("ANDROID_NDK_ARM") then
  45. print("Set ANDROID_NDK_ARM environment variables.")
  46. end
  47. if not os.getenv("PHYSX_SDK_ANDROID") then
  48. print("Set PHYSX_SDK_ANDROID environment variable.")
  49. end
  50. premake.gcc.cc = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-gcc"
  51. premake.gcc.cxx = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-g++"
  52. premake.gcc.ar = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-ar"
  53. location(build_dir .. "projects/" .. "android")
  54. end
  55. end
  56. if _ACTION == "vs2012" then
  57. if not os.is("windows") then print("Action not valid in current OS.") end
  58. if not os.getenv("PHYSX_SDK_WINDOWS") then
  59. print("Set PHYSX_SDK_WINDOWS environment variable.")
  60. end
  61. if not os.getenv("DXSDK_DIR") then
  62. print("Set DXSDK_DIR environment variable.")
  63. end
  64. location(build_dir .. "projects/" .. "windows")
  65. end
  66. flags {
  67. "StaticRuntime",
  68. "NoPCH",
  69. "NoRTTI",
  70. "NoExceptions",
  71. "NoMinimalRebuild",
  72. "NoEditAndContinue",
  73. "Symbols",
  74. }
  75. defines {
  76. "__STDC_FORMAT_MACROS",
  77. "__STDC_CONSTANT_MACROS",
  78. "__STDC_LIMIT_MACROS",
  79. }
  80. configuration { "development" }
  81. flags {
  82. "OptimizeSpeed"
  83. }
  84. configuration { "release" }
  85. flags {
  86. "OptimizeSpeed"
  87. }
  88. configuration { "debug", "x32" }
  89. targetsuffix "-debug-32"
  90. configuration { "debug", "x64" }
  91. targetsuffix "-debug-64"
  92. configuration { "development", "x32" }
  93. targetsuffix "-development-32"
  94. configuration { "development", "x64" }
  95. targetsuffix "-development-64"
  96. configuration { "release", "x32" }
  97. targetsuffix "-release-32"
  98. configuration { "release", "x64" }
  99. targetsuffix "-release-64"
  100. configuration { "debug", "native" }
  101. targetsuffix "-debug"
  102. configuration { "development", "native" }
  103. targetsuffix "-development"
  104. configuration { "release", "native" }
  105. targetsuffix "-release"
  106. configuration { "x32", "linux-*" }
  107. targetdir (build_dir .. "linux32" .. "/bin")
  108. objdir (build_dir .. "linux32" .. "/obj")
  109. libdirs {
  110. lib_dir .. "luajit/src",
  111. lib_dir .. "bgfx/.build/linux32_gcc/bin",
  112. "$(PHYSX_SDK_LINUX)/Lib/linux32"
  113. }
  114. buildoptions {
  115. "-m32",
  116. "-malign-double", -- Required by PhysX
  117. }
  118. configuration { "x64", "linux-*" }
  119. targetdir (build_dir .. "linux64" .. "/bin")
  120. objdir (build_dir .. "linux64" .. "/obj")
  121. libdirs {
  122. lib_dir .. "luajit/src",
  123. lib_dir .. "bgfx/.build/linux64_gcc/bin",
  124. "$(PHYSX_SDK_LINUX)/Lib/linux64"
  125. }
  126. buildoptions {
  127. "-m64",
  128. }
  129. configuration { "linux-*" }
  130. buildoptions {
  131. "-std=c++03",
  132. "-Wall",
  133. "-Wextra",
  134. -- "-Werror",
  135. -- "-pedantic",
  136. "-Wno-unknown-pragmas",
  137. "-Wno-unused-local-typedefs",
  138. }
  139. linkoptions {
  140. "-Wl,-rpath=\\$$ORIGIN",
  141. "-Wl,--no-as-needed",
  142. }
  143. configuration { "android-*" }
  144. flags {
  145. "NoImportLib"
  146. }
  147. includedirs {
  148. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/include",
  149. "$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
  150. }
  151. linkoptions {
  152. "-nostdlib",
  153. "-static-libgcc",
  154. }
  155. links {
  156. ":libluajit.a",
  157. "bgfxDebug",
  158. "c",
  159. "dl",
  160. "m",
  161. "android",
  162. "log",
  163. "gnustl_static",
  164. "gcc",
  165. }
  166. buildoptions {
  167. "-fPIC",
  168. "-std=c++03",
  169. "-no-canonical-prefixes",
  170. "-Wa,--noexecstack",
  171. "-fstack-protector",
  172. "-ffunction-sections",
  173. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  174. "-Wunused-value",
  175. -- "-Wundef", -- note: avoids PhysX warnings
  176. }
  177. linkoptions {
  178. "-no-canonical-prefixes",
  179. "-Wl,--no-undefined",
  180. "-Wl,-z,noexecstack",
  181. "-Wl,-z,relro",
  182. "-Wl,-z,now",
  183. }
  184. configuration { "android-arm" }
  185. targetdir (build_dir .. "android-arm" .. "/bin")
  186. objdir (build_dir .. "android-arm" .. "/obj")
  187. libdirs {
  188. lib_dir .. "luajit/src",
  189. lib_dir .. "bgfx/.build/android-arm/bin",
  190. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a",
  191. "$(PHYSX_SDK_ANDROID)/Lib/android9_neon",
  192. }
  193. includedirs {
  194. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include",
  195. }
  196. buildoptions {
  197. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  198. "-mthumb",
  199. "-march=armv7-a",
  200. "-mfloat-abi=softfp",
  201. "-mfpu=neon",
  202. "-Wunused-value",
  203. -- "-Wundef", -- note: avoids PhysX warnings
  204. }
  205. linkoptions {
  206. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  207. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtbegin_so.o",
  208. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtend_so.o",
  209. "-march=armv7-a",
  210. "-Wl,--fix-cortex-a8",
  211. }
  212. configuration { "vs*" }
  213. includedirs { CROWN_DIR .. "engine/core/compat/msvc" }
  214. defines {
  215. "WIN32",
  216. "_WIN32",
  217. "_HAS_EXCEPTIONS=0",
  218. "_HAS_ITERATOR_DEBUGGING=0",
  219. "_SCL_SECURE=0",
  220. "_SECURE_SCL=0",
  221. "_SCL_SECURE_NO_WARNINGS",
  222. "_CRT_SECURE_NO_WARNINGS",
  223. "_CRT_SECURE_NO_DEPRECATE",
  224. }
  225. buildoptions {
  226. "/Oy-", -- Suppresses creation of frame pointers on the call stack.
  227. "/Ob2", -- The Inline Function Expansion
  228. }
  229. linkoptions {
  230. "/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll
  231. "/ignore:4221", -- LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
  232. }
  233. configuration { "x32", "vs*" }
  234. targetdir (build_dir .. "win32" .. "/bin")
  235. objdir (build_dir .. "win32" .. "/obj")
  236. libdirs {
  237. lib_dir .. "luajit/src",
  238. lib_dir .. "openal/lib",
  239. lib_dir .. "bgfx/.build/win32_vs2012/bin",
  240. "$(PHYSX_SDK_WINDOWS)/Lib/win32",
  241. "$(DXSDK_DIR)/Lib/x86",
  242. }
  243. configuration { "x64", "vs*" }
  244. targetdir (build_dir .. "win64" .. "/bin")
  245. objdir (build_dir .. "win64" .. "/obj")
  246. libdirs {
  247. lib_dir .. "luajit/src",
  248. lib_dir .. "openal/lib",
  249. lib_dir .. "bgfx/.build/win64_vs2012/bin",
  250. "$(PHYSX_SDK_WINDOWS)/Lib/win64",
  251. "$(DXSDK_DIR)/Lib/x64",
  252. }
  253. configuration {} -- reset configuration
  254. end
  255. function strip()
  256. configuration { "android-arm", "release"}
  257. postbuildcommands {
  258. "$(SILENT) echo Stripping symbols",
  259. "$(SILENT) $(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-strip -s \"$(TARGET)\""
  260. }
  261. configuration { "linux-*", "release" }
  262. postbuildcommands {
  263. "$(SILENT) echo Stripping symbols",
  264. "$(SILENT) strip -s \"$(TARGET)\""
  265. }
  266. configuration {} -- reset configuration
  267. end