toolchain.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. --
  2. -- Copyright (c) 2012-2016 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 = "compiler",
  9. value = "COMPILER",
  10. description = "Choose compiler",
  11. allowed =
  12. {
  13. { "android-arm", "Android - ARM" },
  14. { "linux-gcc", "Linux (GCC compiler)" }
  15. }
  16. }
  17. if (_ACTION == nil) then return end
  18. location (build_dir .. "projects/" .. _ACTION)
  19. if _ACTION == "clean" then
  20. os.rmdir(BUILD_DIR)
  21. end
  22. if _ACTION == "gmake" then
  23. if nil == _OPTIONS["compiler"] then
  24. print("Choose a compiler!")
  25. os.exit(1)
  26. end
  27. if "linux-gcc" == _OPTIONS["compiler"] then
  28. if not os.is("linux") then
  29. print("Action not valid in current OS.")
  30. end
  31. location(build_dir .. "projects/" .. "linux")
  32. end
  33. if "android-arm" == _OPTIONS["compiler"] then
  34. if not os.getenv("ANDROID_NDK_ROOT") then
  35. print("Set ANDROID_NDK_ROOT environment variable.")
  36. end
  37. if not os.getenv("ANDROID_NDK_ARM") then
  38. print("Set ANDROID_NDK_ARM environment variables.")
  39. end
  40. premake.gcc.cc = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-gcc"
  41. premake.gcc.cxx = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-g++"
  42. premake.gcc.ar = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-ar"
  43. location(build_dir .. "projects/" .. "android")
  44. end
  45. end
  46. if _ACTION == "vs2013" then
  47. if not os.is("windows") then
  48. print("Action not valid in current OS.")
  49. end
  50. location(build_dir .. "projects/" .. _ACTION)
  51. end
  52. flags {
  53. "StaticRuntime",
  54. "NoPCH",
  55. "NoRTTI",
  56. "NoExceptions",
  57. "NoEditAndContinue",
  58. "Symbols",
  59. }
  60. defines {
  61. "__STDC_FORMAT_MACROS",
  62. "__STDC_CONSTANT_MACROS",
  63. "__STDC_LIMIT_MACROS",
  64. }
  65. configuration { "development or release" }
  66. flags {
  67. "OptimizeSpeed"
  68. }
  69. configuration { "debug", "x32" }
  70. targetsuffix "-debug-32"
  71. configuration { "debug", "x64" }
  72. targetsuffix "-debug-64"
  73. configuration { "development", "x32" }
  74. targetsuffix "-development-32"
  75. configuration { "development", "x64" }
  76. targetsuffix "-development-64"
  77. configuration { "release", "x32" }
  78. targetsuffix "-release-32"
  79. configuration { "release", "x64" }
  80. targetsuffix "-release-64"
  81. configuration { "debug", "native" }
  82. targetsuffix "-debug"
  83. configuration { "development", "native" }
  84. targetsuffix "-development"
  85. configuration { "release", "native" }
  86. targetsuffix "-release"
  87. configuration { "debug or development", "linux-*" }
  88. linkoptions {
  89. "-rdynamic"
  90. }
  91. configuration { "x32", "linux-*" }
  92. targetdir (build_dir .. "linux32" .. "/bin")
  93. objdir (build_dir .. "linux32" .. "/obj")
  94. libdirs {
  95. lib_dir .. "../.build/linux32/bin",
  96. }
  97. buildoptions {
  98. "-m32",
  99. }
  100. configuration { "x64", "linux-*" }
  101. targetdir (build_dir .. "linux64" .. "/bin")
  102. objdir (build_dir .. "linux64" .. "/obj")
  103. libdirs {
  104. lib_dir .. "../.build/linux64/bin",
  105. }
  106. buildoptions {
  107. "-m64",
  108. }
  109. configuration { "linux-*" }
  110. buildoptions {
  111. "-Wall",
  112. "-Wextra",
  113. -- "-Werror",
  114. -- "-pedantic",
  115. "-msse2",
  116. }
  117. buildoptions_cpp {
  118. "-std=c++0x",
  119. }
  120. linkoptions {
  121. "-Wl,-rpath=\\$$ORIGIN",
  122. "-Wl,--no-as-needed",
  123. }
  124. configuration { "android-*" }
  125. flags {
  126. "NoImportLib"
  127. }
  128. includedirs {
  129. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/include",
  130. "$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
  131. }
  132. linkoptions {
  133. "-nostdlib",
  134. "-static-libgcc",
  135. }
  136. links {
  137. "c",
  138. "dl",
  139. "m",
  140. "gcc",
  141. "gnustl_static",
  142. "android",
  143. "log",
  144. }
  145. buildoptions {
  146. "-fPIC",
  147. "-no-canonical-prefixes",
  148. "-Wa,--noexecstack",
  149. "-fstack-protector",
  150. "-ffunction-sections",
  151. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  152. "-Wunused-value",
  153. }
  154. buildoptions_cpp {
  155. "-std=c++0x",
  156. }
  157. linkoptions {
  158. "-no-canonical-prefixes",
  159. "-Wl,--no-undefined",
  160. "-Wl,-z,noexecstack",
  161. "-Wl,-z,relro",
  162. "-Wl,-z,now",
  163. }
  164. configuration { "android-arm" }
  165. targetdir (build_dir .. "android-arm" .. "/bin")
  166. objdir (build_dir .. "android-arm" .. "/obj")
  167. libdirs {
  168. lib_dir .. "../.build/android-arm/bin",
  169. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a",
  170. }
  171. includedirs {
  172. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include",
  173. }
  174. buildoptions {
  175. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  176. "-mthumb",
  177. "-march=armv7-a",
  178. "-mfloat-abi=softfp",
  179. "-mfpu=neon",
  180. "-Wunused-value",
  181. }
  182. linkoptions {
  183. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  184. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtbegin_so.o",
  185. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtend_so.o",
  186. "-march=armv7-a",
  187. "-Wl,--fix-cortex-a8",
  188. }
  189. configuration { "vs*" }
  190. includedirs { CROWN_DIR .. "src/core/compat/msvc" }
  191. defines {
  192. "WIN32",
  193. "_WIN32",
  194. "_HAS_EXCEPTIONS=0",
  195. "_HAS_ITERATOR_DEBUGGING=0",
  196. "_SCL_SECURE=0",
  197. "_SECURE_SCL=0",
  198. "_SCL_SECURE_NO_WARNINGS",
  199. "_CRT_SECURE_NO_WARNINGS",
  200. "_CRT_SECURE_NO_DEPRECATE",
  201. "NOMINMAX",
  202. }
  203. buildoptions {
  204. "/Oy-", -- Suppresses creation of frame pointers on the call stack.
  205. "/Ob2", -- The Inline Function Expansion
  206. }
  207. linkoptions {
  208. "/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll
  209. "/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
  210. "/ignore:4099", -- LNK4099: The linker was unable to find your .pdb file.
  211. }
  212. configuration { "x32", "vs*" }
  213. targetdir (build_dir .. "win32" .. "/bin")
  214. objdir (build_dir .. "win32" .. "/obj")
  215. configuration { "x64", "vs*" }
  216. targetdir (build_dir .. "win64" .. "/bin")
  217. objdir (build_dir .. "win64" .. "/obj")
  218. configuration {} -- reset configuration
  219. end
  220. function strip()
  221. configuration { "android-arm", "release"}
  222. postbuildcommands {
  223. "$(SILENT) echo Stripping symbols",
  224. "$(SILENT) $(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-strip -s \"$(TARGET)\""
  225. }
  226. configuration { "linux-*", "release" }
  227. postbuildcommands {
  228. "$(SILENT) echo Stripping symbols",
  229. "$(SILENT) strip -s \"$(TARGET)\""
  230. }
  231. configuration {} -- reset configuration
  232. end