detect.py 9.9 KB

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