detect.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import os
  2. import sys
  3. import string
  4. import platform
  5. def is_active():
  6. return True
  7. def get_name():
  8. return "Android"
  9. def can_build():
  10. import os
  11. if (not os.environ.has_key("ANDROID_NDK_ROOT")):
  12. return False
  13. return True
  14. def get_opts():
  15. return [
  16. ('ANDROID_NDK_ROOT', 'the path to Android NDK',
  17. os.environ.get("ANDROID_NDK_ROOT", 0)),
  18. ('ndk_platform', 'compile for platform: (android-<api> , example: android-14)', "android-14"),
  19. ('android_arch', 'select compiler architecture: (armv7/armv6/x86)', "armv7"),
  20. ('android_neon', 'enable neon (armv7 only)', "yes"),
  21. ('android_stl', 'enable STL support in android port (for modules)', "no")
  22. ]
  23. def get_flags():
  24. return [
  25. ('tools', 'no'),
  26. ]
  27. def create(env):
  28. tools = env['TOOLS']
  29. if "mingw" in tools:
  30. tools.remove('mingw')
  31. if "applelink" in tools:
  32. tools.remove("applelink")
  33. env.Tool('gcc')
  34. return env.Clone(tools=tools)
  35. def configure(env):
  36. # Workaround for MinGW. See:
  37. # http://www.scons.org/wiki/LongCmdLinesOnWin32
  38. import os
  39. if (os.name == "nt"):
  40. import subprocess
  41. def mySubProcess(cmdline, env):
  42. # print "SPAWNED : " + cmdline
  43. startupinfo = subprocess.STARTUPINFO()
  44. startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  45. proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  46. stderr=subprocess.PIPE, startupinfo=startupinfo, shell=False, env=env)
  47. data, err = proc.communicate()
  48. rv = proc.wait()
  49. if rv:
  50. print "====="
  51. print err
  52. print "====="
  53. return rv
  54. def mySpawn(sh, escape, cmd, args, env):
  55. newargs = ' '.join(args[1:])
  56. cmdline = cmd + " " + newargs
  57. rv = 0
  58. if len(cmdline) > 32000 and cmd.endswith("ar"):
  59. cmdline = cmd + " " + args[1] + " " + args[2] + " "
  60. for i in range(3, len(args)):
  61. rv = mySubProcess(cmdline + args[i], env)
  62. if rv:
  63. break
  64. else:
  65. rv = mySubProcess(cmdline, env)
  66. return rv
  67. env['SPAWN'] = mySpawn
  68. ndk_platform = env['ndk_platform']
  69. if env['android_arch'] not in ['armv7', 'armv6', 'x86']:
  70. env['android_arch'] = 'armv7'
  71. if env['android_arch'] == 'x86':
  72. env["x86_libtheora_opt_gcc"] = True
  73. if env['PLATFORM'] == 'win32':
  74. env.Tool('gcc')
  75. env['SHLIBSUFFIX'] = '.so'
  76. neon_text = ""
  77. if env["android_arch"] == "armv7" and env['android_neon'] == 'yes':
  78. neon_text = " (with neon)"
  79. print("Godot Android!!!!! (" + env['android_arch'] + ")" + neon_text)
  80. env.Append(CPPPATH=['#platform/android'])
  81. if env['android_arch'] == 'x86':
  82. env.extra_suffix = ".x86" + env.extra_suffix
  83. target_subpath = "x86-4.9"
  84. abi_subpath = "i686-linux-android"
  85. arch_subpath = "x86"
  86. elif env['android_arch'] == 'armv6':
  87. env.extra_suffix = ".armv6" + env.extra_suffix
  88. target_subpath = "arm-linux-androideabi-4.9"
  89. abi_subpath = "arm-linux-androideabi"
  90. arch_subpath = "armeabi"
  91. elif env["android_arch"] == "armv7":
  92. target_subpath = "arm-linux-androideabi-4.9"
  93. abi_subpath = "arm-linux-androideabi"
  94. arch_subpath = "armeabi-v7a"
  95. if env['android_neon'] == 'yes':
  96. env.extra_suffix = ".armv7.neon" + env.extra_suffix
  97. else:
  98. env.extra_suffix = ".armv7" + env.extra_suffix
  99. mt_link = True
  100. if (sys.platform.startswith("linux")):
  101. host_subpath = "linux-x86_64"
  102. elif (sys.platform.startswith("darwin")):
  103. host_subpath = "darwin-x86_64"
  104. elif (sys.platform.startswith('win')):
  105. if (platform.machine().endswith('64')):
  106. host_subpath = "windows-x86_64"
  107. else:
  108. mt_link = False
  109. host_subpath = "windows"
  110. compiler_path = env["ANDROID_NDK_ROOT"] + \
  111. "/toolchains/llvm/prebuilt/" + host_subpath + "/bin"
  112. gcc_toolchain_path = env["ANDROID_NDK_ROOT"] + \
  113. "/toolchains/" + target_subpath + "/prebuilt/" + host_subpath
  114. tools_path = gcc_toolchain_path + "/" + abi_subpath + "/bin"
  115. # For Clang to find NDK tools in preference of those system-wide
  116. env.PrependENVPath('PATH', tools_path)
  117. env['CC'] = compiler_path + '/clang'
  118. env['CXX'] = compiler_path + '/clang++'
  119. env['AR'] = tools_path + "/ar"
  120. env['RANLIB'] = tools_path + "/ranlib"
  121. env['AS'] = tools_path + "/as"
  122. if env['android_arch'] == 'x86':
  123. env['ARCH'] = 'arch-x86'
  124. else:
  125. env['ARCH'] = 'arch-arm'
  126. sysroot = env["ANDROID_NDK_ROOT"] + \
  127. "/platforms/" + ndk_platform + "/" + env['ARCH']
  128. common_opts = ['-fno-integrated-as', '-gcc-toolchain', gcc_toolchain_path]
  129. env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include"])
  130. env.Append(CPPFLAGS=string.split(
  131. '-Wno-invalid-command-line-argument -Wno-unused-command-line-argument'))
  132. env.Append(CPPFLAGS=string.split(
  133. '-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -fvisibility=hidden -fno-strict-aliasing -Wa,--noexecstack'))
  134. env.Append(CPPFLAGS=string.split('-DANDROID -DNO_STATVFS -DGLES2_ENABLED'))
  135. env['neon_enabled'] = False
  136. if env['android_arch'] == 'x86':
  137. can_vectorize = True
  138. target_opts = ['-target', 'i686-none-linux-android']
  139. elif env["android_arch"] == "armv6":
  140. can_vectorize = False
  141. target_opts = ['-target', 'armv6-none-linux-androideabi']
  142. env.Append(CPPFLAGS=string.split(
  143. '-D__ARM_ARCH_6__ -march=armv6 -mfpu=vfp -mfloat-abi=softfp'))
  144. elif env["android_arch"] == "armv7":
  145. can_vectorize = True
  146. target_opts = ['-target', 'armv7-none-linux-androideabi']
  147. env.Append(CPPFLAGS=string.split(
  148. '-D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ -march=armv7-a -mfloat-abi=softfp'))
  149. if env['android_neon'] == 'yes':
  150. env['neon_enabled'] = True
  151. env.Append(CPPFLAGS=['-mfpu=neon', '-D__ARM_NEON__'])
  152. else:
  153. env.Append(CPPFLAGS=['-mfpu=vfpv3-d16'])
  154. env.Append(CPPFLAGS=target_opts)
  155. env.Append(CPPFLAGS=common_opts)
  156. env.Append(LIBS=['OpenSLES'])
  157. env.Append(LIBS=['EGL', 'OpenSLES', 'android'])
  158. env.Append(LIBS=['log', 'GLESv1_CM', 'GLESv2', 'z'])
  159. if (sys.platform.startswith("darwin")):
  160. env['SHLIBSUFFIX'] = '.so'
  161. env['LINKFLAGS'] = ['-shared', '--sysroot=' +
  162. sysroot, '-Wl,--warn-shared-textrel']
  163. env.Append(LINKFLAGS=string.split(
  164. '-Wl,--fix-cortex-a8'))
  165. env.Append(LINKFLAGS=string.split(
  166. '-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now'))
  167. env.Append(LINKFLAGS=string.split(
  168. '-Wl,-soname,libgodot_android.so -Wl,--gc-sections'))
  169. if mt_link:
  170. env.Append(LINKFLAGS=['-Wl,--threads'])
  171. env.Append(LINKFLAGS=target_opts)
  172. env.Append(LINKFLAGS=common_opts)
  173. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + '/toolchains/arm-linux-androideabi-4.9/prebuilt/' +
  174. host_subpath + '/lib/gcc/' + abi_subpath + '/4.9.x'])
  175. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] +
  176. '/toolchains/arm-linux-androideabi-4.9/prebuilt/' + host_subpath + '/' + abi_subpath + '/lib'])
  177. if (env["target"].startswith("release")):
  178. env.Append(LINKFLAGS=['-O2'])
  179. env.Append(CPPFLAGS=['-O2', '-DNDEBUG', '-ffast-math',
  180. '-funsafe-math-optimizations', '-fomit-frame-pointer'])
  181. if (can_vectorize):
  182. env.Append(CPPFLAGS=['-ftree-vectorize'])
  183. if (env["target"] == "release_debug"):
  184. env.Append(CPPFLAGS=['-DDEBUG_ENABLED'])
  185. elif (env["target"] == "debug"):
  186. env.Append(LINKFLAGS=['-O0'])
  187. env.Append(CPPFLAGS=['-O0', '-D_DEBUG', '-UNDEBUG', '-DDEBUG_ENABLED',
  188. '-DDEBUG_MEMORY_ALLOC', '-g', '-fno-limit-debug-info'])
  189. env.Append(CPPFLAGS=['-DANDROID_ENABLED',
  190. '-DUNIX_ENABLED', '-DNO_FCNTL', '-DMPC_FIXED_POINT'])
  191. # TODO: Move that to opus module's config
  192. if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"):
  193. if (env["android_arch"] == "armv6" or env["android_arch"] == "armv7"):
  194. env.Append(CFLAGS=["-DOPUS_ARM_OPT"])
  195. env.opus_fixed_point = "yes"
  196. if (env['android_stl'] == 'yes'):
  197. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] +
  198. "/sources/cxx-stl/gnu-libstdc++/4.9/include"])
  199. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] +
  200. "/sources/cxx-stl/gnu-libstdc++/4.9/libs/" + arch_subpath + "/include"])
  201. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] +
  202. "/sources/cxx-stl/gnu-libstdc++/4.9/libs/" + arch_subpath])
  203. env.Append(LIBS=["gnustl_static"])
  204. else:
  205. env.Append(CXXFLAGS=['-fno-rtti', '-fno-exceptions', '-DNO_SAFE_CAST'])
  206. import methods
  207. env.Append(BUILDERS={'GLSL120': env.Builder(
  208. action=methods.build_legacygl_headers, suffix='glsl.h', src_suffix='.glsl')})
  209. env.Append(BUILDERS={'GLSL': env.Builder(
  210. action=methods.build_glsl_headers, suffix='glsl.h', src_suffix='.glsl')})
  211. env.Append(BUILDERS={'GLSL120GLES': env.Builder(
  212. action=methods.build_gles2_headers, suffix='glsl.h', src_suffix='.glsl')})
  213. env.use_windows_spawn_fix()