AndroidBuild.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/bin/bash
  2. #set -xv
  3. # TODO: find out if flavour can be passed from SDL build environment
  4. openmsx_flavour="opt"
  5. echo "AB:INFO Starting AndroidBuild.sh, #params: $#, params: $*"
  6. echo "AB:INFO pwd: $(pwd)"
  7. export TARGET_ABI="$1"
  8. TARGET_TUPLE="$2"
  9. # Read environment.props (if it exists) to get following two params:
  10. # sdl_android_port_path
  11. # my_home_dir
  12. if [ ! -f environment.props ]; then
  13. echo "AB:ERROR: No file environment.props in $(pwd)"
  14. exit 1
  15. fi
  16. . ./environment.props
  17. # Remember location of the current directory, which is the directory
  18. # with all android specific code for the app
  19. my_app_android_dir="$(pwd)"
  20. # Use latest version of the setEnvironment script
  21. set_sdl_app_environment="${sdl_android_port_path}/project/jni/application/setEnvironment-${TARGET_ABI}.sh"
  22. # Parsing the ABI selection
  23. if [ "${TARGET_ABI}" = "armeabi-v7a" ]; then
  24. so_file=libapplication-${TARGET_ABI}.so
  25. openmsx_target_cpu=arm
  26. else
  27. echo "AB:ERROR Unsupported architecture: $1"
  28. exit 1
  29. fi
  30. #echo "AB:INFO current shell: ${SHELL}"
  31. #echo "AB:INFO BEGIN all environment params:"
  32. #set
  33. #echo "AB:INFO END all environment params:"
  34. #cd ${my_home_dir}
  35. # Unset make related environment parameters that get set by the
  36. # SDL for Android build system and that conflict with openMSX
  37. # build system
  38. unset BUILD_NUM_CPUS
  39. unset MAKEFLAGS
  40. unset MAKELEVEL
  41. unset MAKEOVERRIDES
  42. unset MFLAGS
  43. unset V
  44. # The commandergenius build will modify the PATH.
  45. # Pick the right compiler now and store its absolute path.
  46. CXX=$(which ${TARGET_TUPLE}-clang++)
  47. if [ $? -ne 0 ]; then
  48. echo "AB:ERROR Could not find compiler"
  49. exit 1
  50. fi
  51. cpu_count=1
  52. if [ -f /proc/cpuinfo ]; then
  53. cpu_count=$(grep "processor[[:space:]]*:" /proc/cpuinfo | wc -l)
  54. if [ ${cpu_count} -eq 0 ]; then
  55. cpu_count=1
  56. fi
  57. fi
  58. echo "AB:INFO Detected ${cpu_count} CPUs for parallel build"
  59. echo "AB:INFO Making this app for ABI ${TARGET_ABI}"
  60. export SDL_ANDROID_PORT_PATH="${sdl_android_port_path}"
  61. unset BUILD_EXECUTABLE
  62. #"${set_sdl_app_environment}" /bin/bash -c "set"
  63. "${set_sdl_app_environment}" /bin/bash -c "\
  64. echo \"AB:INFO entering openMSX home directory: ${my_home_dir}\"; \
  65. cd ${my_home_dir};\
  66. echo \"AB:INFO CXX: \${CXX}\";\
  67. export _CC=\${CC};\
  68. export _LD=\${LD};\
  69. unset CXXFLAGS;\
  70. unset CFLAGS;\
  71. make -j ${cpu_count} staticbindist\
  72. OPENMSX_TARGET_CPU=${openmsx_target_cpu}\
  73. OPENMSX_TARGET_OS=android\
  74. OPENMSX_FLAVOUR=${openmsx_flavour}\
  75. CXX=${CXX}\
  76. "
  77. if [ $? -ne 0 ]; then
  78. echo "AB:ERROR Make failed"
  79. exit 1
  80. fi
  81. # Return to the directory containing this script and all data about this application
  82. # that the SDL APK build system requires
  83. cd "${my_app_android_dir}"
  84. # Copy the shared library overhere
  85. echo "AB:INFO Copying output file into android directory $(pwd)"
  86. cp "${my_home_dir}/derived/${openmsx_target_cpu}-android-${openmsx_flavour}-3rd/lib/openmsx.so" "${so_file}"
  87. if [ $? -ne 0 ]; then
  88. echo "AB:ERROR Copy failed"
  89. fi
  90. echo "AB:INFO Done with build of app"
  91. echo "AB:INFO Copying icon file"
  92. openmsx_icon_file="${my_home_dir}/share/icons/openMSX-logo-256.png"
  93. cp -p "${openmsx_icon_file}" icon.png
  94. cp -p "${openmsx_icon_file}" banner.png
  95. echo "AB:INFO Building appdata.zip"
  96. rm -f AndroidData/appdata.zip
  97. rm -rf AndroidData/appdata
  98. mkdir -p AndroidData/appdata/openmsx_system
  99. cd "${my_home_dir}"/derived/${openmsx_target_cpu}-android-${openmsx_flavour}-3rd/bindist/install/share
  100. tar -c -f - . | ( cd "${my_app_android_dir}"/AndroidData/appdata/openmsx_system ; tar xf - )
  101. cd "${my_app_android_dir}"/AndroidData/appdata
  102. zip -r ../appdata.zip * > /dev/null
  103. cd ..
  104. rm -rf appdata
  105. echo "AB:INFO Done rebuilding appdata.zip"
  106. MANIFEST="${sdl_android_port_path}/project/AndroidManifest.xml"
  107. # Remove network permissions from manifest. openMSX does not need it.
  108. sed -i "s/<uses-permission android:name=\"android.permission.INTERNET\"><\/uses-permission>/<\!-- -->/" ${MANIFEST}
  109. exit 0