--- /dev/null
+### @configure_input@
+
+# Copyright (C) 2023 Free Software Foundation, Inc.
+
+# 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/>.
+
+top_srcdir = @top_srcdir@
+top_builddir = @top_builddir@
+
+# Cross-compiling Emacs for Android.
+
+# The cross compiled binaries are built by having ``variant''
+# Makefiles generated at configure-time. First,
+# $(top_builddir)/src/Makefile.android,
+# $(top_builddir)/lib/Makefile.android,
+# $(top_builddir)/lib/gnulib.mk.android and
+# $(top_builddir)/lib-src/Makefile.android are copied to their usual
+# locations in this directory.
+
+# Finally, the following commands are executed in order, to produce
+# libgnu.a, various binaries in lib-src, and src/aemacs:
+# make -C lib libgnu.a
+# make -C lib-src src/aemacs
+# make -C src aemacs
+
+# This is possibly the ugliest Makefile ever written!
+
+LIB_SRCDIR = $(realpath ./lib)
+LIB_TOP_SRCDIR = $(realpath $(top_srcdir))
+
+SRC_SRCDIR = $(realpath $(top_srcdir)/src)
+SRC_TOP_SRCDIR = $(realpath $(top_srcdir))
+
+LIB_SRC_SRCDIR = $(realpath $(top_srcdir)/lib-src)
+LIB_SRC_TOP_SRCDIR = $(realpath $(top_src))
+
+# This is a list of binaries to build and install in lib-src.
+
+LIBSRC_BINARIES = lib-src/etags lib-src/ctags lib-src/emacsclient \
+ lib-src/ebrowse lib-src/hexl lib-src/movemail
+
+CLEAN_SUBDIRS=src lib-src
+
+.PHONY: all
+all: lib/libgnu.a src/libemacs.so src/android-emacs $(LIBSRC_BINARIES)
+
+# This Makefile relies on builddir and top_builddir being relative
+# paths in *.android.
+
+# This file is used to trick lib/gnulib.mk, it is not actually useful.
+config.status:
+ touch config.status
+
+src/verbose.mk: verbose.mk.android
+ mkdir -p src
+ cp -f verbose.mk.android src/verbose.mk
+
+# Gnulib, make-fingerprint and make-docfile must be built before
+# entering any of the rules below, or they will get the Android
+# versions of many headers.
+
+.PHONY: $(top_builddir)/lib/libgnu.a
+$(top_builddir)/lib/libgnu.a:
+ + make -C $(top_builddir)/lib libgnu.a
+
+.PHONY: $(top_builddir)/lib-src/make-fingerprint
+$(top_builddir)/lib-src/make-fingerprint:
+ make -C $(top_builddir)/lib-src make-fingerprint
+
+.PHONY: $(top_builddir)/lib-src/make-docfile
+$(top_builddir)/lib-src/make-docfile:
+ make -C $(top_builddir)/lib-src make-docfile
+
+PRE_BUILD_DEPS=$(top_builddir)/lib/libgnu.a \
+ $(top_builddir)/lib-src/make-fingerprint \
+ $(top_builddir)/lib-src/make-docfile
+
+lib/config.h: $(top_builddir)/src/config.h.android
+ cp -f -p $(top_builddir)/src/config.h.android lib/config.h
+
+lib/gnulib.mk: $(top_builddir)/lib/gnulib.mk.android
+ cp -f -p $(top_builddir)/lib/gnulib.mk.android lib/gnulib.mk
+ sed -i 's/srcdir =.*$$/srcdir = $(subst /,\/,$(LIB_SRCDIR))/g' \
+ lib/gnulib.mk
+
+lib/Makefile: $(top_builddir)/lib/Makefile.android
+ cp -f -p $(top_builddir)/lib/Makefile.android lib/Makefile
+ sed -i 's/top_srcdir =.*$$/top_srcdir = $(subst /,\/,$(LIB_TOP_SRCDIR))/g' \
+ lib/Makefile
+
+# What is needed to build gnulib.
+LIB_DEPS = lib/config.h lib/gnulib.mk lib/Makefile
+
+.PHONY: lib/libgnu.a
+lib/libgnu.a: src/verbose.mk config.status $(LIB_DEPS) $(PRE_BUILD_DEPS)
+ mkdir -p lib/deps lib/deps/malloc
+ +make -C lib libgnu.a
+
+src/Makefile src/config.h &: $(top_builddir)/src/config.h.android \
+ $(top_builddir)/src/Makefile.android
+ mkdir -p src src/deps
+# Copy config.h to src/
+ cp -f -p $(top_builddir)/src/config.h.android src/config.h
+# And the Makefile.
+ cp -f -p $(top_builddir)/src/Makefile.android src/Makefile
+# Next, edit srcdir and top_srcdir to the right location.
+ sed -i 's/srcdir =.*$$/srcdir = $(subst /,\/,$(SRC_SRCDIR))/g' src/Makefile
+ sed -i 's/top_srcdir =.*$$/top_srcdir = $(subst /,\/,$(LIB_TOP_SRCDIR))/g' \
+ src/Makefile
+# Edit references to ../admin/unidata to read ../../admin/unidata.
+ sed -i 's/\.\.\/admin\/unidata/..\/..\/admin\/unidata/g' src/Makefile
+ sed -i 's/\.\.\/admin\/charsets/..\/..\/admin\/charsets/g' src/Makefile
+# Next, edit libsrc to the location at top_srcdir! It is important
+# that src/Makefile uses the binaries there, instead of any
+# cross-compiled binaries at ./lib-src.
+ sed -i 's/libsrc =.*$$/libsrc = \.\.\/\.\.\/lib-src/g' src/Makefile
+# Edit out anything saying -I($(top_srcdir)/lib); that should be
+# covered by -I$(lib)
+ sed -i 's/-I\$$(top_srcdir)\/lib//g' src/Makefile
+
+.PHONY: src/android-emacs src/libemacs.so
+src/android-emacs src/libemacs.so &: src/Makefile src/config.h \
+ src/verbose.mk lib/libgnu.a $(PRE_BUILD_DEPS)
+ +make -C src android-emacs libemacs.so
+
+lib-src/Makefile: $(top_builddir)/lib-src/Makefile.android
+ mkdir -p lib-src
+ cp -f -p $< $@
+ sed -i 's/-I\$${srcdir}\/\.\.\/lib//g' lib-src/Makefile
+
+.PHONY: $(LIBSRC_BINARIES)
+$(LIBSRC_BINARIES) &: src/verbose.mk $(top_builddir)/$@ lib/libgnu.a \
+ src/config.h lib-src/Makefile $(PRE_BUILD_DEPS)
+ mkdir -p src lib-src
+# Next, edit srcdir and top_srcdir to the right location.
+ sed -i 's/srcdir=.*$$/srcdir = $(subst /,\/,$(LIB_SRC_SRCDIR))/g' \
+ lib-src/Makefile
+ sed -i 's/top_srcdir=.*$$/top_srcdir = $(subst /,\/,$(LIB_SRC_TOP_SRCDIR))/g' \
+ lib-src/Makefile
+# Edit out SCRIPTS, it interferes with the build.
+ sed -i 's/^SCRIPTS=.*$$/SCRIPTS=/g' lib-src/Makefile
+# Finally, go into lib-src and make everything being built
+ +make -C lib-src $(foreach bin,$(LIBSRC_BINARIES),$(notdir $(bin)))
+
+.PHONY: clean maintainer-clean distclean
+clean:
+ rm -rf $(CLEAN_SUBDIRS) *.bak sys
+ if [ -e lib/Makefile ]; then \
+ make -C lib clean; \
+ fi
+ rm -rf lib/config.h
+ make -C ndk-build clean
+
+distclean bootstrap-clean: clean
+ if [ -e lib/Makefile ]; then \
+ make -C lib distclean; \
+ fi
+# Just in case.
+ rm -rf lib/Makefile lib/gnulib.mk ndk-build/Makefile
+ rm -rf ndk-build/ndk-build.mk
+
+maintainer-clean: distclean bootstrap-clean
+ if [ -e lib/Makefile ]; then \
+ make -C lib maintainer-clean; \
+ fi
--- /dev/null
+### verbose.mk --- Makefile fragment for GNU Emacs during
+### cross-compilation.
+
+## Copyright (C) 2023 Free Software Foundation, Inc.
+
+## 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/>.
+
+# 'make' verbosity.
+V = 0
+ifeq (${V},1)
+AM_V_AR =
+AM_V_at =
+AM_V_CC =
+AM_V_CXX =
+AM_V_CCLD =
+AM_V_CXXLD =
+AM_V_ELC =
+AM_V_ELN =
+AM_V_GEN =
+AM_V_GLOBALS =
+AM_V_NO_PD =
+AM_V_RC =
+AM_V_JAVAC =
+AM_V_DX =
+AM_V_AAPT =
+AM_V_ZIPALIGN =
+else
+
+# Whether $(info ...) works. This is to work around a bug in GNU Make
+# 4.3 and earlier, which implements $(info MSG) via two system calls
+# { write (..., "MSG", 3); write (..., "\n", 1); }
+# which looks bad when make -j interleaves two of these at about the same time.
+#
+# Later versions of GNU Make have the 'notintermediate' feature,
+# so assume that $(info ...) works if this feature is present.
+#
+have_working_info = $(filter notintermediate,$(value .FEATURES))
+#
+# The workaround is to use the shell and 'echo' rather than $(info ...).
+# The workaround is done only for AM_V_ELC and AM_V_ELN,
+# since the bug is not annoying elsewhere.
+
+AM_V_AR = @$(info $ AR $@)
+AM_V_at = @
+AM_V_CC = @$(info $ ANDROID_CC $@)
+AM_V_CXX = @$(info $ ANDROID_CXX $@)
+AM_V_CCLD = @$(info $ CCLD $@)
+AM_V_CXXLD = @$(info $ CXXLD $@)
+
+AM_V_GEN = @$(info $ GEN $@)
+AM_V_NO_PD = --no-print-directory
+endif