+++ /dev/null
-Installation instructions for Android
-Copyright (C) 2023 Free Software Foundation, Inc.
-See the end of the file for license conditions.
-
-Please read the entirety of this file before attempting to build Emacs
-as an application package which can run on Android devices.
-
-When building from the source repository, make sure to read
-INSTALL.REPO as well.
-
-\f
-
-Android is an unusual operating system in that program binaries cannot
-be produced on computers running Android themselves. Instead, they
-must be built on some other computer using a set of tools known as the
-``Android SDK'' (Software Development Kit) and the ``Android NDK''
-(Native Development Kit.) Appropriate versions of both must be
-obtained to build GNU Emacs; after being built, the generated binaries
-will work on almost all Android devices. This document does not
-elaborate on how both sets of tools can be obtained. However, for
-your freedom's sake, you should use the Android SDK provided by the
-Debian project.
-
-In addition to the Android SDK and Android NDK, Emacs also requires
-the Java compiler from OpenJDK 1.7.0 to be installed on your system.
-Building on GNU systems is all that is officially supported. We are
-told that Mac OS works too, and other Unix systems will likely work
-as well, but MS Windows and Cygwin will not.
-
-Once all of those tools are obtained, you may invoke the `configure'
-script like so:
-
- ./configure --with-android=/path/to/android.jar \
- ANDROID_CC=/path/to/android/ndk/cc \
- SDK_BUILD_TOOLS=/path/to/sdk/build/tools
-
-Replacing the paths in the command line above with:
-
- - the path to the `android.jar' headers which come with the Android
- SDK. They must correspond to Android version 13 (API level 33) or
- later.
-
- - the path to the C compiler in the Android NDK, for the kind of CPU
- you are building Emacs to run on.
-
- - the path to the directory in the Android SDK containing binaries
- such as `aapt', `apksigner', and `d8'. These are used to build
- the application package.
-
-Where the type of CPU can either be `armeabi', `armv7*', `i686',
-`x86_64', `mips', or `mips64'.
-
-After the configuration process completes, you may run:
-
- make all
-
-Once `make' finishes, there should be a file in the `java' directory
-named along the lines of:
-
- emacs-<version>-<api-version>-<abi>.apk
-
-where <api-version> is the oldest version of Android that the package
-will run on, and <abi> is the type of Android machine the package was
-built for.
-
-The generated package can be uploaded onto an SD card (or similar
-medium) and installed on-device.
-
-BUILDING WITH OLD NDK VERSIONS
-
-Building Emacs with an old version of the Android NDK requires special
-setup. This is because there is no separate C compiler binary for
-each version of Android in those versions of the NDK.
-
-Before running `configure', you must identify three variables:
-
- - What kind of Android system you are building Emacs for.
-
- - The minimum API version of Android you want to build Emacs for.
-
- - The locations of the system root and include files for that
- version of Android in the NDK.
-
-That information must then be specified as arguments to the NDK C
-compiler. For example:
-
- ./configure [...] \
- ANDROID_CC="i686-linux-android-gcc \
- --sysroot=/path/to/ndk/platforms/android-14/arch-x86/"
- ANDROID_CFLAGS="-isystem /path/to/ndk/sysroot/usr/include \
- -isystem /path/to/ndk/sysroot/usr/include/i686-linux-android \
- -D__ANDROID_API__=14"
-
-Where __ANDROID_API__ and the version identifier in
-"platforms/android-14" defines the version of Android you are building
-for, and the include directories specify the paths to the relevant
-Android headers. In addition, it may be necessary to specify
-"-gdwarf-2", due to a bug in the Android NDK.
-
-Even older versions of the Android SDK do not require the extra
-`-isystem' directives.
-
-Emacs is known to run on Android 2.2 (API version 8) or later, with
-the NDK r10b or later. We wanted to make Emacs work on even older
-versions of Android, but they are missing the required JNI graphics
-library that allows Emacs to display text from C code.
-
-Due to an extremely nasty bug in the Android 2.2 system, the generated
-Emacs package cannot be compressed in builds for Android 2.2. As a
-result, the Emacs package will be approximately 100 megabytes larger
-than a compressed package for a newer version of Android.
-
-DEBUG AND RELEASE BUILDS
-
-Android makes a distinction between ``debug'' and ``release'' builds
-of applications. With ``release'' builds, the system will apply
-stronger optimizations to the application at the cost of being unable
-to debug them with the steps in etc/DEBUG.
-
-Emacs is built as a debuggable package by default, but:
-
- ./configure --without-android-debug
-
-will create a release build of Emacs instead. This may be useful when
-running Emacs on resource constrained machines.
-
-If you are building an Emacs package for redistribution, we urge you
-to provide both debug and release versions.
-
-BUILDING WITH THIRD PARTY LIBRARIES
-
-The Android NDK does not support the usual ways of locating third
-party libraries, especially not via `pkg-config'. Instead, it uses
-its own system called `ndk-build'. The one exception to this rule is
-zlib, which is considered a part of the Android OS itself and is
-available on all devices running Android.
-
-Android also requires that each application include its own
-dependencies, as the system makes no guarantee about the existence of
-any particular library.
-
-Emacs is not built with the `ndk-build' system. Instead, it is built
-with Autoconf and Make.
-
-However, it supports building and including dependencies which use the
-similarly Make-based `ndk-build' system.
-
-To use dependencies built through `ndk-build', you must specify a list
-of directories within which Emacs will search for ``Android.mk''
-files, like so:
-
- ./configure "--with-ndk-path=directory1 directory2"
-
-If `configure' complains about not being able to find
-``libc++_shared.so'', then you must locate that file in your copy of
-the NDK, and specify it like so:
-
- ./configure --with-ndk-cxx-shared=/path/to/sysroot/libc++_shared.so
-
-Emacs will then read the ``Android.mk'' file in each directory, and
-automatically build and use those modules.
-
-When building for Intel systems, some ``ndk-build'' modules require
-the Netwide Assembler, usually installed under ``nasm'', to be present
-on the system that is building Emacs.
-
-Google, Inc. has adapted many common Emacs dependencies to use the
-`ndk-build' system. Here is a non-exhaustive list of what is known to
-work, along with what has to be patched to make them work:
-
- libpng - https://android.googlesource.com/platform/external/libpng
- libwebp - https://android.googlesource.com/platform/external/webp
- (You must apply the patch at the end of this file for the resulting
- binary to work on armv7 devices.)
- giflib - https://android.googlesource.com/platform/external/giflib
- (You must add LOCAL_EXPORT_CFLAGS := -I$(LOCAL_PATH) before
- its Android.mk includes $(BUILD_STATIC_LIBRARY))
- libjpeg-turbo - https://android.googlesource.com/platform/external/libjpeg-turbo
- (You must add LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) before
- its Android.mk includes $(BUILD_SHARED_LIBRARY))
- libxml2 - https://android.googlesource.com/platform/external/libxml2/
- (You must also place the dependency icu4c in ``--with-ndk-path'',
- and apply the patch at the end of this file.)
- icu4c - https://android.googlesource.com/platform/external/icu/
- (You must apply the patch at the end of this file.)
- sqlite3 - https://android.googlesource.com/platform/external/sqlite/
- (You must apply the patch at the end of this file, and add the `dist'
- directory to ``--with-ndk-path''.)
- libselinux - https://android.googlesource.com/platform/external/libselinux
- (You must apply the patches at the end of the file, and obtain
- the following three dependencies.)
- libpackagelistparser
- https://android.googlesource.com/platform/system/core/+/refs/heads/nougat-mr1-dev/libpackagelistparser/
- libpcre - https://android.googlesource.com/platform/external/pcre
- libcrypto - https://android.googlesource.com/platform/external/boringssl
- (You must apply the patch at the end of this file when building for
- ARM systems.)
-
-Many of these dependencies have been migrated over to the
-``Android.bp'' build system now used to build Android itself.
-However, the old ``Android.mk'' Makefiles are still present in older
-branches, and can be easily adapte to newer versions.
-
-In addition, some Emacs dependencies provide `ndk-build' support
-themselves:
-
- libjansson - https://github.com/akheron/jansson
- (You must add LOCAL_EXPORT_INCLUDES := $(LOCAL_C_INCLUDES) before
- its Android.mk includes $(BUILD_SHARED_LIBRARY), then copy
- android/jansson_config.h to android/jansson_private_config.h.)
-
-Emacs developers have ported the following dependencies to ARM Android
-systems:
-
- gnutls, gmp - https://sourceforge.net/projects/android-ports-for-gnu-emacs
- (Please see the section GNUTLS near the end of this file.)
- libtiff - https://sourceforge.net/projects/android-ports-for-gnu-emacs
- (Extract and point ``--with-ndk-path'' to tiff-4.5.0-emacs.tar.gz.)
- tree-sitter - https://sourceforge.net/projects/android-ports-for-gnu-emacs
- (Please see the section TREE-SITTER near the end of this file.)
-
-And other developers have ported the following dependencies to Android
-systems:
-
- ImageMagick, lcms2 - https://github.com/MolotovCherry/Android-ImageMagick7
- (Please see the section IMAGEMAGICK near the end of this file.)
-
-We anticipate that most untested non-trivial ndk-build dependencies
-will need adjustments in Emacs to work, as the Emacs build system
-which emulates ndk-build is in an extremely early state.
-
-NDK BUILD SYSTEM IMPLEMENTATION
-
-Emacs implements ndk-build itself, because the version that comes with
-the Android NDK is not easy to use from another Makefile, and keeps
-accumulating incompatible changes.
-
-The Emacs implementation of ndk-build consists of one m4 file:
-
- m4/ndk-build.m4
-
-four Makefiles in build-aux, run during configure:
-
- build-aux/ndk-build-helper-1.mk
- build-aux/ndk-build-helper-2.mk
- build-aux/ndk-build-helper-3.mk
- build-aux/ndk-build-helper.mk
-
-one awk script in build-awx, run during configure:
-
- build-aux/ndk-module-extract.awk
-
-seven Makefiles in cross/ndk-build,
-
- cross/ndk-build/ndk-build-shared-library.mk
- cross/ndk-build/ndk-build-static-library.mk
- cross/ndk-build/ndk-build-executable.mk
- cross/ndk-build/ndk-clear-vars.mk
- cross/ndk-build/ndk-prebuilt-shared-library.mk
- cross/ndk-build/ndk-prebuilt-static-library.mk
- cross/ndk-build/ndk-resolve.mk
-
-and finally, two more Makefiles in cross/ndk-build, generated by
-configure:
-
- cross/ndk-build/Makefile (generated from cross/ndk-build/Makefile.in)
- cross/ndk-build/ndk-build.mk (generated from cross/ndk-build/ndk-build.mk.in)
-
-m4/ndk-build.m4 is a collection of macros which are used by the
-configure script to set up the ndk-build system, look for modules, add
-the appropriate options to LIBS and CFLAGS, and generate the Makefiles
-necessary to build the rest of Emacs.
-
-Immediately after determining the list of directories in which to look
-for ``Android.mk'' files, the version and type of Android system being
-built for, configure calls:
-
- ndk_INIT([$android_abi], [$ANDROID_SDK], [cross/ndk-build])
-
-This expands to a sequence of shell script that enumerates all of the
-Android.mk files specified in "$with_ndk_path", sets up some shell
-functions used by the rest of the ndk-build code run by the configure
-script, and teaches the ndk-build system that the Makefiles to be
-generated are found in the directory "cross/ndk-build/Makefile".
-
-When configure is cross-compiling for Android, the macro
-EMACS_CHECK_MODULES will expand to the macro ndk_CHECK_MODULES,
-instead of pkg-config.m4's PKG_CHECK_MODULES. Thus, the following
-code:
-
- EMACS_CHECK_MODULES([PNG], [libpng >= 1.0.0])
-
-will actually expand to:
-
- ndk_CHECK_MODULES([PNG], [libpng >= 1.0.0], [HAVE_PNG=yes],
- [HAVE_PNG=no])
-
-which in turn expands to a sequence shell script that first invokes:
-
- make -f build-aux/ndk-build-helper.mk
-
-for each ``Android.mk'' file found by ndk_INIT, with the following
-variables given to Make:
-
- EMACS_SRCDIR=. # the source directory (in which configure is running)
- EMACS_ABI=$ndk_ABI # this is the $android_abi given to ndk_INIT
- ANDROID_MAKEFILE="/opt/android/libpng/Android.mk"
- ANDROID_MODULE_DIRECTORY="/opt/android/libpng"
- NDK_BUILD_DIR="$ndk_DIR" # this is the directory given as to ndk_INIT
-
-build-aux/ndk-build-helper.mk will then evaluate the contents
-$(ANDROID_MAKEFILE), the ``Android.mk'' file, for the first time. The
-purpose of this evaluation is to establish a list of packages (or
-modules) provided by the ``Android.mk'' file, and the corresponding
-Makefile targets and compiler and linker flags required to build and
-link to those tagets.
-
-Before doing so, build-aux/ndk-build-helper.mk will define several
-variables and functions required by all ``Android.mk'' files. The
-most important of these are:
-
- my-dir # the directory containing the Android.mk file.
- BUILD_SHARED_LIBRARY # build-aux/ndk-build-helper-1.mk
- BUILD_STATIC_LIBRARY # build-aux/ndk-build-helper-2.mk
- BUILD_EXECUTABLE # build-aux/ndk-build-helper-3.mk
- CLEAR_VARS # build-aux/ndk-build-helper-4.mk
-
-Then, ``Android.mk'' will include $(CLEAN_VARS), possibly other
-``Android.mk'' files, (to clear variables previously set), set several
-variables describing each module to the ndk-build system, and include
-one of $(BUILD_SHARED_LIBRARY), $(BUILD_STATIC_LIBRARY) and
-$(BUILD_EXECUTABLE).
-
-Each one of those three scripts will then read from the variables set
-by ``Android.mk'', resolve dependencies, and print out some text
-describing the module to Emacs. For example, the shared library
-module "libpng" results in the following text being printed:
-
-Building shared
-libpng
-/opt/android/libpng/png.c /opt/android/libpng/pngerror.c /opt/android/libpng/pngget.c /opt/android/libpng/pngmem.c /opt/android/libpng/pngpread.c /opt/android/libpng/pngread.c /opt/android/libpng/pngrio.c /opt/android/libpng/pngrtran.c /opt/android/libpng/pngrutil.c /opt/android/libpng/pngset.c /opt/android/libpng/pngtrans.c /opt/android/libpng/pngwio.c /opt/android/libpng/pngwrite.c /opt/android/libpng/pngwtran.c /opt/android/libpng/pngwutil.c
--I/opt/android/libpng
-
- -L/opt/emacs/cross/ndk-build -l:libpng_emacs.so
-libpng_emacs.so
-End
-
-The output is arranged as follows:
-
- - The first line consists of the word ``Building'', followed by
- either ``shared'', ``static'', or ``executable'', depending on
- what type of module being built.
-
- - The second line consists of the name of the module currently being
- built.
-
- - The third line consists of all of the source code files comprising
- the module.
-
- - The fourth line consists of the text that has to be added to
- CFLAGS in order to find the includes associated with the module.
-
- - The fifth line consists of the text that has to be added to LIBS
- in order to link with this module and all of its dependencies.
-
- - The sixth line consists of the Make targets (more on this later)
- that will build the final shared object or library archive of this
- module, along with all of its dependencies.
-
- - The seventh line is either empty, or the name of a dependency on
- the C++ standard library. This is used to determine whether or
- not Emacs will include the C++ standard library in the application
- package.
-
-The output from Make is given to an awk script,
-build-aux/ndk-module-extract.awk. This is responsible for parsing the
-that output and filtering out modules other than what is being built:
-
- awk -f build-aux/ndk-module-extract.awk MODULE=libpng
-
-eventually generating this section of shell script:
-
-module_name=libpng
-module_kind=shared
-module_src="/opt/android/libpng/png.c /opt/android/libpng/pngerror.c /opt/android/libpng/pngget.c /opt/android/libpng/pngmem.c /opt/android/libpng/pngpread.c /opt/android/libpng/pngread.c /opt/android/libpng/pngrio.c /opt/android/libpng/pngrtran.c /opt/android/libpng/pngrutil.c /opt/android/libpng/pngset.c /opt/android/libpng/pngtrans.c /opt/android/libpng/pngwio.c /opt/android/libpng/pngwrite.c /opt/android/libpng/pngwtran.c /opt/android/libpng/pngwutil.c"
-module_includes="-I/opt/android/libpng"
-module_cflags=""
-module_ldflags=" -L/opt/emacs/cross/ndk-build -l:libpng_emacs.so"
-module_target="libpng_emacs.so"
-module_cxx_deps=""
-module_imports=""
-
-which is then evaluated by `configure'. Once the variable
-`module_name' is set, configure apends the remaining
-$(module_includes), $(module_cflags) and $(module_ldflags) to the
-module's CFLAGS and LIBS variables, and appends the list of Makefile
-targets specified to the variable NDK_BUILD_MODULES.
-
-In some cases, an ``Android.mk'' file may chose to import a module
-defined in ``--with-ndk-path'', but not defined inside its own
-``Android.mk'' file. build-aux/ndk-build-helper.mk defines the
-`import-module' function to add the modules being imported to a
-variable, which is then printed out after ``ndk-build-helper.mk''
-completes. For example, libxml2 imports the ``libicucc'' module,
-which results in the following text being printed:
-
-Building shared
-libxml2
-/home/oldosfan/libxml2/SAX.c /home/oldosfan/libxml2/entities.c /home/oldosfan/libxml2/encoding.c /home/oldosfan/libxml2/error.c /home/oldosfan/libxml2/parserInternals.c /home/oldosfan/libxml2/parser.c /home/oldosfan/libxml2/tree.c /home/oldosfan/libxml2/hash.c /home/oldosfan/libxml2/list.c /home/oldosfan/libxml2/xmlIO.c /home/oldosfan/libxml2/xmlmemory.c /home/oldosfan/libxml2/uri.c /home/oldosfan/libxml2/valid.c /home/oldosfan/libxml2/xlink.c /home/oldosfan/libxml2/debugXML.c /home/oldosfan/libxml2/xpath.c /home/oldosfan/libxml2/xpointer.c /home/oldosfan/libxml2/xinclude.c /home/oldosfan/libxml2/DOCBparser.c /home/oldosfan/libxml2/catalog.c /home/oldosfan/libxml2/globals.c /home/oldosfan/libxml2/threads.c /home/oldosfan/libxml2/c14n.c /home/oldosfan/libxml2/xmlstring.c /home/oldosfan/libxml2/buf.c /home/oldosfan/libxml2/xmlregexp.c /home/oldosfan/libxml2/xmlschemas.c /home/oldosfan/libxml2/xmlschemastypes.c /home/oldosfan/libxml2/xmlunicode.c /home/oldosfan/libxml2/xmlreader.c /home/oldosfan/libxml2/relaxng.c /home/oldosfan/libxml2/dict.c /home/oldosfan/libxml2/SAX2.c /home/oldosfan/libxml2/xmlwriter.c /home/oldosfan/libxml2/legacy.c /home/oldosfan/libxml2/chvalid.c /home/oldosfan/libxml2/pattern.c /home/oldosfan/libxml2/xmlsave.c /home/oldosfan/libxml2/xmlmodule.c /home/oldosfan/libxml2/schematron.c /home/oldosfan/libxml2/SAX.c /home/oldosfan/libxml2/entities.c /home/oldosfan/libxml2/encoding.c /home/oldosfan/libxml2/error.c /home/oldosfan/libxml2/parserInternals.c /home/oldosfan/libxml2/parser.c /home/oldosfan/libxml2/tree.c /home/oldosfan/libxml2/hash.c /home/oldosfan/libxml2/list.c /home/oldosfan/libxml2/xmlIO.c /home/oldosfan/libxml2/xmlmemory.c /home/oldosfan/libxml2/uri.c /home/oldosfan/libxml2/valid.c /home/oldosfan/libxml2/xlink.c /home/oldosfan/libxml2/debugXML.c /home/oldosfan/libxml2/xpath.c /home/oldosfan/libxml2/xpointer.c /home/oldosfan/libxml2/xinclude.c /home/oldosfan/libxml2/DOCBparser.c /home/oldosfan/libxml2/catalog.c /home/oldosfan/libxml2/globals.c /home/oldosfan/libxml2/threads.c /home/oldosfan/libxml2/c14n.c /home/oldosfan/libxml2/xmlstring.c /home/oldosfan/libxml2/buf.c /home/oldosfan/libxml2/xmlregexp.c /home/oldosfan/libxml2/xmlschemas.c /home/oldosfan/libxml2/xmlschemastypes.c /home/oldosfan/libxml2/xmlunicode.c /home/oldosfan/libxml2/xmlreader.c /home/oldosfan/libxml2/relaxng.c /home/oldosfan/libxml2/dict.c /home/oldosfan/libxml2/SAX2.c /home/oldosfan/libxml2/xmlwriter.c /home/oldosfan/libxml2/legacy.c /home/oldosfan/libxml2/chvalid.c /home/oldosfan/libxml2/pattern.c /home/oldosfan/libxml2/xmlsave.c /home/oldosfan/libxml2/xmlmodule.c /home/oldosfan/libxml2/schematron.c
-
-
- -L/home/oldosfan/emacs-dev/emacs-android/cross/ndk-build -l:libxml2_emacs.so -l:libicuuc_emacs.so
-libxml2_emacs.so libicuuc_emacs.so
-End
-Start Imports
-libicuuc
-End Imports
-
-Upon encountering the ``Start Imports'' section,
-build-aux/ndk-module-extract.awk collects all imports until it
-encounters the line ``End Imports'', at which point it prints:
-
-module_imports="libicuuc"
-
-Then, if the list of imports is not empty, ndk_CHECK_MODULES
-additionally calls itself for each import before appending the
-module's own ``Android.mk'', ensuring that the module's imported
-dependencies are included by $ndk_DIR/Makefile before itself.
-
-Finally, immediately before generating src/Makefile.android, configure
-expands:
-
- ndk_CONFIG_FILES
-
-to generate $ndk_DIR/Makefile and $ndk_DIR/ndk-build.mk.
-
-Now, the $ndk_DIR directory is set up to build all modules upon which
-depends, and $ndk_DIR/ndk-build.mk includes a list of files required
-to link Emacs, along with the rules to chdir into $ndk_DIR in order to
-build them.
-
-$ndk_DIR/ndk-build.mk is included by cross/src/Makefile
-(Makefile.android) and java/Makefile. It defines three different
-variables:
-
- NDK_BUILD_MODULES the file names of all modules to be built.
- NDK_BUILD_STATIC absolute names of all library archives
- to be built.
- NDK_BUILD_SHARED absolute names of all shared libraries to
- be built.
-
-and then proceeds to define rules to build each of the modules in
-$(NDK_BUILD_MODULES).
-
-cross/src/Makefile arranges to have all dependencies of Emacs not
-already built built before linking ``libemacs.so'' with them.
-
-java/Makefile additionally arranges to have all shared object
-dependencies built before the application package is built, which is
-normally redundant because they should have already been built before
-linking ``libemacs.so''.
-
-Building the modules is performed through $ndk_DIR/Makefile, which
-contains the actual implementation of the ``ndk-build'' build system.
-First, it defines certain variables constant within the ``ndk-build''
-build system, such as the files included by ``Android.mk'' to build
-shared or static libraries, and CLEAR_VARS. The most important of
-these are:
-
- CLEAR_VARS cross/ndk-build/ndk-clear-vars.mk
- BUILD_EXECUTABLE cross/ndk-build/ndk-build-executable.mk
- BUILD_SHARED_LIBRARY cross/ndk-build/ndk-build-shared-library.mk
- BUILD_STATIC_LIBRARY cross/ndk-build/ndk-build-static-library.mk
- PREBUILT_SHARED_LIBRARY cross/ndk-build/ndk-prebuilt-shared-library.mk
- PREBUILT_STATIC_LIBRARY cross/ndk-build/ndk-prebuilt-static-library.mk
-
-Then, it loads each Emacs dependency's ``Android.mk'' file. For each
-module defined there, ``Android.mk'' includes $(CLEAR_VARS) to unset
-all variables specific to each module, and then includes
-$(BUILD_SHARED_LIBRARY) or $(BUILD_STATIC_LIBRARY) for each shared or
-static library module.
-
-This results in cross/ndk-build/ndk-build-shared-library.mk or
-cross/ndk-build/ndk-build-static-library being included, just like the
-Makefiles in build-aux were inside the configure script.
-
-Each one of those two scripts then defines rules to build all of the
-object files associated with the module, and then link or archive
-them. The name under which the module is linked is the same as the
-Make target found on the sixth line of output from
-build-aux/ndk-build-helper.mk.
-
-In doing so, they both include the file ndk-resolve.mk.
-ndk-resolve.mk is expected to recursively add all of the exported
-CFLAGS and includes of any dependencies to the compiler and linker
-command lines for the module being built.
-
-When building a shared library module, ndk-resolve.mk is also expected
-to define the variables NDK_LOCAL_A_NAMES_$(LOCAL_MODULE) and
-NDK_WHOLE_A_NAMES_$(LOCAL_MODULE), containing all static library
-dependencies' archive files. They are to be linked in to the
-resulting shared object file.
-
-This is done by including cross/ndk-build/ndk-resolve.mk each time a
-shared or static library module is going to be built. How is this
-done?
-
-First, ndk-resolve.mk saves the LOCAL_PATH, LOCAL_STATIC_LIBRARIES,
-LOCAL_SHARED_LIBRARIES, LOCAL_EXPORT_CFLAGS and
-LOCAL_EXPORT_C_INCLUDES from the module.
-
-Next, ndk-resolve loops through the dependencies the module has
-specified, appending its CFLAGS and includes to the command line for
-the current module.
-
-Then, that process is repeated for each such dependency which has not
-already been resolved, until all dependencies have been resolved.
-
-libpng is a very simple module, providing only a single shared object
-module. This module is named libpng_emacs.so and is eventually built
-and packaged into the library directory of the Emacs application
-package. Now, let us look at a more complex module, libwebp:
-
-\f
-
-When built with libwebp, Emacs depends on a single library,
-libwebpdemux. This library is named ``libwebpdemux'' on Unix systems,
-and that is the name by which it is found with pkg-config.
-
-However, the library's module is only named ``webpdemux'' on Android.
-When ndk_CHECK_MODULES begins to look for a module, it first tries to
-see if its name is found in the variable `ndk_package_map', which was
-set inside ndk_INIT. In this case, it finds the following word:
-
- libwebpdemux:webpdemux
-
-and immediately replaces ``libwebpdemux'' with ``webpdemux''.
-
-Then, it locates the ``Android.mk'' file containing a static library
-module named webpdemux and gives the output from
-build-aux/ndk-build-helper.mk to the awk script, resulting in:
-
-module_name=webpdemux
-module_kind=static
-module_src="/opt/android/webp/src/demux/anim_decode.c /opt/android/webp/src/demux/demux.c"
-module_includes="-I/opt/android/webp/src"
-module_cflags=""
-module_ldflags=" cross/ndk-build/libwebpdemux.a cross/ndk-build/libwebp.a cross/ndk-build/libwebpdecoder_static.a "
-module_target="libwebpdemux.a libwebp.a libwebpdecoder_static.a"
-
-The attentive reader will notice that in addition to the
-``libwebpdemux.a'' archive associated with the ``webpdemux'' library,
-Emacs has been made to link with two additional libraries. This is
-because the ``webpdemux'' module specifies a dependency on the
-``webp'' module (defined in the same Android.mk).
-build-aux/ndk-build-helper.mk resolved that dependency, noticing that
-it in turn specified another dependency on ``webpdecoder_static'',
-which in turn was added to the linker command line and list of targets
-to build.
-
-As a result, all three dependencies will be built and linked to Emacs,
-instead of just the single ``webpdemux'' dependency that was
-specified.
-
-GNUTLS
-
-Modified copies of GnuTLS and its dependencies (such as libgmp,
-libtasn1, p11-kit) which can be built with the ndk-build system can be
-found at https://sourceforge.net/projects/android-ports-for-gnu-emacs.
-
-They have only been tested on arm64 Android systems running Android
-5.0 or later, and armv7l systems running Android 13 or later, so your
-mileage may vary, especially if you are trying to build Emacs for
-another kind of machine.
-
-To build Emacs with GnuTLS, you must unpack each of the following tar
-archives in that site:
-
- gmp-6.2.1-emacs.tgz
- gnutls-3.7.8-emacs.tar.gz
- libtasn1-4.19.0-emacs.tar.gz
- p11-kit-0.24.1-emacs.tar.gz
- nettle-3.8-emacs.tar.gz
-
-and add the resulting folders to ``--with-ndk-path''. Note that you
-should not try to build these packages separately using any
-`configure' script or Makefiles inside.
-
-TREE-SITTER
-
-A copy of tree-sitter modified to build with the ndk-build system can
-also find that URL. To build Emacs with tree-sitter, you must unpack
-the following tar archive in that site:
-
- tree-sitter-0.20.7-emacs.tar.gz
-
-and add the resulting folder to ``--with-ndk-build''.
-
-IMAGEMAGICK
-
-There is a third party port of ImageMagick to Android. Unfortunately,
-the port also uses its own patched versions of libpng, libjpeg,
-libtiff and libwebp, which conflict with those used by Emacs. Its
-Makefiles were also written for MS Windows, so you must also apply the
-patch at the end of this file.
-
-\f
-
-This file is part of GNU Emacs.
-
-GNU Emacs is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-GNU Emacs is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-\f
-
-PATCH FOR LIBXML2
-
-This patch must be applied to the Android.mk in Google's version of
-libxml2 before it can be built for Emacs. In addition, you must also
-revert the commit `edb5870767fed8712a9b77ef34097209b61ab2db'.
-
-diff --git a/Android.mk b/Android.mk
-index 07c7b372..24f67e49 100644
---- a/Android.mk
-+++ b/Android.mk
-@@ -80,6 +80,7 @@ LOCAL_SHARED_LIBRARIES := libicuuc
- LOCAL_MODULE:= libxml2
- LOCAL_CLANG := true
- LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-+LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)
- include $(BUILD_SHARED_LIBRARY)
-
- # For the host
-@@ -94,3 +95,5 @@ LOCAL_MODULE := libxml2
- LOCAL_CLANG := true
- LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
- include $(BUILD_HOST_STATIC_LIBRARY)
-+
-+$(call import-module,libicuuc)
-
-PATCH FOR ICU
-
-This patch must be applied to icu4j/Android.mk in Google's version of
-icu before it can be built for Emacs.
-
-diff --git a/icu4j/Android.mk b/icu4j/Android.mk
-index d1ab3d5..69eff81 100644
---- a/icu4j/Android.mk
-+++ b/icu4j/Android.mk
-@@ -69,7 +69,7 @@ include $(BUILD_STATIC_JAVA_LIBRARY)
- # Path to the ICU4C data files in the Android device file system:
- icu4c_data := /system/usr/icu
- icu4j_config_root := $(LOCAL_PATH)/main/classes/core/src
--include external/icu/icu4j/adjust_icudt_path.mk
-+include $(LOCAL_PATH)/adjust_icudt_path.mk
-
- include $(CLEAR_VARS)
- LOCAL_SRC_FILES := $(icu4j_src_files)
-
-diff --git a/icu4c/source/common/Android.mk b/icu4c/source/common/Android.mk
-index 8e5f757..44bb130 100644
---- a/icu4c/source/common/Android.mk
-+++ b/icu4c/source/common/Android.mk
-@@ -231,7 +231,7 @@ include $(CLEAR_VARS)
- LOCAL_SRC_FILES += $(src_files)
- LOCAL_C_INCLUDES += $(c_includes) $(optional_android_logging_includes)
- LOCAL_CFLAGS += $(local_cflags) -DPIC -fPIC
--LOCAL_SHARED_LIBRARIES += libdl $(optional_android_logging_libraries)
-+LOCAL_SHARED_LIBRARIES += libdl libstdc++ $(optional_android_logging_libraries)
- LOCAL_MODULE_TAGS := optional
- LOCAL_MODULE := libicuuc
- LOCAL_RTTI_FLAG := -frtti
-
-PATCH FOR SQLITE3
-
-diff --git a/dist/Android.mk b/dist/Android.mk
-index bf277d2..36734d9 100644
---- a/dist/Android.mk
-+++ b/dist/Android.mk
-@@ -141,6 +141,7 @@ include $(BUILD_HOST_EXECUTABLE)
- include $(CLEAR_VARS)
- LOCAL_SRC_FILES := $(common_src_files)
- LOCAL_CFLAGS += $(minimal_sqlite_flags)
-+LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)
- LOCAL_MODULE:= libsqlite_static_minimal
- LOCAL_SDK_VERSION := 23
- include $(BUILD_STATIC_LIBRARY)
-
-diff --git a/dist/sqlite3.c b/dist/sqlite3.c
-index b0536a4..8fa1ee9 100644
---- a/dist/sqlite3.c
-+++ b/dist/sqlite3.c
-@@ -26474,7 +26474,7 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
- */
- #if !defined(HAVE_POSIX_FALLOCATE) \
- && (_XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L)
--# define HAVE_POSIX_FALLOCATE 1
-+/* # define HAVE_POSIX_FALLOCATE 1 */
- #endif
-
- /*
-
-PATCH FOR WEBP
-
-diff --git a/Android.mk b/Android.mk
-index c7bcb0f5..d4da1704 100644
---- a/Android.mk
-+++ b/Android.mk
-@@ -28,9 +28,10 @@ ifneq ($(findstring armeabi-v7a, $(TARGET_ARCH_ABI)),)
- # Setting LOCAL_ARM_NEON will enable -mfpu=neon which may cause illegal
- # instructions to be generated for armv7a code. Instead target the neon code
- # specifically.
-- NEON := c.neon
-- USE_CPUFEATURES := yes
-- WEBP_CFLAGS += -DHAVE_CPU_FEATURES_H
-+ # NEON := c.neon
-+ # USE_CPUFEATURES := yes
-+ # WEBP_CFLAGS += -DHAVE_CPU_FEATURES_H
-+ NEON := c
- else
- NEON := c
- endif
-
-PATCHES FOR SELINUX
-
-diff --git a/Android.mk b/Android.mk
-index 659232e..1e64fd6 100644
---- a/Android.mk
-+++ b/Android.mk
-@@ -116,3 +116,7 @@ LOCAL_STATIC_LIBRARIES := libselinux
- LOCAL_WHOLE_STATIC_LIBRARIES := libpcre
- LOCAL_C_INCLUDES := external/pcre
- include $(BUILD_HOST_EXECUTABLE)
-+
-+$(call import-module,libpcre)
-+$(call import-module,libpackagelistparser)
-+$(call import-module,libcrypto)
-
-diff --git a/src/android.c b/src/android.c
-index 5206a9f..b351ffc 100644
---- a/src/android.c
-+++ b/src/android.c
-@@ -21,8 +21,7 @@
- #include <selinux/label.h>
- #include <selinux/avc.h>
- #include <openssl/sha.h>
--#include <private/android_filesystem_config.h>
--#include <log/log.h>
-+#include <android/log.h>
- #include "policy.h"
- #include "callbacks.h"
- #include "selinux_internal.h"
-@@ -686,6 +685,7 @@ static int seapp_context_lookup(enum seapp_kind kind,
- seinfo = parsedseinfo;
- }
-
-+#if 0
- userid = uid / AID_USER;
- isOwner = (userid == 0);
- appid = uid % AID_USER;
-@@ -702,9 +702,13 @@ static int seapp_context_lookup(enum seapp_kind kind,
- username = "_app";
- appid -= AID_APP;
- } else {
-+#endif
- username = "_isolated";
-+ appid = 0;
-+#if 0
- appid -= AID_ISOLATED_START;
- }
-+#endif
-
- if (appid >= CAT_MAPPING_MAX_ID || userid >= CAT_MAPPING_MAX_ID)
- goto err;
-@@ -1662,8 +1666,10 @@ int selinux_log_callback(int type, const char *fmt, ...)
-
- va_start(ap, fmt);
- if (vasprintf(&strp, fmt, ap) != -1) {
-+#if 0
- LOG_PRI(priority, "SELinux", "%s", strp);
- LOG_EVENT_STRING(AUDITD_LOG_TAG, strp);
-+#endif
- free(strp);
- }
- va_end(ap);
-
-PATCH FOR BORINGSSL
-
-diff --git a/Android.mk b/Android.mk
-index 3e3ef2a..277d4a9 100644
---- a/Android.mk
-+++ b/Android.mk
-@@ -27,7 +27,9 @@ LOCAL_MODULE := libcrypto
- LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/src/include
- LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/crypto-sources.mk
- LOCAL_CFLAGS += -fvisibility=hidden -DBORINGSSL_SHARED_LIBRARY -DBORINGSSL_IMPLEMENTATION -DOPENSSL_SMALL -Wno-unused-parameter
-+LOCAL_CFLAGS_arm = -DOPENSSL_STATIC_ARMCAP -DOPENSSL_NO_ASM
- LOCAL_SDK_VERSION := 9
-+LOCAL_LDFLAGS = --no-undefined
- # sha256-armv4.S does not compile with clang.
- LOCAL_CLANG_ASFLAGS_arm += -no-integrated-as
- LOCAL_CLANG_ASFLAGS_arm64 += -march=armv8-a+crypto
-diff --git a/sources.mk b/sources.mk
-index e82f3d5..be3a3c4 100644
---- a/sources.mk
-+++ b/sources.mk
-@@ -337,20 +337,20 @@ linux_aarch64_sources := \
- linux-aarch64/crypto/sha/sha256-armv8.S\
- linux-aarch64/crypto/sha/sha512-armv8.S\
-
--linux_arm_sources := \
-- linux-arm/crypto/aes/aes-armv4.S\
-- linux-arm/crypto/aes/aesv8-armx32.S\
-- linux-arm/crypto/aes/bsaes-armv7.S\
-- linux-arm/crypto/bn/armv4-mont.S\
-- linux-arm/crypto/modes/ghash-armv4.S\
-- linux-arm/crypto/modes/ghashv8-armx32.S\
-- linux-arm/crypto/sha/sha1-armv4-large.S\
-- linux-arm/crypto/sha/sha256-armv4.S\
-- linux-arm/crypto/sha/sha512-armv4.S\
-- src/crypto/chacha/chacha_vec_arm.S\
-- src/crypto/cpu-arm-asm.S\
-- src/crypto/curve25519/asm/x25519-asm-arm.S\
-- src/crypto/poly1305/poly1305_arm_asm.S\
-+# linux_arm_sources := \
-+# linux-arm/crypto/aes/aes-armv4.S\
-+# linux-arm/crypto/aes/aesv8-armx32.S\
-+# linux-arm/crypto/aes/bsaes-armv7.S\
-+# linux-arm/crypto/bn/armv4-mont.S\
-+# linux-arm/crypto/modes/ghash-armv4.S\
-+# linux-arm/crypto/modes/ghashv8-armx32.S\
-+# linux-arm/crypto/sha/sha1-armv4-large.S\
-+# linux-arm/crypto/sha/sha256-armv4.S\
-+# linux-arm/crypto/sha/sha512-armv4.S\
-+# src/crypto/chacha/chacha_vec_arm.S\
-+# src/crypto/cpu-arm-asm.S\
-+# src/crypto/curve25519/asm/x25519-asm-arm.S\
-+# src/crypto/poly1305/poly1305_arm_asm.S\
-
- linux_x86_sources := \
- linux-x86/crypto/aes/aes-586.S\
-
-PATCH FOR IMAGEMAGICK
-
-diff --git a/Android.mk b/Android.mk
-index 5ab6699..4441417 100644
---- a/Android.mk
-+++ b/Android.mk
-@@ -52,6 +52,20 @@ LZMA_LIB_PATH := $(LOCAL_PATH)/xz-5.2.4
- BZLIB_LIB_PATH := $(LOCAL_PATH)/bzip-1.0.8
- LCMS_LIB_PATH := $(LOCAL_PATH)/liblcms2-2.9
-
-+LIBBZ2_ENABLED := true
-+LIBFFTW_ENABLED := true
-+LIBFREETYPE2_ENABLED := true
-+LIBJPEG_TURBO_ENABLED := true
-+LIBLZMA_ENABLED := true
-+LIBOPENJPEG_ENABLED := true
-+LIBPNG_ENABLED := true
-+LIBTIFF_ENABLED := true
-+LIBWEBP_ENABLED := true
-+LIBXML2_ENABLED := true
-+LIBZLIB_ENABLED := true
-+LIBLCMS2_ENABLED := true
-+BUILD_MAGICKWAND := true
-+
- #-------------------------------------------------------------
- # Include all modules
- #-------------------------------------------------------------
-@@ -68,6 +82,9 @@ include $(MAKE_PATH)/libjpeg-turbo.mk
- # libopenjpeg
- include $(MAKE_PATH)/libopenjpeg.mk
-
-+# libwebp
-+include $(MAKE_PATH)/libwebp.mk
-+
- # libtiff
- include $(MAKE_PATH)/libtiff.mk
-
-@@ -77,9 +94,6 @@ include $(MAKE_PATH)/libpng.mk
- # libfreetype2
- include $(MAKE_PATH)/libfreetype2.mk
-
--# libwebp
--include $(MAKE_PATH)/libwebp.mk
--
- # libfftw
- include $(MAKE_PATH)/libfftw.mk
-
-diff --git a/libjpeg-turbo-2.0.2/jconfig.h b/libjpeg-turbo-2.0.2/jconfig.h
-index 47d14c9..5c6f8ee 100644
---- a/libjpeg-turbo-2.0.2/jconfig.h
-+++ b/libjpeg-turbo-2.0.2/jconfig.h
-@@ -1,57 +1,43 @@
--/* autogenerated jconfig.h based on Android.mk var JCONFIG_FLAGS */
-+/* autogenerated jconfig.h based on Android.mk var JCONFIG_FLAGS */
- #ifndef JPEG_LIB_VERSION
- #define JPEG_LIB_VERSION 62
- #endif
--
- #ifndef LIBJPEG_TURBO_VERSION
- #define LIBJPEG_TURBO_VERSION 2.0.2
- #endif
--
- #ifndef LIBJPEG_TURBO_VERSION_NUMBER
- #define LIBJPEG_TURBO_VERSION_NUMBER 202
- #endif
--
- #ifndef C_ARITH_CODING_SUPPORTED
- #define C_ARITH_CODING_SUPPORTED
- #endif
--
- #ifndef D_ARITH_CODING_SUPPORTED
- #define D_ARITH_CODING_SUPPORTED
- #endif
--
- #ifndef MEM_SRCDST_SUPPORTED
- #define MEM_SRCDST_SUPPORTED
- #endif
--
- #ifndef WITH_SIMD
- #define WITH_SIMD
- #endif
--
- #ifndef BITS_IN_JSAMPLE
- #define BITS_IN_JSAMPLE 8
- #endif
--
- #ifndef HAVE_LOCALE_H
- #define HAVE_LOCALE_H
- #endif
--
- #ifndef HAVE_STDDEF_H
- #define HAVE_STDDEF_H
- #endif
--
- #ifndef HAVE_STDLIB_H
- #define HAVE_STDLIB_H
- #endif
--
- #ifndef NEED_SYS_TYPES_H
- #define NEED_SYS_TYPES_H
- #endif
--
- #ifndef HAVE_UNSIGNED_CHAR
- #define HAVE_UNSIGNED_CHAR
- #endif
--
- #ifndef HAVE_UNSIGNED_SHORT
- #define HAVE_UNSIGNED_SHORT
- #endif
--
-diff --git a/libxml2-2.9.9/encoding.c b/libxml2-2.9.9/encoding.c
-index a3aaf10..60f165b 100644
---- a/libxml2-2.9.9/encoding.c
-+++ b/libxml2-2.9.9/encoding.c
-@@ -2394,7 +2394,6 @@ xmlCharEncOutput(xmlOutputBufferPtr output, int init)
- {
- int ret;
- size_t written;
-- size_t writtentot = 0;
- size_t toconv;
- int c_in;
- int c_out;
-@@ -2451,7 +2450,6 @@ retry:
- xmlBufContent(in), &c_in);
- xmlBufShrink(in, c_in);
- xmlBufAddLen(out, c_out);
-- writtentot += c_out;
- if (ret == -1) {
- if (c_out > 0) {
- /* Can be a limitation of iconv or uconv */
-@@ -2536,7 +2534,6 @@ retry:
- }
-
- xmlBufAddLen(out, c_out);
-- writtentot += c_out;
- goto retry;
- }
- }
-@@ -2567,9 +2564,7 @@ xmlCharEncOutFunc(xmlCharEncodingHandler *handler, xmlBufferPtr out,
- xmlBufferPtr in) {
- int ret;
- int written;
-- int writtentot = 0;
- int toconv;
-- int output = 0;
-
- if (handler == NULL) return(-1);
- if (out == NULL) return(-1);
-@@ -2612,7 +2607,6 @@ retry:
- in->content, &toconv);
- xmlBufferShrink(in, toconv);
- out->use += written;
-- writtentot += written;
- out->content[out->use] = 0;
- if (ret == -1) {
- if (written > 0) {
-@@ -2622,8 +2616,6 @@ retry:
- ret = -3;
- }
-
-- if (ret >= 0) output += ret;
--
- /*
- * Attempt to handle error cases
- */
-@@ -2700,7 +2692,6 @@ retry:
- }
-
- out->use += written;
-- writtentot += written;
- out->content[out->use] = 0;
- goto retry;
- }
-diff --git a/libxml2-2.9.9/xpath.c b/libxml2-2.9.9/xpath.c
-index 5e3bb9f..505ec82 100644
---- a/libxml2-2.9.9/xpath.c
-+++ b/libxml2-2.9.9/xpath.c
-@@ -10547,7 +10547,7 @@ xmlXPathCompFilterExpr(xmlXPathParserContextPtr ctxt) {
-
- static xmlChar *
- xmlXPathScanName(xmlXPathParserContextPtr ctxt) {
-- int len = 0, l;
-+ int l;
- int c;
- const xmlChar *cur;
- xmlChar *ret;
-@@ -10567,7 +10567,6 @@ xmlXPathScanName(xmlXPathParserContextPtr ctxt) {
- (c == '_') || (c == ':') ||
- (IS_COMBINING(c)) ||
- (IS_EXTENDER(c)))) {
-- len += l;
- NEXTL(l);
- c = CUR_CHAR(l);
- }
-diff --git a/make/libicu4c.mk b/make/libicu4c.mk
-index 21ec121..8b77865 100644
---- a/make/libicu4c.mk
-+++ b/make/libicu4c.mk
-@@ -250,7 +250,7 @@ LOCAL_MODULE := libicuuc
- LOCAL_SRC_FILES := $(src_files)
-
- # when built in android, they require uconfig_local (because of android project), but we don't need this
--$(shell > $(ICU_COMMON_PATH)/unicode/uconfig_local.h echo /* Autogenerated stub file to make libicuuc build happy */) \
-+$(shell > $(ICU_COMMON_PATH)/unicode/uconfig_local.h echo /\* Autogenerated stub file to make libicuuc build happy \*/) \
-
- ifeq ($(LIBXML2_ENABLED),true)
- include $(BUILD_STATIC_LIBRARY)
-diff --git a/make/libjpeg-turbo.mk b/make/libjpeg-turbo.mk
-index d39dd41..fdebcf3 100644
---- a/make/libjpeg-turbo.mk
-+++ b/make/libjpeg-turbo.mk
-@@ -230,30 +230,30 @@ JCONFIG_FLAGS += \
- HAVE_UNSIGNED_SHORT
-
- JCONFIGINT_FLAGS += \
-- BUILD="20190814" \
-- PACKAGE_NAME="libjpeg-turbo" \
-- VERSION="2.0.2"
-+ BUILD=\"20190814\" \
-+ PACKAGE_NAME=\"libjpeg-turbo\" \
-+ VERSION=\"2.0.2\"
-
- # originally defined in jconfigint.h, but the substitution has problems with spaces
- LOCAL_CFLAGS := \
- -DINLINE="inline __attribute__((always_inline))"
-
- # create definition file jconfig.h, needed in order to build
--$(shell echo /* autogenerated jconfig.h based on Android.mk var JCONFIG_FLAGS */ > $(JPEG_LIB_PATH)/jconfig.h)
-+$(shell echo \/\* autogenerated jconfig.h based on Android.mk var JCONFIG_FLAGS \*\/ > $(JPEG_LIB_PATH)/jconfig.h)
- $(foreach name,$(JCONFIG_FLAGS), \
- $(if $(findstring =,$(name)), \
-- $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo #ifndef $(firstword $(subst =, ,$(name)))) \
-+ $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo \#ifndef $(firstword $(subst =, ,$(name)))) \
- , \
-- $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo #ifndef $(name)) \
-+ $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo \#ifndef $(name)) \
- ) \
-- $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo #define $(subst =, ,$(name))) \
-- $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo #endif) \
-+ $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo \#define $(subst =, ,$(name))) \
-+ $(shell >>$(JPEG_LIB_PATH)/jconfig.h echo \#endif) \
- $(shell >> $(JPEG_LIB_PATH)/jconfig.h echo.) \
- )
-
- # create definition file jconfigint.h, needed in order to build
--$(shell >$(JPEG_LIB_PATH)/jconfigint.h echo /* autogenerated jconfigint.h based on Android.mk vars JCONFIGINT_FLAGS */)
--$(foreach name,$(JCONFIGINT_FLAGS),$(shell >>$(JPEG_LIB_PATH)/jconfigint.h echo #define $(subst =, ,$(name))))
-+$(shell >$(JPEG_LIB_PATH)/jconfigint.h echo /\* autogenerated jconfigint.h based on Android.mk vars JCONFIGINT_FLAGS \*/)
-+$(foreach name,$(JCONFIGINT_FLAGS),$(shell >>$(JPEG_LIB_PATH)/jconfigint.h echo \#define $(subst =, ,$(name))))
-
- ifeq ($(LIBJPEG_TURBO_ENABLED),true)
- include $(BUILD_STATIC_LIBRARY)
-diff --git a/make/liblcms2.mk b/make/liblcms2.mk
-index e1fd3b9..29ca791 100644
---- a/make/liblcms2.mk
-+++ b/make/liblcms2.mk
-@@ -10,6 +10,10 @@ LOCAL_C_INCLUDES := \
- $(LCMS_LIB_PATH)/include \
- $(LCMS_LIB_PATH)/src
-
-+LOCAL_EXPORT_C_INCLUDES := \
-+ $(LCMS_LIB_PATH) \
-+ $(LCMS_LIB_PATH)/include \
-+ $(LCMS_LIB_PATH)/src
-
- LOCAL_CFLAGS := \
- -DHAVE_FUNC_ATTRIBUTE_VISIBILITY=1 \
-diff --git a/make/libmagick++-7.mk b/make/libmagick++-7.mk
-index 5352ccb..929396d 100644
---- a/make/libmagick++-7.mk
-+++ b/make/libmagick++-7.mk
-@@ -12,7 +12,7 @@ LOCAL_C_INCLUDES := \
-
- ifneq ($(STATIC_BUILD),true)
- LOCAL_LDFLAGS += -fexceptions
-- LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz
-+ LOCAL_LDLIBS := -llog -lz
- endif
-
- LOCAL_SRC_FILES := \
-diff --git a/make/libmagickcore-7.mk b/make/libmagickcore-7.mk
-index 81293b2..d51fced 100644
---- a/make/libmagickcore-7.mk
-+++ b/make/libmagickcore-7.mk
-@@ -25,6 +25,7 @@ else ifeq ($(TARGET_ARCH_ABI),x86_64)
-
- endif
-
-+LOCAL_EXPORT_C_INCLUDES += $(IMAGE_MAGICK)
-
- LOCAL_C_INCLUDES += \
- $(IMAGE_MAGICK) \
-@@ -45,10 +46,9 @@ LOCAL_C_INCLUDES += \
- $(BZLIB_LIB_PATH) \
- $(LCMS_LIB_PATH)/include
-
--
- ifneq ($(STATIC_BUILD),true)
- # ignored in static library builds
-- LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz
-+ LOCAL_LDLIBS := -llog -lz
- endif
-
-
-diff --git a/make/libmagickwand-7.mk b/make/libmagickwand-7.mk
-index 7be2fb6..0bbcca5 100644
---- a/make/libmagickwand-7.mk
-+++ b/make/libmagickwand-7.mk
-@@ -14,7 +14,7 @@ LOCAL_C_INCLUDES := \
-
- # always ignored in static builds
- ifneq ($(STATIC_BUILD),true)
-- LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz
-+ LOCAL_LDLIBS := -llog -lz
- endif
-
- LOCAL_SRC_FILES := \
-@@ -54,6 +54,29 @@ ifeq ($(OPENCL_BUILD),true)
- LOCAL_SHARED_LIBRARIES += libopencl
- endif
-
-+LOCAL_SHARED_LIBRARIES += libstdc++
-+
-+ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
-+ LOCAL_EXPORT_C_INCLUDES += $(IMAGE_MAGICK)/configs/arm64
-+ LOCAL_C_INCLUDES += $(IMAGE_MAGICK)/configs/arm64
-+else ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
-+ LOCAL_EXPORT_C_INCLUDES += $(IMAGE_MAGICK)/configs/arm
-+ LOCAL_C_INCLUDES += $(IMAGE_MAGICK)/configs/arm
-+else ifeq ($(TARGET_ARCH_ABI),x86)
-+ LOCAL_EXPORT_C_INCLUDES += $(IMAGE_MAGICK)/configs/x86
-+ LOCAL_C_INCLUDES += $(IMAGE_MAGICK)/configs/x86
-+else ifeq ($(TARGET_ARCH_ABI),x86_64)
-+ LOCAL_EXPORT_C_INCLUDES += $(IMAGE_MAGICK)/configs/x86-64
-+ LOCAL_C_INCLUDES += $(IMAGE_MAGICK)/configs/x86-64
-+
-+ ifneq ($(STATIC_BUILD),true)
-+ LOCAL_LDFLAGS += -latomic
-+ endif
-+
-+endif
-+
-+LOCAL_EXPORT_C_INCLUDES += $(IMAGE_MAGICK)
-+
- ifeq ($(BUILD_MAGICKWAND),true)
- ifeq ($(STATIC_BUILD),true)
- LOCAL_STATIC_LIBRARIES := \
-diff --git a/make/libpng.mk b/make/libpng.mk
-index 24fb8ac..dda05fd 100644
---- a/make/libpng.mk
-+++ b/make/libpng.mk
-@@ -30,6 +30,7 @@ ifeq ($(TARGET_ARCH_ABI), arm64-v8a)
- endif # TARGET_ARCH_ABI == arm64-v8a
-
-
-+LOCAL_EXPORT_C_INCLUDES := $(PNG_LIB_PATH)
- LOCAL_C_INCLUDES := $(PNG_LIB_PATH)
-
- LOCAL_SRC_FILES += \
-diff --git a/make/libtiff.mk b/make/libtiff.mk
-index ca43f25..2b17508 100644
---- a/make/libtiff.mk
-+++ b/make/libtiff.mk
-@@ -12,6 +12,9 @@ LOCAL_C_INCLUDES := \
- $(LZMA_LIB_PATH)/liblzma/api \
- $(WEBP_LIB_PATH)/src
-
-+LOCAL_EXPORT_C_INCLUDES := \
-+ $(TIFF_LIB_PATH)
-+
- ifeq ($(LIBLZMA_ENABLED),true)
- LOCAL_CFLAGS += -DLZMA_SUPPORT=1
- endif
-diff --git a/make/magick.mk b/make/magick.mk
-index 3ba4b1d..5471608 100644
---- a/make/magick.mk
-+++ b/make/magick.mk
-@@ -18,7 +18,7 @@ LOCAL_C_INCLUDES := \
- $(FREETYPE_LIB_PATH)/include
-
-
--LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz
-+LOCAL_LDLIBS := -llog -lz
- LOCAL_SRC_FILES := \
- $(IMAGE_MAGICK)/utilities/magick.c \
-