aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2023-03-04 11:19:25 +0800
committerPo Lu2023-03-04 11:19:25 +0800
commit0e995d06a8df4660a4eca63673087d2df63bf8b0 (patch)
treef748106c90ac4aa12ec6e65dc65645d5c4b4c852
parent0d363aded1e33762f9ed91aef2497a162de956b2 (diff)
downloademacs-0e995d06a8df4660a4eca63673087d2df63bf8b0.tar.gz
emacs-0e995d06a8df4660a4eca63673087d2df63bf8b0.zip
Improve support for building Android C++ dependencies
* configure.ac: Call ndk_LATE after gl_EARLY. * cross/ndk-build/Makefile.in (NDK_BUILD_CXX): New variable. * cross/ndk-build/ndk-build-shared-library.mk: * cross/ndk-build/ndk-build-static-library.mk: Use it. * java/INSTALL: Describe how to build C++ dependencies. * m4/ndk-build.m4 (ndk_LATE): New macro. (ndk_INIT): Try to find a suitable C++ compiler. (ndk_CHECK_MODULES): Make sure the C++ compiler works before allowing C++ dependencies.
-rw-r--r--configure.ac3
-rw-r--r--cross/ndk-build/Makefile.in1
-rw-r--r--cross/ndk-build/ndk-build-shared-library.mk4
-rw-r--r--cross/ndk-build/ndk-build-static-library.mk4
-rw-r--r--java/INSTALL18
-rw-r--r--m4/ndk-build.m494
6 files changed, 114 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac
index 0eb7db1cb29..e15d0c7ef39 100644
--- a/configure.ac
+++ b/configure.ac
@@ -173,6 +173,7 @@ if test "$XCONFIGURE" = "android"; then
173 # NDK require them to be able to find system includes. 173 # NDK require them to be able to find system includes.
174 with_ndk_path="$android_ndk_path" 174 with_ndk_path="$android_ndk_path"
175 with_ndk_cxx_shared="$android_ndk_cxx_shared" 175 with_ndk_cxx_shared="$android_ndk_cxx_shared"
176 with_ndk_cxx="$android_ndk_cxx"
176 ndk_INIT([$android_abi], [$ANDROID_SDK], [cross/ndk-build],\ 177 ndk_INIT([$android_abi], [$ANDROID_SDK], [cross/ndk-build],\
177 [$ANDROID_CFLAGS]) 178 [$ANDROID_CFLAGS])
178fi 179fi
@@ -1155,6 +1156,7 @@ package will likely install on older systems but crash on startup.])
1155 ANDROID_SDK="$android_sdk" android_abi=$android_abi \ 1156 ANDROID_SDK="$android_sdk" android_abi=$android_abi \
1156 android_ndk_path="$with_ndk_path" \ 1157 android_ndk_path="$with_ndk_path" \
1157 android_ndk_cxx_shared="$with_ndk_cxx_shared" \ 1158 android_ndk_cxx_shared="$with_ndk_cxx_shared" \
1159 android_ndk_cxx="$android_ndk_cxx" \
1158 $0 $passthrough], [], 1160 $0 $passthrough], [],
1159 [AC_MSG_ERROR([Failed to cross-configure Emacs for android.])]) 1161 [AC_MSG_ERROR([Failed to cross-configure Emacs for android.])])
1160 1162
@@ -1472,6 +1474,7 @@ AC_DEFUN([gt_TYPE_WINT_T],
1472# Initialize gnulib right after choosing the compiler. 1474# Initialize gnulib right after choosing the compiler.
1473dnl Amongst other things, this sets AR and ARFLAGS. 1475dnl Amongst other things, this sets AR and ARFLAGS.
1474gl_EARLY 1476gl_EARLY
1477ndk_LATE
1475 1478
1476if test "$ac_test_CFLAGS" != set; then 1479if test "$ac_test_CFLAGS" != set; then
1477 # It's helpful to have C macros available to GDB, so prefer -g3 to -g 1480 # It's helpful to have C macros available to GDB, so prefer -g3 to -g
diff --git a/cross/ndk-build/Makefile.in b/cross/ndk-build/Makefile.in
index b546c5b6231..cdf18471ff3 100644
--- a/cross/ndk-build/Makefile.in
+++ b/cross/ndk-build/Makefile.in
@@ -29,6 +29,7 @@ NDK_BUILD_ANDROID_MK = @NDK_BUILD_ANDROID_MK@
29 NDK_BUILD_ABI = @NDK_BUILD_ABI@ 29 NDK_BUILD_ABI = @NDK_BUILD_ABI@
30 NDK_BUILD_SDK = @NDK_BUILD_SDK@ 30 NDK_BUILD_SDK = @NDK_BUILD_SDK@
31 NDK_BUILD_CC = @NDK_BUILD_CC@ 31 NDK_BUILD_CC = @NDK_BUILD_CC@
32 NDK_BUILD_CXX = @NDK_BUILD_CXX@
32 NDK_BUILD_AR = @NDK_BUILD_AR@ 33 NDK_BUILD_AR = @NDK_BUILD_AR@
33 NDK_BUILD_NASM = @NDK_BUILD_NASM@ 34 NDK_BUILD_NASM = @NDK_BUILD_NASM@
34 NDK_BUILD_CFLAGS = @NDK_BUILD_CFLAGS@ 35 NDK_BUILD_CFLAGS = @NDK_BUILD_CFLAGS@
diff --git a/cross/ndk-build/ndk-build-shared-library.mk b/cross/ndk-build/ndk-build-shared-library.mk
index 12712265de2..3a400644070 100644
--- a/cross/ndk-build/ndk-build-shared-library.mk
+++ b/cross/ndk-build/ndk-build-shared-library.mk
@@ -46,7 +46,7 @@ else
46ifeq (x$(suffix $(1)),x.$(or $(LOCAL_CPP_EXTENSION),cpp)) 46ifeq (x$(suffix $(1)),x.$(or $(LOCAL_CPP_EXTENSION),cpp))
47 47
48$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1)) 48$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1))
49 $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_BUILD_CFLAGS_CXX) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) 49 $(NDK_BUILD_CXX) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_BUILD_CFLAGS_CXX) $(NDK_CXXFLAGS_$(LOCAL_MODULE))
50 50
51else 51else
52ifneq ($(or $(call eq,x$(suffix $(1)),x.s),$(call eq,x$(suffix $(1)),x.S)),) 52ifneq ($(or $(call eq,x$(suffix $(1)),x.s),$(call eq,x$(suffix $(1)),x.S)),)
@@ -59,7 +59,7 @@ ifneq (x$(suffix $(1)),x.asm)
59ifeq (x$(suffix $(1)),x.cc) 59ifeq (x$(suffix $(1)),x.cc)
60 60
61$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2)) 61$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2))
62 $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_BUILD_CFLAGS_CXX) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) 62 $(NDK_BUILD_CXX) -c $$< -o $$@ $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_BUILD_CFLAGS_CXX) $(NDK_CXXFLAGS_$(LOCAL_MODULE))
63 63
64else 64else
65$$(error Unsupported suffix: $(suffix $(1))) 65$$(error Unsupported suffix: $(suffix $(1)))
diff --git a/cross/ndk-build/ndk-build-static-library.mk b/cross/ndk-build/ndk-build-static-library.mk
index 163a4487e5f..3566ee2c65e 100644
--- a/cross/ndk-build/ndk-build-static-library.mk
+++ b/cross/ndk-build/ndk-build-static-library.mk
@@ -34,7 +34,7 @@ else
34ifeq (x$(suffix $(1)),x.$(or $(LOCAL_CPP_EXTENSION),cpp)) 34ifeq (x$(suffix $(1)),x.$(or $(LOCAL_CPP_EXTENSION),cpp))
35 35
36$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2)) 36$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2))
37 $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_BUILD_CFLAGS_CXX) $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) 37 $(NDK_BUILD_CXX) -c $$< -o $$@ $(NDK_BUILD_CFLAGS_CXX) $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE))
38 38
39else 39else
40ifneq ($(or $(call eq,x$(suffix $(1)),x.s),$(call eq,x$(suffix $(1)),x.S)),) 40ifneq ($(or $(call eq,x$(suffix $(1)),x.s),$(call eq,x$(suffix $(1)),x.S)),)
@@ -47,7 +47,7 @@ ifneq (x$(suffix $(1)),x.asm)
47ifeq (x$(suffix $(1)),x.cc) 47ifeq (x$(suffix $(1)),x.cc)
48 48
49$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2)) 49$(call objname,$(LOCAL_MODULE),$(basename $(1))): $(call maybe-absolute,$(1),$(2))
50 $(NDK_BUILD_CC) -c $$< -o $$@ $(NDK_BUILD_CFLAGS_CXX) $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE)) 50 $(NDK_BUILD_CXX) -c $$< -o $$@ $(NDK_BUILD_CFLAGS_CXX) $(NDK_CFLAGS_$(LOCAL_MODULE)) $(NDK_CXXFLAGS_$(LOCAL_MODULE))
51 51
52else 52else
53$$(error Unsupported suffix: $(suffix $(1))) 53$$(error Unsupported suffix: $(suffix $(1)))
diff --git a/java/INSTALL b/java/INSTALL
index bc5f4a70cd0..b331d09d9ff 100644
--- a/java/INSTALL
+++ b/java/INSTALL
@@ -112,6 +112,24 @@ result, the Emacs package will be approximately 100 megabytes larger
112than a compressed package for a newer version of Android. 112than a compressed package for a newer version of Android.
113 113
114 114
115BUILDING C++ DEPENDENCIES
116
117With a new version of the NDK, dependencies containing C++ code should
118build without any futher configuration. However, older versions
119require that you use the ``make_standalone_toolchain.py'' script in
120the NDK distribution to create a ``standalone toolchain'', and use
121that instead, in order for C++ headers to be found.
122
123See https://developer.android.com/ndk/guides/standalone_toolchain for
124more details; when a ``standalone toolchain'' is specified, the
125configure script will try to determine the location of the C++
126compiler based on the C compiler specified. If that automatic
127detection does not work, you can specify a C++ compiler yourself, like
128so:
129
130 ./configure --with-ndk-cxx=/path/to/toolchain/bin/i686-linux-android-g++
131
132
115DEBUG AND RELEASE BUILDS 133DEBUG AND RELEASE BUILDS
116 134
117Android makes a distinction between ``debug'' and ``release'' builds 135Android makes a distinction between ``debug'' and ``release'' builds
diff --git a/m4/ndk-build.m4 b/m4/ndk-build.m4
index d635b8d1a6b..0ade91da230 100644
--- a/m4/ndk-build.m4
+++ b/m4/ndk-build.m4
@@ -25,6 +25,10 @@ AC_ARG_WITH([ndk_cxx_shared],
25 [AS_HELP_STRING([--with-ndk-cxx-shared], 25 [AS_HELP_STRING([--with-ndk-cxx-shared],
26 [name of the C++ standard library included with the NDK])]) 26 [name of the C++ standard library included with the NDK])])
27 27
28AC_ARG_WITH([ndk_cxx],
29 [AS_HELP_STRING([--with-ndk-cxx],
30 [name of the C++ compiler included with the NDK])])
31
28# ndk_INIT(ABI, API, DIR, CFLAGS) 32# ndk_INIT(ABI, API, DIR, CFLAGS)
29# ------------------------------- 33# -------------------------------
30# Initialize the Android NDK. ABI is the ABI being built for. 34# Initialize the Android NDK. ABI is the ABI being built for.
@@ -54,6 +58,7 @@ ndk_API=$2
54ndk_DIR=$3 58ndk_DIR=$3
55ndk_ANY_CXX= 59ndk_ANY_CXX=
56ndk_BUILD_CFLAGS="$4" 60ndk_BUILD_CFLAGS="$4"
61ndk_working_cxx=no
57 62
58AS_CASE(["$ndk_ABI"], 63AS_CASE(["$ndk_ABI"],
59 [*arm64*], [ndk_ARCH=arm64], 64 [*arm64*], [ndk_ARCH=arm64],
@@ -169,6 +174,10 @@ that could not be found in the list of directories specified in \
169 [AC_MSG_ERROR([The module [$]1 requires the C++ standard library \ 174 [AC_MSG_ERROR([The module [$]1 requires the C++ standard library \
170(libc++_shared.so), but it was not found.])]) 175(libc++_shared.so), but it was not found.])])
171 176
177 AS_IF([test "$ndk_ANY_CXX" = "yes" && test "$ndk_working_cxx" != "yes"],
178 [AC_MSG_ERROR([The module [$]1 requires the C++ standard library \
179(libc++_shared.so), but a working C++ compiler was not found.])])
180
172 AC_MSG_RESULT([yes]) 181 AC_MSG_RESULT([yes])
173 182
174 # Make sure the module is prepended. 183 # Make sure the module is prepended.
@@ -181,6 +190,44 @@ that could not be found in the list of directories specified in \
181 done 190 done
182} 191}
183 192
193# ndk_filter_cc_for_cxx
194# ---------------------
195# Run through $CC, removing any options that are not suitable for
196# use in a C++ compiler.
197
198ndk_filter_cc_for_cxx () {
199 for ndk_word in $CC; do
200 AS_CASE([$ndk_word], [*-std=*], [],
201 [AS_ECHO_N(["$ndk_word "])])
202 done
203}
204
205# ndk_subst_cc_onto_cxx
206# ---------------------
207# Print the value of $CXX, followed by any innocent looking options
208# in $CC.
209
210ndk_subst_cc_onto_cxx () {
211 AS_ECHO_N(["$CXX "])
212 ndk_flag=
213 for ndk_word in `AS_ECHO_N(["$CC"]) | cut -s -f2- -d' '`; do
214 AS_IF([test "$ndk_flag" = "yes"],
215 [AS_ECHO_N(["$ndk_word "])],
216 [AS_CASE([$ndk_word],
217 [*-sysroot=*],
218 [AS_ECHO_N(["$ndk_word "])],
219 [*-isystem*],
220 [AS_ECHO_N(["$ndk_word "])
221 ndk_flag=yes],
222 [*-sysroot*],
223 [AS_ECHO_N(["$ndk_word "])
224 ndk_flag=yes],
225 [-D__ANDROID_API__*],
226 [AS_ECHO_N(["$ndk_word "])])])
227 ndk_flag=no
228 done
229}
230
184# Look for a suitable ar in the same directory as the C compiler. 231# Look for a suitable ar in the same directory as the C compiler.
185ndk_cc_firstword=`AS_ECHO(["$CC"]) | cut -d' ' -f1` 232ndk_cc_firstword=`AS_ECHO(["$CC"]) | cut -d' ' -f1`
186ndk_where_cc=`which $ndk_cc_firstword` 233ndk_where_cc=`which $ndk_cc_firstword`
@@ -209,7 +256,7 @@ ndk_where_toolchain=
209AS_IF([test -z "$with_ndk_cxx_shared" && test -n "$ndk_where_cc"],[ 256AS_IF([test -z "$with_ndk_cxx_shared" && test -n "$ndk_where_cc"],[
210 # Find the NDK root directory. Go to $ndk_where_cc. 257 # Find the NDK root directory. Go to $ndk_where_cc.
211 SAVE_PWD=`pwd` 258 SAVE_PWD=`pwd`
212 cd `dirname "$ndk_where_cc"` 259 cd `AS_DIRNAME(["$ndk_where_cc"])`
213 260
214 # Now, keep moving backwards until pwd ends with ``toolchains''. 261 # Now, keep moving backwards until pwd ends with ``toolchains''.
215 while :; do 262 while :; do
@@ -264,7 +311,37 @@ name of an appropriate ``libc++_shared.so'' binary.])],
264 311
265ndk_CXX_SHARED=$with_ndk_cxx_shared 312ndk_CXX_SHARED=$with_ndk_cxx_shared
266 313
267# These variables have now been found. 314# These variables have now been found. Now look for a C++ compiler.
315# Upon failure, pretend the C compiler is a C++ compiler and use that
316# instead.
317
318ndk_cc_name=`AS_BASENAME(["${ndk_cc_firstword}"])`
319ndk_cxx_name=
320
321AS_CASE([$ndk_cc_name], [*-gcc],
322 [ndk_cxx_name=`AS_ECHO([$ndk_cc_name]) | sed 's/gcc/g++/'`],
323 [ndk_cxx_name="${ndk_cc_name}++"])
324
325AS_IF([test -n "$with_ndk_cxx"], [CXX=$with_ndk_cxx],
326 [AC_PATH_PROGS([CXX], [$ndk_cxx_name],
327 [], [`AS_DIRNAME(["$ndk_where_cc"])`:$PATH])
328 AS_IF([test -z "$CXX"], [CXX=`ndk_filter_cc_for_cxx`],
329 [CXX=`ndk_subst_cc_onto_cxx`])])
330])
331
332# ndk_LATE
333# --------
334# Perform late initialization of the ndk-build system by checking for
335# required C and C++ headers.
336
337AC_DEFUN([ndk_LATE],
338[
339AS_IF([test "$ndk_INITIALIZED" = "yes"],[
340 AS_IF([test -n "$CXX"], [AC_LANG_PUSH([C++])
341 AC_CHECK_HEADER([string], [ndk_working_cxx=yes],
342 [AC_MSG_WARN([Your C++ compiler is not properly set up, and\
343 the standard library headers could not be found.])])
344 AC_LANG_POP([C++])])])
268]) 345])
269 346
270# ndk_SEARCH_MODULE(MODULE, NAME, ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND]) 347# ndk_SEARCH_MODULE(MODULE, NAME, ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND])
@@ -303,10 +380,13 @@ else
303 ndk_ANY_CXX=yes 380 ndk_ANY_CXX=yes
304 fi 381 fi
305 382
306 if test "$ndk_ANY_CXX" = "yes" && test -z "$with_ndk_cxx_shared"; then 383 AS_IF([test "$ndk_ANY_CXX" = "yes" && test -z "$with_ndk_cxx_shared"],
307 AC_MSG_ERROR([The module $1 requires the C++ standard library \ 384 [AC_MSG_ERROR([The module $1 requires the C++ standard library \
308(libc++_shared.so), but it was not found.]) 385(libc++_shared.so), but it was not found.])])
309 fi 386
387 AS_IF([test "$ndk_ANY_CXX" = "yes" && test "$ndk_working_cxx" != "yes"],
388 [AC_MSG_ERROR([The module [$]1 requires the C++ standard library \
389(libc++_shared.so), but a working C++ compiler was not found.])])
310 390
311 $2[]_CFLAGS="[$]$2[]_CFLAGS $module_cflags $module_includes" 391 $2[]_CFLAGS="[$]$2[]_CFLAGS $module_cflags $module_includes"
312 $2[]_LIBS="[$]$2[]_LIBS $module_ldflags" 392 $2[]_LIBS="[$]$2[]_LIBS $module_ldflags"
@@ -357,6 +437,7 @@ AC_DEFUN_ONCE([ndk_CONFIG_FILES],
357 NDK_BUILD_ABI=$ndk_ABI 437 NDK_BUILD_ABI=$ndk_ABI
358 NDK_BUILD_SDK=$ndk_API 438 NDK_BUILD_SDK=$ndk_API
359 NDK_BUILD_CC=$CC 439 NDK_BUILD_CC=$CC
440 NDK_BUILD_CXX=$CXX
360 NDK_BUILD_AR=$AR 441 NDK_BUILD_AR=$AR
361 NDK_BUILD_MODULES="$ndk_MODULES" 442 NDK_BUILD_MODULES="$ndk_MODULES"
362 NDK_BUILD_CXX_SHARED="$ndk_CXX_SHARED" 443 NDK_BUILD_CXX_SHARED="$ndk_CXX_SHARED"
@@ -368,6 +449,7 @@ AC_DEFUN_ONCE([ndk_CONFIG_FILES],
368 AC_SUBST([NDK_BUILD_ABI]) 449 AC_SUBST([NDK_BUILD_ABI])
369 AC_SUBST([NDK_BUILD_SDK]) 450 AC_SUBST([NDK_BUILD_SDK])
370 AC_SUBST([NDK_BUILD_CC]) 451 AC_SUBST([NDK_BUILD_CC])
452 AC_SUBST([NDK_BUILD_CXX])
371 AC_SUBST([NDK_BUILD_AR]) 453 AC_SUBST([NDK_BUILD_AR])
372 AC_SUBST([NDK_BUILD_NASM]) 454 AC_SUBST([NDK_BUILD_NASM])
373 AC_SUBST([NDK_BUILD_MODULES]) 455 AC_SUBST([NDK_BUILD_MODULES])