detect.py 9.7 KB

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