diff options
| author | Po Lu | 2023-03-03 21:13:58 +0800 |
|---|---|---|
| committer | Po Lu | 2023-03-03 21:13:58 +0800 |
| commit | d8ea139e83dc74336569d71e6969cae269547265 (patch) | |
| tree | 7d03f5e8c2b742cdb55fd4753cc7d6dbe1c88f9b /m4 | |
| parent | 48b5a770f247d8c027d209ce941767ab5a7d139d (diff) | |
| download | emacs-d8ea139e83dc74336569d71e6969cae269547265.tar.gz emacs-d8ea139e83dc74336569d71e6969cae269547265.zip | |
Improve ndk-build implementation
* build-aux/ndk-build-helper.mk: Define in terms of BUILD_AUXDIR.
* m4/ndk-build.m4 (ndk_INIT): Find right build-aux directory.
Remove uses of unportable shell constructs.
Diffstat (limited to 'm4')
| -rw-r--r-- | m4/ndk-build.m4 | 185 |
1 files changed, 82 insertions, 103 deletions
diff --git a/m4/ndk-build.m4 b/m4/ndk-build.m4 index 7b5c45997b1..8fe84cee40e 100644 --- a/m4/ndk-build.m4 +++ b/m4/ndk-build.m4 | |||
| @@ -44,6 +44,8 @@ for file in $with_ndk_path; do | |||
| 44 | fi | 44 | fi |
| 45 | done | 45 | done |
| 46 | 46 | ||
| 47 | AC_REQUIRE_AUX_FILE([ndk-build-helper.mk]) | ||
| 48 | ndk_AUX_DIR=$ac_aux_dir | ||
| 47 | ndk_ABI=$1 | 49 | ndk_ABI=$1 |
| 48 | ndk_MODULES= | 50 | ndk_MODULES= |
| 49 | ndk_MAKEFILES= | 51 | ndk_MAKEFILES= |
| @@ -53,29 +55,14 @@ ndk_DIR=$3 | |||
| 53 | ndk_ANY_CXX= | 55 | ndk_ANY_CXX= |
| 54 | ndk_BUILD_CFLAGS="$4" | 56 | ndk_BUILD_CFLAGS="$4" |
| 55 | 57 | ||
| 56 | case "$ndk_ABI" in | 58 | AS_CASE(["$ndk_ABI"], |
| 57 | *arm64* ) | 59 | [*arm64*], [ndk_ARCH=arm64], |
| 58 | ndk_ARCH=arm64 | 60 | [*arm*], [ndk_ARCH=arm], |
| 59 | ;; | 61 | [*x86_64*], [ndk_ARCH=x86_64], |
| 60 | *arm* ) | 62 | [*x86*], [ndk_ARCH=x86], |
| 61 | ndk_ARCH=arm | 63 | [*mips64*], [ndk_ARCH=mips64], |
| 62 | ;; | 64 | [*mips*], [ndk_ARCH=mips], |
| 63 | *x86_64* ) | 65 | [AC_MSG_ERROR([Failed to determine Android device architecture])]) |
| 64 | ndk_ARCH=x86_64 | ||
| 65 | ;; | ||
| 66 | *x86* ) | ||
| 67 | ndk_ARCH=x86 | ||
| 68 | ;; | ||
| 69 | *mips64* ) | ||
| 70 | ndk_ARCH=mips64 | ||
| 71 | ;; | ||
| 72 | *mips* ) | ||
| 73 | ndk_ARCH=mips | ||
| 74 | ;; | ||
| 75 | * ) | ||
| 76 | AC_MSG_ERROR([Failed to determine Android device architecture]) | ||
| 77 | ;; | ||
| 78 | esac | ||
| 79 | 66 | ||
| 80 | # This is a map between pkg-config style package names and Android | 67 | # This is a map between pkg-config style package names and Android |
| 81 | # ones. | 68 | # ones. |
| @@ -89,8 +76,8 @@ ndk_package_map="$ndk_package_map MagickWand:libmagickwand-7 lcms2:liblcms2" | |||
| 89 | 76 | ||
| 90 | ndk_replace_pkg_config_package () { | 77 | ndk_replace_pkg_config_package () { |
| 91 | for ndk_stuff in $ndk_package_map; do | 78 | for ndk_stuff in $ndk_package_map; do |
| 92 | ndk_key=${ndk_stuff%%:*} | 79 | ndk_key=`AS_ECHO([$ndk_stuff]) | cut -d: -f1` |
| 93 | ndk_value=${ndk_stuff#*:} | 80 | ndk_value=`AS_ECHO([$ndk_stuff]) | cut -d: -f2` |
| 94 | 81 | ||
| 95 | if test "$ndk_key" = "$ndk_module"; then | 82 | if test "$ndk_key" = "$ndk_module"; then |
| 96 | ndk_module="$ndk_value" | 83 | ndk_module="$ndk_value" |
| @@ -99,6 +86,28 @@ ndk_replace_pkg_config_package () { | |||
| 99 | done | 86 | done |
| 100 | } | 87 | } |
| 101 | 88 | ||
| 89 | # Run the Makefile helper script for the Android.mk file. | ||
| 90 | |||
| 91 | ndk_run_test () { | ||
| 92 | # Figure out where the helper Makefile is. | ||
| 93 | ndk_build_helper_file="${ndk_AUX_DIR}ndk-build-helper.mk" | ||
| 94 | ndk_module_extract_awk="${ndk_AUX_DIR}ndk-module-extract.awk" | ||
| 95 | ndk_dir=`AS_DIRNAME([$ndk_android_mk])` | ||
| 96 | |||
| 97 | # Now call Make with the right arguments. | ||
| 98 | "$MAKE" -s -f "$ndk_build_helper_file" EMACS_SRCDIR=`pwd` \ | ||
| 99 | EMACS_ABI="$ndk_ABI" ANDROID_MAKEFILE="$ndk_android_mk" \ | ||
| 100 | NDK_BUILD_DIR="$ndk_DIR" NDK_ROOT="/tmp" \ | ||
| 101 | ANDROID_MODULE_DIRECTORY="$ndk_dir" BUILD_AUXDIR=$ndk_AUX_DIR \ | ||
| 102 | 2>&AS_MESSAGE_LOG_FD >conftest.ndk | ||
| 103 | |||
| 104 | # Read the output. | ||
| 105 | cat conftest.ndk | awk -f "$ndk_module_extract_awk" MODULE="$ndk_module" | ||
| 106 | |||
| 107 | # Remove the temporary file. | ||
| 108 | rm -f conftest.ndk | ||
| 109 | } | ||
| 110 | |||
| 102 | # ndk_parse_pkg_config_string PKG_CONFIG_STRING | 111 | # ndk_parse_pkg_config_string PKG_CONFIG_STRING |
| 103 | # --------------------------------------------- | 112 | # --------------------------------------------- |
| 104 | # Parse a pkg-config style list of modules. Place the resulting list | 113 | # Parse a pkg-config style list of modules. Place the resulting list |
| @@ -108,13 +117,13 @@ ndk_parse_pkg_config_string () { | |||
| 108 | ndk_input=[$]1 | 117 | ndk_input=[$]1 |
| 109 | ndk_modules= | 118 | ndk_modules= |
| 110 | while test -n "$ndk_input"; do | 119 | while test -n "$ndk_input"; do |
| 111 | ndk_str=$(printf "$ndk_input" | cut -f1 -d' ') | 120 | ndk_str=`AS_ECHO_N(["$ndk_input"]) | cut -f1 -d' '` |
| 112 | ndk_input="$(printf "$ndk_input" | cut -s -f2- -d' ')" | 121 | ndk_input=`AS_ECHO_N(["$ndk_input"]) | cut -s -f2- -d' '` |
| 113 | 122 | ||
| 114 | if test "$ndk_str" = ">=" || test "$ndk_str" = "<=" \ | 123 | if test "$ndk_str" = ">=" || test "$ndk_str" = "<=" \ |
| 115 | || test "$ndk_str" = ">" || test "$ndk_str" = "<" \ | 124 | || test "$ndk_str" = ">" || test "$ndk_str" = "<" \ |
| 116 | || test "$ndk_str" = "!="; then | 125 | || test "$ndk_str" = "!="; then |
| 117 | ndk_input="$(printf "$ndk_input" | cut -s -f2- -d' ')" | 126 | ndk_input=`AS_ECHO_N(["$ndk_input"]) | cut -s -f2- -d' '` |
| 118 | else | 127 | else |
| 119 | ndk_modules="$ndk_modules$ndk_str " | 128 | ndk_modules="$ndk_modules$ndk_str " |
| 120 | fi | 129 | fi |
| @@ -137,13 +146,7 @@ ndk_resolve_import_module () { | |||
| 137 | # Read this Android.mk file. Set NDK_ROOT to /tmp: the Android in | 146 | # Read this Android.mk file. Set NDK_ROOT to /tmp: the Android in |
| 138 | # tree build system sets it to a meaning value, but build files | 147 | # tree build system sets it to a meaning value, but build files |
| 139 | # just use it to test whether or not the NDK is being used. | 148 | # just use it to test whether or not the NDK is being used. |
| 140 | ndk_commands=$(($MAKE -s -f build-aux/ndk-build-helper.mk EMACS_SRCDIR=. \ | 149 | ndk_commands=`ndk_run_test` |
| 141 | EMACS_ABI=$ndk_ABI ANDROID_MAKEFILE="$ndk_android_mk" \ | ||
| 142 | ANDROID_MODULE_DIRECTORY=$(dirname "$ndk_android_mk") \ | ||
| 143 | NDK_BUILD_DIR="$ndk_DIR" NDK_ROOT="/tmp" \ | ||
| 144 | 2>&AS_MESSAGE_LOG_FD) \ | ||
| 145 | | awk -f build-aux/ndk-module-extract.awk \ | ||
| 146 | MODULE="$ndk_module") | ||
| 147 | 150 | ||
| 148 | AS_IF([test -n "${ndk_commands//\n }"], [eval "$ndk_commands"]) | 151 | AS_IF([test -n "${ndk_commands//\n }"], [eval "$ndk_commands"]) |
| 149 | 152 | ||
| @@ -152,21 +155,19 @@ ndk_resolve_import_module () { | |||
| 152 | fi | 155 | fi |
| 153 | done | 156 | done |
| 154 | 157 | ||
| 155 | if test -z "$module_name"; then | 158 | AS_IF([test -z "$module_name"], |
| 156 | AC_MSG_RESULT([no]) | 159 | [AC_MSG_RESULT([no]) |
| 157 | AC_MSG_ERROR([The module currently being built depends on [$]1, but \ | 160 | AC_MSG_ERROR([The module currently being built depends on [$]1, but \ |
| 158 | that could not be found in the list of directories specified in \ | 161 | that could not be found in the list of directories specified in \ |
| 159 | `--with-ndk-path'.]) | 162 | `--with-ndk-path'.])]) |
| 160 | fi | ||
| 161 | 163 | ||
| 162 | if test -n "$module_cxx_deps"; then | 164 | if test -n "$module_cxx_deps"; then |
| 163 | ndk_ANY_CXX=yes | 165 | ndk_ANY_CXX=yes |
| 164 | fi | 166 | fi |
| 165 | 167 | ||
| 166 | if test "$ndk_ANY_CXX" = "yes" && test -z "$with_ndk_cxx_shared"; then | 168 | AS_IF([test "$ndk_ANY_CXX" = "yes" && test -z "$with_ndk_cxx_shared"], |
| 167 | AC_MSG_ERROR([The module [$]1 requires the C++ standard library \ | 169 | [AC_MSG_ERROR([The module [$]1 requires the C++ standard library \ |
| 168 | (libc++_shared.so), but it was not found.]) | 170 | (libc++_shared.so), but it was not found.])]) |
| 169 | fi | ||
| 170 | 171 | ||
| 171 | AC_MSG_RESULT([yes]) | 172 | AC_MSG_RESULT([yes]) |
| 172 | 173 | ||
| @@ -181,35 +182,34 @@ that could not be found in the list of directories specified in \ | |||
| 181 | } | 182 | } |
| 182 | 183 | ||
| 183 | # Look for a suitable ar in the same directory as the C compiler. | 184 | # Look for a suitable ar in the same directory as the C compiler. |
| 184 | ndk_where_cc=$(which $(echo "$CC" | awk -- "{ print \[$]1 }")) | 185 | ndk_cc_firstword=`AS_ECHO([$CC]) | cut -d' ' -f1` |
| 186 | ndk_where_cc=`which $ndk_cc_firstword` | ||
| 185 | ndk_ar_search_path=$PATH | 187 | ndk_ar_search_path=$PATH |
| 186 | 188 | ||
| 187 | # First, try to find $host_alias-ar in PATH. | 189 | # First, try to find $host_alias-ar in PATH. |
| 188 | AC_PATH_PROGS([AR], [$host_alias-ar], [], [$ndk_ar_search_path]) | 190 | AC_PATH_PROGS([AR], [$host_alias-ar], [], [$ndk_ar_search_path]) |
| 189 | 191 | ||
| 190 | if test -z "$AR"; then | 192 | AS_IF([test -z "$AR"],[ |
| 191 | # Next, try finding either that or llvm-ar in the directory holding | 193 | # Next, try finding either that or llvm-ar in the directory holding |
| 192 | # CC. | 194 | # CC. |
| 193 | ndk_ar_search_path="$(dirname $ndk_where_cc):$ndk_ar_search_path" | 195 | ndk_ar_search_path="`AS_DIRNAME([$ndk_where_cc])`:$ndk_ar_search_path" |
| 194 | AC_PATH_PROGS([AR], [$host_alias-ar llvm-ar], [], [$ndk_ar_search_path]) | 196 | AC_PATH_PROGS([AR], [$host_alias-ar llvm-ar], [], [$ndk_ar_search_path])]) |
| 195 | fi | ||
| 196 | 197 | ||
| 197 | NDK_BUILD_NASM= | 198 | NDK_BUILD_NASM= |
| 198 | 199 | ||
| 199 | # Next, try to find nasm on x86. This doesn't ship with the NDK. | 200 | # Next, try to find nasm on x86. This doesn't ship with the NDK. |
| 200 | if test "$ndk_ARCH" = "x86" || test "$ndk_ARCH" = "x86_64"; then | 201 | AS_IF([test "$ndk_ARCH" = "x86" || test "$ndk_ARCH" = "x86_64"], |
| 201 | AC_CHECK_PROGS([NDK_BUILD_NASM], [nasm]) | 202 | [AC_CHECK_PROGS([NDK_BUILD_NASM], [nasm])]) |
| 202 | fi | ||
| 203 | 203 | ||
| 204 | # Look for a file named ``libc++_shared.so'' in a subdirectory of | 204 | # Look for a file named ``libc++_shared.so'' in a subdirectory of |
| 205 | # $ndk_where_cc if it was not specified. | 205 | # $ndk_where_cc if it was not specified. |
| 206 | AC_MSG_CHECKING([for libc++_shared.so]) | 206 | AC_MSG_CHECKING([for libc++_shared.so]) |
| 207 | 207 | ||
| 208 | ndk_where_toolchain= | 208 | ndk_where_toolchain= |
| 209 | if test -z "$with_ndk_cxx_shared" && test -n "$ndk_where_cc"; then | 209 | AS_IF([test -z "$with_ndk_cxx_shared" && test -n "$ndk_where_cc"],[ |
| 210 | # Find the NDK root directory. Go to $ndk_where_cc. | 210 | # Find the NDK root directory. Go to $ndk_where_cc. |
| 211 | SAVE_PWD=`pwd` | 211 | SAVE_PWD=`pwd` |
| 212 | cd $(dirname "$ndk_where_cc") | 212 | cd `dirname "$ndk_where_cc"` |
| 213 | 213 | ||
| 214 | # Now, keep moving backwards until pwd ends with ``toolchains''. | 214 | # Now, keep moving backwards until pwd ends with ``toolchains''. |
| 215 | while :; do | 215 | while :; do |
| @@ -218,8 +218,9 @@ if test -z "$with_ndk_cxx_shared" && test -n "$ndk_where_cc"; then | |||
| 218 | break | 218 | break |
| 219 | fi | 219 | fi |
| 220 | 220 | ||
| 221 | if test "`basename $(pwd)`" = "toolchains"; then | 221 | ndk_pwd=`pwd` |
| 222 | ndk_where_toolchain=`pwd` | 222 | if test "`AS_BASENAME([$ndk_pwd])`" = "toolchains"; then |
| 223 | ndk_where_toolchain=$ndk_pwd | ||
| 223 | cd "$SAVE_PWD" | 224 | cd "$SAVE_PWD" |
| 224 | break | 225 | break |
| 225 | fi | 226 | fi |
| @@ -230,51 +231,36 @@ if test -z "$with_ndk_cxx_shared" && test -n "$ndk_where_cc"; then | |||
| 230 | ndk_matching_libcxx_shared_so= | 231 | ndk_matching_libcxx_shared_so= |
| 231 | 232 | ||
| 232 | # The toolchain directory should be in "$ndk_where_toolchain". | 233 | # The toolchain directory should be in "$ndk_where_toolchain". |
| 233 | if test -n "$ndk_where_toolchain"; then | 234 | AS_IF([test -n "$ndk_where_toolchain"],[ |
| 234 | # Now, look in the directory behind it. | 235 | # Now, look in the directory behind it. |
| 235 | ndk_cxx_shared_so=`find "$ndk_where_toolchain" -name libc++_shared.so` | 236 | ndk_cxx_shared_so=`find "$ndk_where_toolchain" -name libc++_shared.so` |
| 236 | 237 | ||
| 237 | # Look for one with the correct architecture. | 238 | # Look for one with the correct architecture. |
| 238 | for ndk_candidate in $ndk_cxx_shared_so; do | 239 | for ndk_candidate in $ndk_cxx_shared_so; do |
| 239 | case "$ndk_candidate" in | 240 | AS_CASE([$ndk_candidate], |
| 240 | *arm-linux-android* ) | 241 | [*arm-linux-android*], |
| 241 | if test "$ndk_ARCH" = "arm"; then | 242 | [AS_IF([test "$ndk_ARCH" = "arm"], |
| 242 | ndk_matching_libcxx_shared_so=$ndk_candidate | 243 | [ndk_matching_libcxx_shared_so=$ndk_candidate])], |
| 243 | fi | 244 | [*aarch64-linux-android*], |
| 244 | ;; | 245 | [AS_IF([test "$ndk_ARCH" = "arm64"], |
| 245 | *aarch64-linux-android* ) | 246 | [ndk_matching_libcxx_shared_so=$ndk_candidate])], |
| 246 | if test "$ndk_ARCH" = "arm64"; then | 247 | [*i[[3-6]]86-linux-android*], |
| 247 | ndk_matching_libcxx_shared_so=$ndk_candidate | 248 | [AS_IF([test "$ndk_ARCH" = "x86"], |
| 248 | fi | 249 | [ndk_matching_libcxx_shared_so=$ndk_candidate])], |
| 249 | ;; | 250 | [*x86_64-linux-android*], |
| 250 | *i[[3-6]]86-linux-android* ) | 251 | [AS_IF([test "$ndk_ARCH" = "x86_64"], |
| 251 | if test "$ndk_ARCH" = "x86"; then | 252 | [ndk_matching_libcxx_shared_so=$ndk_candidate])]) |
| 252 | ndk_matching_libcxx_shared_so=$ndk_candidate | 253 | |
| 253 | fi | 254 | AS_IF([test -n "$ndk_matching_libcxx_shared_so"], |
| 254 | ;; | 255 | [with_ndk_cxx_shared=$ndk_matching_libcxx_shared_so]) |
| 255 | *x86_64-linux-android* ) | 256 | done])]) |
| 256 | if test "$ndk_ARCH" = "x86_64"; then | 257 | |
| 257 | ndk_matching_libcxx_shared_so=$ndk_candidate | 258 | AS_IF([test -z "$with_ndk_cxx_shared"],[AC_MSG_RESULT([no]) |
| 258 | fi | ||
| 259 | ;; | ||
| 260 | esac | ||
| 261 | |||
| 262 | if test -n "$ndk_matching_libcxx_shared_so"; then | ||
| 263 | with_ndk_cxx_shared=$ndk_matching_libcxx_shared_so | ||
| 264 | fi | ||
| 265 | done | ||
| 266 | fi | ||
| 267 | fi | ||
| 268 | |||
| 269 | if test -z "$with_ndk_cxx_shared"; then | ||
| 270 | AC_MSG_RESULT([no]) | ||
| 271 | AC_MSG_WARN([The C++ standard library could not be found. \ | 259 | AC_MSG_WARN([The C++ standard library could not be found. \ |
| 272 | If you try to build Emacs with a dependency that requires the C++ standard \ | 260 | If you try to build Emacs with a dependency that requires the C++ standard \ |
| 273 | library, Emacs will not build correctly, unless you manually specify the \ | 261 | library, Emacs will not build correctly, unless you manually specify the \ |
| 274 | name of an appropriate ``libc++_shared.so'' binary.]) | 262 | name of an appropriate ``libc++_shared.so'' binary.])], |
| 275 | else | 263 | [AC_MSG_RESULT([$with_ndk_cxx_shared])]) |
| 276 | AC_MSG_RESULT([$with_ndk_cxx_shared]) | ||
| 277 | fi | ||
| 278 | 264 | ||
| 279 | ndk_CXX_SHARED=$with_ndk_cxx_shared | 265 | ndk_CXX_SHARED=$with_ndk_cxx_shared |
| 280 | 266 | ||
| @@ -301,18 +287,11 @@ for ndk_android_mk in $ndk_module_files; do | |||
| 301 | # Read this Android.mk file. Set NDK_ROOT to /tmp: the Android in | 287 | # Read this Android.mk file. Set NDK_ROOT to /tmp: the Android in |
| 302 | # tree build system sets it to a meaning value, but build files just | 288 | # tree build system sets it to a meaning value, but build files just |
| 303 | # use it to test whether or not the NDK is being used. | 289 | # use it to test whether or not the NDK is being used. |
| 304 | ndk_commands=$(($MAKE -s -f build-aux/ndk-build-helper.mk EMACS_SRCDIR=. \ | 290 | ndk_commands=`ndk_run_test` |
| 305 | EMACS_ABI=$ndk_ABI ANDROID_MAKEFILE="$ndk_android_mk" \ | ||
| 306 | ANDROID_MODULE_DIRECTORY=$(dirname "$ndk_android_mk") \ | ||
| 307 | NDK_BUILD_DIR="$ndk_DIR" NDK_ROOT="/tmp" \ | ||
| 308 | 2>&AS_MESSAGE_LOG_FD) \ | ||
| 309 | | awk -f build-aux/ndk-module-extract.awk \ | ||
| 310 | MODULE="$ndk_module") | ||
| 311 | |||
| 312 | AS_IF([test -n "${ndk_commands//\n }"], [eval "$ndk_commands"]) | ||
| 313 | 291 | ||
| 292 | eval "$ndk_commands" | ||
| 314 | if test -n "$module_name"; then | 293 | if test -n "$module_name"; then |
| 315 | break | 294 | break; |
| 316 | fi | 295 | fi |
| 317 | done | 296 | done |
| 318 | 297 | ||