detect.py 6.9 KB

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