detect.py 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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_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.find("linux")==0):
  95. if (platform.architecture()[0]=='64bit' or os.path.isdir(gcc_path+"linux-x86_64/bin")): # check was not working
  96. gcc_path=gcc_path+"/linux-x86_64/bin"
  97. else:
  98. gcc_path=gcc_path+"/linux-x86/bin"
  99. elif (sys.platform=="darwin"):
  100. gcc_path=gcc_path+"/darwin-x86_64/bin" #this may be wrong
  101. env['SHLINKFLAGS'][1] = '-shared'
  102. env['SHLIBSUFFIX'] = '.so'
  103. elif (os.name=="nt"):
  104. gcc_path=gcc_path+"/windows-x86_64/bin" #this may be wrong
  105. env['ENV']['PATH'] = gcc_path+":"+env['ENV']['PATH']
  106. if env['android_arch']=='x86':
  107. env['CC'] = gcc_path+'/i686-linux-android-gcc'
  108. env['CXX'] = gcc_path+'/i686-linux-android-g++'
  109. env['AR'] = gcc_path+"/i686-linux-android-ar"
  110. env['RANLIB'] = gcc_path+"/i686-linux-android-ranlib"
  111. env['AS'] = gcc_path+"/i686-linux-android-as"
  112. else:
  113. env['CC'] = gcc_path+'/arm-linux-androideabi-gcc'
  114. env['CXX'] = gcc_path+'/arm-linux-androideabi-g++'
  115. env['AR'] = gcc_path+"/arm-linux-androideabi-ar"
  116. env['RANLIB'] = gcc_path+"/arm-linux-androideabi-ranlib"
  117. env['AS'] = gcc_path+"/arm-linux-androideabi-as"
  118. if env['android_arch']=='x86':
  119. env['ARCH'] = 'arch-x86'
  120. else:
  121. env['ARCH'] = 'arch-arm'
  122. import string
  123. #include path
  124. gcc_include=env["ANDROID_NDK_ROOT"]+"/platforms/"+ndk_platform+"/"+env['ARCH'] +"/usr/include"
  125. ld_sysroot=env["ANDROID_NDK_ROOT"]+"/platforms/"+ndk_platform+"/"+env['ARCH']
  126. #glue_include=env["ANDROID_NDK_ROOT"]+"/sources/android/native_app_glue"
  127. ld_path=env["ANDROID_NDK_ROOT"]+"/platforms/"+ndk_platform+"/"+env['ARCH']+"/usr/lib"
  128. env.Append(CPPPATH=[gcc_include])
  129. # 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 ')
  130. env['neon_enabled']=False
  131. if env['android_arch']=='x86':
  132. 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'))
  133. elif env["android_arch"]=="armv6":
  134. 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'))
  135. elif env["android_arch"]=="armv7":
  136. 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'))
  137. if env['android_neon']=='yes':
  138. env['neon_enabled']=True
  139. env.Append(CCFLAGS=['-mfpu=neon','-D__ARM_NEON__'])
  140. else:
  141. env.Append(CCFLAGS=['-mfpu=vfpv3-d16'])
  142. env.Append(LDPATH=[ld_path])
  143. env.Append(LIBS=['OpenSLES'])
  144. # env.Append(LIBS=['c','m','stdc++','log','EGL','GLESv1_CM','GLESv2','OpenSLES','supc++','android'])
  145. env.Append(LIBS=['EGL','OpenSLES','android'])
  146. env.Append(LIBS=['c','m','stdc++','log','GLESv1_CM','GLESv2', 'z'])
  147. env["LINKFLAGS"]= string.split(" -g --sysroot="+ld_sysroot+" -Wl,--no-undefined -Wl,-z,noexecstack ")
  148. env.Append(LINKFLAGS=["-Wl,-soname,libgodot_android.so"])
  149. if (env["target"]=="release"):
  150. env.Append(CCFLAGS=['-O2', '-ffast-math','-fomit-frame-pointer'])
  151. elif (env["target"]=="release_debug"):
  152. env.Append(CCFLAGS=['-O2', '-ffast-math','-DDEBUG_ENABLED'])
  153. elif (env["target"]=="debug"):
  154. env.Append(CCFLAGS=['-D_DEBUG', '-g1', '-Wall', '-O0', '-DDEBUG_ENABLED'])
  155. env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC'])
  156. env.Append(CPPFLAGS=['-DANDROID_ENABLED', '-DUNIX_ENABLED', '-DNO_FCNTL','-DMPC_FIXED_POINT'])
  157. # env.Append(CPPFLAGS=['-DANDROID_ENABLED', '-DUNIX_ENABLED','-DMPC_FIXED_POINT'])
  158. # TODO: Move that to opus module's config
  159. if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"):
  160. if (env["android_arch"]=="armv6" or env["android_arch"]=="armv7"):
  161. env.Append(CFLAGS=["-DOPUS_ARM_OPT"])
  162. env.opus_fixed_point="yes"
  163. if (env['android_stl']=='yes'):
  164. #env.Append(CCFLAGS=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/system/include"])
  165. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.9/include"])
  166. if env['android_arch']=='x86':
  167. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include"])
  168. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86"])
  169. elif env['android_arch']=='armv6':
  170. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include"])
  171. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi"])
  172. elif env["android_arch"]=="armv7":
  173. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include"])
  174. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a"])
  175. env.Append(LIBS=["gnustl_static","supc++"])
  176. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cpufeatures"])
  177. #env.Append(CCFLAGS=["-I"+env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/stlport/stlport"])
  178. #env.Append(CCFLAGS=["-I"+env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include"])
  179. #env.Append(LINKFLAGS=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/libs/armeabi/libstdc++.a"])
  180. else:
  181. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.9/include"])
  182. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cpufeatures"])
  183. if env['android_arch']=='x86':
  184. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86"])
  185. elif env["android_arch"]=="armv6":
  186. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi"])
  187. elif env["android_arch"]=="armv7":
  188. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a"])
  189. env.Append(LIBS=['gnustl_static'])
  190. env.Append(CCFLAGS=["-fno-exceptions",'-DNO_SAFE_CAST'])
  191. import methods
  192. env.Append( BUILDERS = { 'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
  193. env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
  194. env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
  195. env.use_windows_spawn_fix()