detect.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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','compile for x86','no')
  24. ]
  25. def get_flags():
  26. return [
  27. ('lua', 'no'),
  28. ('tools', 'no'),
  29. ('nedmalloc', 'no'),
  30. ('builtin_zlib', 'no'),
  31. ('openssl','builtin'), #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. if env['x86']=='yes':
  43. env['NDK_TARGET']='x86-4.8'
  44. if env['PLATFORM'] == 'win32':
  45. import methods
  46. env.Tool('gcc')
  47. env['SPAWN'] = methods.win32_spawn
  48. # env.android_source_modules.append("../libs/apk_expansion")
  49. env.android_source_modules.append("../libs/google_play_services")
  50. env.android_source_modules.append("../libs/downloader_library")
  51. env.android_source_modules.append("../libs/play_licensing")
  52. ndk_platform=""
  53. ndk_platform="android-15"
  54. print("Godot Android!!!!!")
  55. env.Append(CPPPATH=['#platform/android'])
  56. if env['x86']=='yes':
  57. env['OBJSUFFIX'] = ".android.ox"
  58. env['LIBSUFFIX'] = ".android.ax"
  59. else:
  60. env['OBJSUFFIX'] = ".android.o"
  61. env['LIBSUFFIX'] = ".android.a"
  62. env['PROGSUFFIX'] = ".android"
  63. env['SHLIBSUFFIX'] = ".so"
  64. gcc_path=env["ANDROID_NDK_ROOT"]+"/toolchains/"+env["NDK_TARGET"]+"/prebuilt/";
  65. import os
  66. if (sys.platform.find("linux")==0):
  67. if (platform.architecture()[0]=='64bit' or os.path.isdir(gcc_path+"linux-x86_64/bin")): # check was not working
  68. gcc_path=gcc_path+"/linux-x86_64/bin"
  69. else:
  70. gcc_path=gcc_path+"/linux-x86/bin"
  71. elif (sys.platform=="darwin"):
  72. gcc_path=gcc_path+"/darwin-x86_64/bin" #this may be wrong
  73. env['SHLINKFLAGS'][1] = '-shared'
  74. elif (os.name=="nt"):
  75. gcc_path=gcc_path+"/windows/bin" #this may be wrong
  76. env['ENV']['PATH'] = gcc_path+":"+env['ENV']['PATH']
  77. if env['x86']=='yes':
  78. env['CC'] = gcc_path+'/i686-linux-android-gcc'
  79. env['CXX'] = gcc_path+'/i686-linux-android-g++'
  80. env['AR'] = gcc_path+"/i686-linux-android-ar"
  81. env['RANLIB'] = gcc_path+"/i686-linux-android-ranlib"
  82. env['AS'] = gcc_path+"/i686-linux-android-as"
  83. else:
  84. env['CC'] = gcc_path+'/arm-linux-androideabi-gcc'
  85. env['CXX'] = gcc_path+'/arm-linux-androideabi-g++'
  86. env['AR'] = gcc_path+"/arm-linux-androideabi-ar"
  87. env['RANLIB'] = gcc_path+"/arm-linux-androideabi-ranlib"
  88. env['AS'] = gcc_path+"/arm-linux-androideabi-as"
  89. if env['x86']=='yes':
  90. env['ARCH'] = 'arch-x86'
  91. else:
  92. env['ARCH'] = 'arch-arm'
  93. import string
  94. #include path
  95. gcc_include=env["ANDROID_NDK_ROOT"]+"/platforms/"+ndk_platform+"/"+env['ARCH'] +"/usr/include"
  96. ld_sysroot=env["ANDROID_NDK_ROOT"]+"/platforms/"+ndk_platform+"/"+env['ARCH']
  97. #glue_include=env["ANDROID_NDK_ROOT"]+"/sources/android/native_app_glue"
  98. ld_path=env["ANDROID_NDK_ROOT"]+"/platforms/"+ndk_platform+"/"+env['ARCH']+"/usr/lib"
  99. env.Append(CPPPATH=[gcc_include])
  100. # 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 ')
  101. print("********* armv6", env['armv6'])
  102. if env['x86']=='yes':
  103. env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -D__GLIBC__ -Wno-psabi -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
  104. elif env["armv6"]!="no":
  105. env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -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 -DGLES1_ENABLED')
  106. else:
  107. env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -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 -DGLES1_ENABLED')
  108. env.Append(LDPATH=[ld_path])
  109. env.Append(LIBS=['OpenSLES'])
  110. # env.Append(LIBS=['c','m','stdc++','log','EGL','GLESv1_CM','GLESv2','OpenSLES','supc++','android'])
  111. if (env["ndk_platform"]!="2.2"):
  112. env.Append(LIBS=['EGL','OpenSLES','android'])
  113. env.Append(LIBS=['c','m','stdc++','log','GLESv1_CM','GLESv2', 'z'])
  114. env["LINKFLAGS"]= string.split(" -g --sysroot="+ld_sysroot+" -Wl,--no-undefined -Wl,-z,noexecstack ")
  115. env.Append(LINKFLAGS=["-Wl,-soname,libgodot_android.so"])
  116. if (env["target"]=="release"):
  117. env.Append(CCFLAGS=['-O2', '-ffast-math','-fomit-frame-pointer'])
  118. env['OBJSUFFIX'] = "_opt"+env['OBJSUFFIX']
  119. env['LIBSUFFIX'] = "_opt"+env['LIBSUFFIX']
  120. elif (env["target"]=="release_debug"):
  121. env.Append(CCFLAGS=['-O2', '-ffast-math','-DDEBUG_ENABLED'])
  122. env['OBJSUFFIX'] = "_optd"+env['OBJSUFFIX']
  123. env['LIBSUFFIX'] = "_optd"+env['LIBSUFFIX']
  124. elif (env["target"]=="profile"):
  125. env.Append(CCFLAGS=['-O2', '-ffast-math','-fomit-frame-pointer', '-g1'])
  126. env.Append(LIBPATH=['#platform/android/armeabi'])
  127. env.Append(LIBS=['andprof'])
  128. env['OBJSUFFIX'] = "_prof"+env['OBJSUFFIX']
  129. env['LIBSUFFIX'] = "_prof"+env['LIBSUFFIX']
  130. env['SHLIBSUFFIX'] = "_prof"+env['SHLIBSUFFIX']
  131. elif (env["target"]=="debug"):
  132. env.Append(CCFLAGS=['-D_DEBUG', '-g1', '-Wall', '-O0', '-DDEBUG_ENABLED'])
  133. env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC'])
  134. if env["armv6"] == "no" and env['x86'] != 'yes':
  135. env['neon_enabled']=True
  136. env.Append(CPPFLAGS=['-DANDROID_ENABLED', '-DUNIX_ENABLED', '-DNO_FCNTL','-DMPC_FIXED_POINT'])
  137. # env.Append(CPPFLAGS=['-DANDROID_ENABLED', '-DUNIX_ENABLED','-DMPC_FIXED_POINT'])
  138. if (env['android_stl']=='yes'):
  139. #env.Append(CCFLAGS=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/system/include"])
  140. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.4.3/include"])
  141. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi/include"])
  142. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi"])
  143. env.Append(LIBS=["gnustl_static","supc++"])
  144. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cpufeatures"])
  145. #env.Append(CCFLAGS=["-I"+env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/stlport/stlport"])
  146. #env.Append(CCFLAGS=["-I"+env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include"])
  147. #env.Append(LINKFLAGS=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gnu-libstdc++/libs/armeabi/libstdc++.a"])
  148. else:
  149. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gabi++/include"])
  150. env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cpufeatures"])
  151. if env['x86']=='yes':
  152. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gabi++/libs/x86"])
  153. else:
  154. env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"]+"/sources/cxx-stl/gabi++/libs/armeabi"])
  155. env.Append(LIBS=['gabi++_static'])
  156. env.Append(CCFLAGS=["-fno-exceptions",'-DNO_SAFE_CAST'])
  157. import methods
  158. env.Append( BUILDERS = { 'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
  159. env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
  160. env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )