From 9d3aacedf0c217af207d39e390f376914160396b Mon Sep 17 00:00:00 2001 From: Po Lu Date: Tue, 24 Jan 2023 10:24:13 +0800 Subject: [PATCH] Update android port * xcompile: Move to cross. * cross: New directory. --- cross/Makefile.in | 178 +++++++++++++++++++++++++++++++++++++++ cross/README | 6 ++ cross/langinfo.h | 20 +++++ cross/verbose.mk.android | 65 ++++++++++++++ 4 files changed, 269 insertions(+) create mode 100644 cross/Makefile.in create mode 100644 cross/README create mode 100644 cross/langinfo.h create mode 100644 cross/verbose.mk.android diff --git a/cross/Makefile.in b/cross/Makefile.in new file mode 100644 index 00000000000..2ee8c8110d6 --- /dev/null +++ b/cross/Makefile.in @@ -0,0 +1,178 @@ +### @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 . + +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 diff --git a/cross/README b/cross/README new file mode 100644 index 00000000000..8b00dec97ff --- /dev/null +++ b/cross/README @@ -0,0 +1,6 @@ +This directory holds Makefiles and other required assets to build an +Emacs binary independently for another toolchain. It also holds +another copy of gnulib that may be modified to work on Android. + +The directory ndk-build also contains an implementation of the Android +`ndk-build' build system. diff --git a/cross/langinfo.h b/cross/langinfo.h new file mode 100644 index 00000000000..b296ba8db80 --- /dev/null +++ b/cross/langinfo.h @@ -0,0 +1,20 @@ +/* Replacement langinfo.h file for building GNU Emacs on Android. + +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 . */ + +#define nl_langinfo(ignore) "ASCII" diff --git a/cross/verbose.mk.android b/cross/verbose.mk.android new file mode 100644 index 00000000000..7d07b978de2 --- /dev/null +++ b/cross/verbose.mk.android @@ -0,0 +1,65 @@ +### 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 . + +# '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 -- 2.39.5