detect.py 8.5 KB

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