detect.py 6.9 KB

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