detect.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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', os.environ.get("ANDROID_NDK_ROOT", 0)),
  17. ('NDK_TARGET', 'toolchain to use for the NDK', os.environ.get("NDK_TARGET", "arm-linux-androideabi-4.9")),
  18. ('NDK_TARGET_X86', 'toolchain to use for the NDK x86', os.environ.get("NDK_TARGET_X86", "x86-4.9")),
  19. ('ndk_platform', 'compile for platform: (android-<api> , example: android-14)', "android-14"),
  20. ('android_arch', 'select compiler architecture: (armv7/armv6/x86)', "armv7"),
  21. ('android_neon', 'enable neon (armv7 only)', "yes"),
  22. ('android_stl', 'enable STL support in android port (for modules)', "no")
  23. ]
  24. def get_flags():
  25. return [
  26. ('tools', 'no'),
  27. ('openssl', 'builtin'), # use builtin openssl
  28. ]
  29. def create(env):
  30. tools = env['TOOLS']
  31. if "mingw" in tools:
  32. tools.remove('mingw')
  33. if "applelink" in tools:
  34. tools.remove("applelink")
  35. env.Tool('gcc')
  36. return env.Clone(tools=tools)
  37. def configure(env):
  38. # Workaround for MinGW. See:
  39. # http://www.scons.org/wiki/LongCmdLinesOnWin32
  40. import os
  41. if (os.name == "nt"):
  42. import subprocess
  43. def mySubProcess(cmdline, env):
  44. # print "SPAWNED : " + cmdline
  45. startupinfo = subprocess.STARTUPINFO()
  46. startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  47. proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  48. stderr=subprocess.PIPE, startupinfo=startupinfo, shell=False, env=env)
  49. data, err = proc.communicate()
  50. rv = proc.wait()
  51. if rv:
  52. print "====="
  53. print err
  54. print "====="
  55. return rv
  56. def mySpawn(sh, escape, cmd, args, env):
  57. newargs = ' '.join(args[1:])
  58. cmdline = cmd + " " + newargs
  59. rv = 0
  60. if len(cmdline) > 32000 and cmd.endswith("ar"):
  61. cmdline = cmd + " " + args[1] + " " + args[2] + " "
  62. for i in range(3, len(args)):
  63. rv = mySubProcess(cmdline + args[i], env)
  64. if rv:
  65. break
  66. else:
  67. rv = mySubProcess(cmdline, env)
  68. return rv
  69. env['SPAWN'] = mySpawn
  70. ndk_platform = env['ndk_platform']
  71. if env['android_arch'] not in ['armv7', 'armv6', 'x86']:
  72. env['android_arch'] = 'armv7'
  73. if env['android_arch'] == 'x86':
  74. env['NDK_TARGET'] = env['NDK_TARGET_X86']
  75. env["x86_libtheora_opt_gcc"] = True
  76. if env['PLATFORM'] == 'win32':
  77. env.Tool('gcc')
  78. env['SHLIBSUFFIX'] = '.so'
  79. neon_text = ""
  80. if env["android_arch"] == "armv7" and env['android_neon'] == 'yes':
  81. neon_text = " (with neon)"
  82. print("Godot Android!!!!! (" + env['android_arch'] + ")" + neon_text)
  83. env.Append(CPPPATH=['#platform/android'])
  84. if env['android_arch'] == 'x86':
  85. env.extra_suffix = ".x86" + env.extra_suffix
  86. elif env['android_arch'] == 'armv6':
  87. env.extra_suffix = ".armv6" + env.extra_suffix
  88. elif env["android_arch"] == "armv7":
  89. if env['android_neon'] == 'yes':
  90. env.extra_suffix = ".armv7.neon" + env.extra_suffix
  91. else:
  92. env.extra_suffix = ".armv7" + env.extra_suffix
  93. gcc_path = env["ANDROID_NDK_ROOT"] + "/toolchains/" + env["NDK_TARGET"] + "/prebuilt/"
  94. if (sys.platform.startswith("linux")):
  95. if (platform.machine().endswith('64')):
  96. gcc_path = gcc_path + "/linux-x86_64/bin"
  97. else:
  98. gcc_path = gcc_path + "/linux-x86/bin"
  99. elif (sys.platform.startswith("darwin")):
  100. gcc_path = gcc_path + "/darwin-x86_64/bin"
  101. env['SHLINKFLAGS'][1] = '-shared'
  102. env['SHLIBSUFFIX'] = '.so'
  103. elif (sys.platform.startswith('win')):
  104. if (platform.machine().endswith('64')):
  105. gcc_path = gcc_path + "/windows-x86_64/bin"
  106. else:
  107. gcc_path = gcc_path + "/windows-x86/bin"
  108. env['ENV']['PATH'] = gcc_path + ":" + env['ENV']['PATH']
  109. if env['android_arch'] == 'x86':
  110. env['CC'] = gcc_path + '/i686-linux-android-gcc'
  111. env['CXX'] = gcc_path + '/i686-linux-android-g++'
  112. env['AR'] = gcc_path + "/i686-linux-android-ar"
  113. env['RANLIB'] = gcc_path + "/i686-linux-android-ranlib"
  114. env['AS'] = gcc_path + "/i686-linux-android-as"
  115. else:
  116. env['CC'] = gcc_path + '/arm-linux-androideabi-gcc'
  117. env['CXX'] = gcc_path + '/arm-linux-androideabi-g++'
  118. env['AR'] = gcc_path + "/arm-linux-androideabi-ar"
  119. env['RANLIB'] = gcc_path + "/arm-linux-androideabi-ranlib"
  120. env['AS'] = gcc_path + "/arm-linux-androideabi-as"
  121. if env['android_arch'] == 'x86':
  122. env['ARCH'] = 'arch-x86'
  123. else:
  124. env['ARCH'] = 'arch-arm'
  125. import string
  126. # include path
  127. gcc_include = env["ANDROID_NDK_ROOT"] + "/platforms/" + ndk_platform + "/" + env['ARCH'] + "/usr/include"
  128. ld_sysroot = env["ANDROID_NDK_ROOT"] + "/platforms/" + ndk_platform + "/" + env['ARCH']
  129. # glue_include=env["ANDROID_NDK_ROOT"]+"/sources/android/native_app_glue"
  130. ld_path = env["ANDROID_NDK_ROOT"] + "/platforms/" + ndk_platform + "/" + env['ARCH'] + "/usr/lib"
  131. env.Append(CPPPATH=[gcc_include])
  132. # env['CCFLAGS'] = string.split('-DNO_THREADS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -mthumb -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED ')
  133. env['neon_enabled'] = False
  134. if env['android_arch'] == 'x86':
  135. env.Append(CCFLAGS=string.split('-DNO_STATVFS -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__GLIBC__ -Wno-psabi -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED'))
  136. elif env["android_arch"] == "armv6":
  137. env.Append(CCFLAGS=string.split('-DNO_STATVFS -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_6__ -D__GLIBC__ -Wno-psabi -march=armv6 -mfpu=vfp -mfloat-abi=softfp -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED'))
  138. elif env["android_arch"] == "armv7":
  139. env.Append(CCFLAGS=string.split('-DNO_STATVFS -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ -D__GLIBC__ -Wno-psabi -march=armv7-a -mfloat-abi=softfp -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED'))
  140. if env['android_neon'] == 'yes':
  141. env['neon_enabled'] = True
  142. env.Append(CCFLAGS=['-mfpu=neon', '-D__ARM_NEON__'])
  143. else:
  144. env.Append(CCFLAGS=['-mfpu=vfpv3-d16'])
  145. env.Append(LDPATH=[ld_path])
  146. env.Append(LIBS=['OpenSLES'])
  147. # env.Append(LIBS=['c','m','stdc++','log','EGL','GLESv1_CM','GLESv2','OpenSLES','supc++','android'])
  148. env.Append(LIBS=['EGL', 'OpenSLES', 'android'])
  149. env.Append(LIBS=['c', 'm', 'stdc++', 'log', 'GLESv1_CM', 'GLESv2', 'z'])
  150. env["LINKFLAGS"] = string.split(" -g --sysroot=" + ld_sysroot + " -Wl,--no-undefined -Wl,-z,noexecstack ")
  151. env.Append(LINKFLAGS=["-Wl,-soname,libgodot_android.so"])
  152. if (env["target"] == "release"):
  153. env.Append(CCFLAGS=['-O2', '-ffast-math', '-fomit-frame-pointer'])
  154. elif (env["target"] == "release_debug"):
  155. env.Append(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED'])
  156. elif (env["target"] == "debug"):
  157. env.Append(CCFLAGS=['-D_DEBUG', '-g1', '-Wall', '-O0', '-DDEBUG_ENABLED'])
  158. env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC'])
  159. env.Append(CPPFLAGS=['-DANDROID_ENABLED', '-DUNIX_ENABLED', '-DNO_FCNTL', '-DMPC_FIXED_POINT'])
  160. # env.Append(CPPFLAGS=['-DANDROID_ENABLED', '-DUNIX_ENABLED','-DMPC_FIXED_POINT'])
  161. # TODO: Move that to opus module's config
  162. if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"):
  163. if (env["android_arch"] == "armv6" or env["android_arch"] == "armv7"):
  164. env.Append(CFLAGS=["-DOPUS_ARM_OPT"])
  165. env.opus_fixed_point = "yes"
  166. if (env['android_stl'] == 'yes'):
  167. # env.Append(CCFLAGS=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/system/include"])
  168. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/include"])
  169. if env['android_arch'] == 'x86':
  170. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include"])
  171. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86"])
  172. elif env['android_arch'] == 'armv6':
  173. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include"])
  174. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi"])
  175. elif env["android_arch"] == "armv7":
  176. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include"])
  177. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a"])
  178. env.Append(LIBS=["gnustl_static", "supc++"])
  179. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cpufeatures"])
  180. # env.Append(CCFLAGS=["-I"+env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/stlport/stlport"])
  181. # env.Append(CCFLAGS=["-I"+env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include"])
  182. # env.Append(LINKFLAGS=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/libs/armeabi/libstdc++.a"])
  183. else:
  184. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/include"])
  185. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cpufeatures"])
  186. if env['android_arch'] == 'x86':
  187. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86"])
  188. elif env["android_arch"] == "armv6":
  189. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi"])
  190. elif env["android_arch"] == "armv7":
  191. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a"])
  192. env.Append(LIBS=['gnustl_static'])
  193. env.Append(CCFLAGS=["-fno-exceptions", '-DNO_SAFE_CAST'])
  194. import methods
  195. env.Append(BUILDERS={'GLSL120': env.Builder(action=methods.build_legacygl_headers, suffix='glsl.h', src_suffix='.glsl')})
  196. env.Append(BUILDERS={'GLSL': env.Builder(action=methods.build_glsl_headers, suffix='glsl.h', src_suffix='.glsl')})
  197. env.Append(BUILDERS={'GLSL120GLES': env.Builder(action=methods.build_gles2_headers, suffix='glsl.h', src_suffix='.glsl')})
  198. env.use_windows_spawn_fix()