summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2023-01-26 15:37:04 +0800
committerPo Lu <luangruo@yahoo.com>2023-01-26 15:37:04 +0800
commit4255d7f0514c5fa1badded6b0bc445ec2d2764c0 (patch)
tree93efa03d4ba0c1987eab16645f9ebcc405ab9e19 /m4
parent8125e26a323cb8906a14005519b0fa5693718c90 (diff)
downloademacs-4255d7f0514c5fa1badded6b0bc445ec2d2764c0.tar.gz
Update Android port
* .gitignore: Ignore lib/math.h. * INSTALL.android: Update accordingly. * build-aux/ndk-build-helper-1.mk: * build-aux/ndk-build-helper-2.mk: * build-aux/ndk-build-helper.mk: * build-aux/ndk-module-extract.awk: Handle C++ modules. * configure.ac: Enable libxml2 on Android. * cross/ndk-build/Makefile.in: * cross/ndk-build/ndk-build-shared-library.mk: * cross/ndk-build/ndk-build-static-library.mk: * cross/ndk-build/ndk-build.mk.in: * cross/ndk-build/ndk-resolve.mk: Fix dependency resolution of includes. * java/org/gnu/emacs/EmacsView.java (popupMenu): Fix minimum SDK version for actual popup menus. * lib/math.h: Delete file. * m4/ndk-build.m4 (ndk_SEARCH_MODULE, ndk_CHECK_MODULES): Look for nasm and C++ libraries. * src/android.c (faccessat): Rename to `android_faccessat'. * src/android.h: Update prototypes. * src/dired.c (file_name_completion_dirp): * src/fileio.c (file_access_p, Faccess_file, file_directory_p): * src/lisp.h: * src/lread.c (openp): * src/process.c (allocate_pty): Use sys_faccessat. * src/sysdep.c (sys_faccessat): New function.
Diffstat (limited to 'm4')
-rw-r--r--m4/ndk-build.m4180
1 files changed, 175 insertions, 5 deletions
diff --git a/m4/ndk-build.m4 b/m4/ndk-build.m4
index d3614a9f490..27092e4b400 100644
--- a/m4/ndk-build.m4
+++ b/m4/ndk-build.m4
@@ -21,6 +21,10 @@ AC_ARG_WITH([ndk_path],
[AS_HELP_STRING([--with-ndk-path],
[find Android libraries in these directories])])
+AC_ARG_WITH([ndk_cxx_shared],
+ [AS_HELP_STRING([--with-ndk-cxx-shared],
+ [name of the C++ standard library included with the NDK])])
+
# ndk_INIT(ABI, API, DIR)
# --------
# Initialize the Android NDK. ABI is the ABI being built for.
@@ -45,6 +49,7 @@ ndk_MAKEFILES=
ndk_INITIALIZED=yes
ndk_API=$2
ndk_DIR=$3
+ndk_ANY_CXX=
case "$ndk_ABI" in
*arm64* )
@@ -103,6 +108,62 @@ ndk_parse_pkg_config_string () {
done
}
+# Resolve $1, a single import. Prepend its makefile to ndk_MAKEFILES
+# if found. Also, prepend all includes to the variable
+# ndk_import_includes.
+
+ndk_resolve_import_module () {
+ module_name=
+ ndk_module=[$]1
+
+ AC_MSG_CHECKING([for imported $ndk_module])
+
+ for ndk_android_mk in $ndk_module_files; do
+ # Read this Android.mk file. Set NDK_ROOT to /tmp: the Android in
+ # tree build system sets it to a meaning value, but build files
+ # just use it to test whether or not the NDK is being used.
+ ndk_commands=$($MAKE -s -f build-aux/ndk-build-helper.mk EMACS_SRCDIR=. \
+ EMACS_ABI=$ndk_ABI ANDROID_MAKEFILE="$ndk_android_mk" \
+ ANDROID_MODULE_DIRECTORY=$(dirname "$ndk_android_mk") \
+ NDK_BUILD_DIR="$ndk_DIR" NDK_ROOT="/tmp" \
+ | awk -f build-aux/ndk-module-extract.awk \
+ MODULE="$ndk_module")
+
+ AS_IF([test -n "${ndk_commands//\n }"], [eval "$ndk_commands"])
+
+ if test -n "$module_name"; then
+ break;
+ fi
+ done
+
+ if test -z "$module_name"; then
+ AC_MSG_RESULT([no])
+ AC_MSG_ERROR([The module currently being built depends on [$]1, but \
+that could not be found in the list of directories specified in \
+`--with-ndk-path'.])
+ fi
+
+ if test -n "$module_cxx_deps"; then
+ ndk_ANY_CXX=yes
+ fi
+
+ if test "$ndk_ANY_CXX" = "yes" && test -z "$with_ndk_cxx_shared"; then
+ AC_MSG_ERROR([The module [$]1 requires the C++ standard library \
+(libc++_shared.so), but it was not found.])
+ fi
+
+ AC_MSG_RESULT([yes])
+
+ # Make sure the module is prepended.
+ ndk_MAKEFILES="$ndk_android_mk $ndk_MAKEFILES"
+ ndk_import_includes="$module_includes $ndk_import_includes"
+
+ # Now recursively resolve this module's imports.
+ for ndk_module in $module_imports; do
+ ndk_resolve_import_module $ndk_module
+ done
+}
+
# Look for a suitable ar in the same directory as the C compiler.
ndk_where_cc=$(which $CC)
ndk_ar_search_path=$PATH
@@ -117,15 +178,102 @@ if test -z "$AR"; then
AC_PATH_PROGS([AR], [$host_alias-ar llvm-ar], [], [$ndk_ar_search_path])
fi
+NDK_BUILD_NASM=
+
+# Next, try to find nasm on x86. This doesn't ship with the NDK.
+if test "$ndk_ARCH" = "x86" || test "$ndk_ARCH" = "x86_64"; then
+ AC_CHECK_PROGS([NDK_BUILD_NASM], [nasm])
+fi
+
+# Look for a file named ``libc++_shared.so'' in a subdirectory of
+# $ndk_where_cc if it was not specified.
+AC_MSG_CHECKING([for libc++_shared.so])
+
+ndk_where_toolchain=
+if test -z "$with_ndk_cxx_shared" && test -n "$ndk_where_cc"; then
+ # Find the NDK root directory. Go to $ndk_where_cc.
+ SAVE_PWD=`pwd`
+ cd $(dirname "$ndk_where_cc")
+
+ # Now, keep moving backwards until pwd ends with ``toolchains''.
+ while :; do
+ if test "`pwd`" = "/"; then
+ cd "$SAVE_PWD"
+ break
+ fi
+
+ if test "`basename $(pwd)`" = "toolchains"; then
+ ndk_where_toolchain=`pwd`
+ cd "$SAVE_PWD"
+ break
+ fi
+
+ cd ..
+ done
+
+ ndk_matching_libcxx_shared_so=
+
+ # The toolchain directory should be in "$ndk_where_toolchain".
+ if test -n "$ndk_where_toolchain"; then
+ # Now, look in the directory behind it.
+ ndk_cxx_shared_so=`find "$ndk_where_toolchain" -name libc++_shared.so`
+
+ # Look for one with the correct architecture.
+ for ndk_candidate in $ndk_cxx_shared_so; do
+ case "$ndk_candidate" in
+ *arm-linux-android* )
+ if test "$ndk_ARCH" = "arm"; then
+ ndk_matching_libcxx_shared_so=$ndk_candidate
+ fi
+ ;;
+ *aarch64-linux-android* )
+ if test "$ndk_ARCH" = "arm64"; then
+ ndk_matching_libcxx_shared_so=$ndk_candidate
+ fi
+ ;;
+ *i[[3-6]]86-linux-android* )
+ if test "$ndk_ARCH" = "x86"; then
+ ndk_matching_libcxx_shared_so=$ndk_candidate
+ fi
+ ;;
+ *x86_64-linux-android* )
+ if test "$ndk_ARCH" = "x86_64"; then
+ ndk_matching_libcxx_shared_so=$ndk_candidate
+ fi
+ ;;
+ esac
+
+ if test -n "$ndk_matching_libcxx_shared_so"; then
+ with_ndk_cxx_shared=$ndk_matching_libcxx_shared_so
+ fi
+ done
+ fi
+fi
+
+if test -z "$with_ndk_cxx_shared"; then
+ AC_MSG_RESULT([no])
+ AC_MSG_WARN([The C++ standard library could not be found. \
+If you try to build Emacs with a dependency that requires the C++ standard \
+library, Emacs will not build correctly, unless you manually specify the \
+name of an appropriate ``libc++_shared.so'' binary.])
+else
+ AC_MSG_RESULT([$with_ndk_cxx_shared])
+fi
+
+ndk_CXX_SHARED=$with_ndk_cxx_shared
+
# These variables have now been found.
])
# ndk_SEARCH_MODULE(MODULE, NAME, ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND])
-# --------------------------------------------------------------------
+# -----------------------------------------------------------------------
# Search for a module named MODULE in `with_ndk_path'. Add the file
-# name of the module's Android.mk file to the variable ndk_MODULES.
-# Set NAME_CFLAGS and NAME_LIBS to the appropriate values. Then,
-# call ACTION-IF-FOUND, or ACTION-IF-NOT-FOUND upon failure.
+# name of the module's Android.mk file to the variable ndk_MAKEFILES.
+# Set NAME_CFLAGS and NAME_LIBS to the appropriate values. Then, call
+# ACTION-IF-FOUND, or ACTION-IF-NOT-FOUND upon failure.
+#
+# Resolve any imports specified by MODULE, and expand AC_MSG_ERROR
+# with a suitable error message if imports were not found.
AC_DEFUN([ndk_SEARCH_MODULE],
[
module_name=
@@ -137,7 +285,7 @@ for ndk_android_mk in $ndk_module_files; do
# Read this Android.mk file. Set NDK_ROOT to /tmp: the Android in
# tree build system sets it to a meaning value, but build files just
# use it to test whether or not the NDK is being used.
- ndk_commands=$(make -s -f build-aux/ndk-build-helper.mk EMACS_SRCDIR=. \
+ ndk_commands=$($MAKE -s -f build-aux/ndk-build-helper.mk EMACS_SRCDIR=. \
EMACS_ABI=$ndk_ABI ANDROID_MAKEFILE="$ndk_android_mk" \
ANDROID_MODULE_DIRECTORY=$(dirname "$ndk_android_mk") \
NDK_BUILD_DIR="$ndk_DIR" NDK_ROOT="/tmp" \
@@ -155,12 +303,29 @@ if test -z "$module_name"; then
AC_MSG_RESULT([no])
$4
else
+ if test -n "$module_cxx_deps"; then
+ ndk_ANY_CXX=yes
+ fi
+
+ if test "$ndk_ANY_CXX" = "yes" && test -z "$with_ndk_cxx_shared"; then
+ AC_MSG_ERROR([The module $1 requires the C++ standard library \
+(libc++_shared.so), but it was not found.])
+ fi
+
$2[]_CFLAGS="[$]$2[]_CFLAGS $module_cflags $module_includes"
$2[]_LIBS="[$]$2[]_LIBS $module_ldflags"
ndk_MAKEFILES="$ndk_MAKEFILES $ndk_android_mk"
ndk_MODULES="$ndk_MODULES $module_target"
AC_MSG_RESULT([yes])
$3
+
+ # Now, resolve imports. Make sure the imports' Makefiles comes
+ # before ndk_MAKEFILES; likewise for its includes.
+ ndk_import_includes=
+ for ndk_module in $module_imports; do
+ ndk_resolve_import_module $ndk_module
+ $2[]_CFLAGS="$ndk_import_includes [$]$2[]_CFLAGS"
+ done
fi
])
@@ -198,6 +363,8 @@ AC_DEFUN_ONCE([ndk_CONFIG_FILES],
NDK_BUILD_CC=$CC
NDK_BUILD_AR=$AR
NDK_BUILD_MODULES="$ndk_MODULES"
+ NDK_BUILD_CXX_SHARED="$ndk_CXX_SHARED"
+ NDK_BUILD_ANY_CXX_MODULE=$ndk_ANY_CXX
AC_SUBST([NDK_BUILD_ANDROID_MK])
AC_SUBST([NDK_BUILD_ARCH])
@@ -205,7 +372,10 @@ AC_DEFUN_ONCE([ndk_CONFIG_FILES],
AC_SUBST([NDK_BUILD_SDK])
AC_SUBST([NDK_BUILD_CC])
AC_SUBST([NDK_BUILD_AR])
+ AC_SUBST([NDK_BUILD_NASM])
AC_SUBST([NDK_BUILD_MODULES])
+ AC_SUBST([NDK_BUILD_CXX_SHARED])
+ AC_SUBST([NDK_BUILD_ANY_CXX_MODULE])
AC_CONFIG_FILES([$ndk_DIR/Makefile])
AC_CONFIG_FILES([$ndk_DIR/ndk-build.mk])