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