emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/android daf9c62871a: Fix out-of-tree Android builds


From: Po Lu
Subject: feature/android daf9c62871a: Fix out-of-tree Android builds
Date: Wed, 1 Mar 2023 06:40:28 -0500 (EST)

branch: feature/android
commit daf9c62871af8539044da15028a078905bb9ba06
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Fix out-of-tree Android builds
    
    * configure.ac (JAVA_PUSH_LINT): Push to WARN_JAVAFLAGS instead
    of JAVAFLAGS.
    (cross/lib): Always AS_MKDIR_P.
    * cross/Makefile.in (srcdir): New variable.
    (LIB_SRCDIR): Take realpath relative to srcdir, not
    .:(src/verbose.mk): Depend on verbose.mk.android in srcdir.
    (lib/Makefile): Edit srcdir and VPATH to LIB_SRCDIR.
    (src/Makefile): Edit -I$$(top_srcdir) to -I../$(srcdir)/lib,
    instead of ommitting it.
    (clean): Allow ndk-build clean to fail.
    
    * java/Makefile.in (builddir): New variable.
    (WARN_JAVAFLAGS): Likewise.
    (JAVAFLAGS): Define in terms of WARN_JAVAFLAGS.
    (SIGN_EMACS, SIGN_EMACS_V2): Use emacs.keystore relative to
    srcdir.  Allow inclusion of ndk-build.mk to fail.
    (install_temp, emacs.apk-in)
    (../config.status): Depend relative to top_srcdir.
    (AndroidManifest.xml, $(APK_NAME)): Likewise.
    (RESOURCE_FILE, CLASS_FILES, classes.dex): Output class files
    to $(srcdir); these are arch independents, so this is okay.
---
 configure.ac      | 20 +++++++++++---------
 cross/Makefile.in | 34 ++++++++++++++++++++++------------
 java/Makefile.in  | 42 ++++++++++++++++++++++++------------------
 3 files changed, 57 insertions(+), 39 deletions(-)

diff --git a/configure.ac b/configure.ac
index 67ee0a1c413..47939f1950a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -742,7 +742,7 @@ AC_SUBST([BUILD_DETAILS])
 # JAVA_PUSH_LINT(OPT)
 # -------------------
 # Check if javac supports the diagnostic flag -Xlint:OPT.
-# If it does, add it to JAVAFLAGS.
+# If it does, add it to WARN_JAVAFLAGS.
 
 AC_DEFUN([JAVA_PUSH_LINT],
 [
@@ -762,7 +762,7 @@ EOF
      [emacs_cv_javac_knows_lint_$1=no]))
 
   AS_IF([test "$emacs_cv_javac_knows_lint_$1" = "yes"],
-    [JAVAFLAGS="$JAVAFLAGS -Xlint:$1"])
+    [WARN_JAVAFLAGS="$WARN_JAVAFLAGS -Xlint:$1"])
 ])
 
 # Start Android configuration.  This is done in three steps:
@@ -786,7 +786,7 @@ ZIPALIGN=
 DX=
 ANDROID_JAR=
 ANDROID_ABI=
-JAVAFLAGS=
+WARN_JAVAFLAGS=
 
 # This is a list of Makefiles that have alternative versions for
 # Android.
@@ -906,10 +906,10 @@ EOF
       [emacs_cv_javac_release_7=no]))
 
   if test "$emacs_cv_javac_release_7" = "yes"; then
-    JAVAFLAGS="$JAVAFLAGS --release 7"
+    WARN_JAVAFLAGS="$WARN_JAVAFLAGS --release 7"
   else
     dnl If not, just make sure the generated bytecode is correct.
-    JAVAFLAGS="$JAVAFLAGS -target 1.7 -source 1.7"
+    WARN_JAVAFLAGS="$WARN_JAVAFLAGS -target 1.7 -source 1.7"
   fi
 
   dnl Enable some useful Java linting options.
@@ -927,10 +927,8 @@ EOF
   # Get the name of the android.jar file.
   ANDROID_JAR="$with_android"
 
-  dnl Set up the class path to include android.jar, along with the cwd
-  dnl (which is $(top_builddir)/java.)
-  JAVAFLAGS="$JAVAFLAGS -classpath \"$ANDROID_JAR:.\""
-  AC_SUBST([JAVAFLAGS])
+  # Substitute this into java/Makefile.
+  AC_SUBST([WARN_JAVAFLAGS])
 
   AC_PATH_PROGS([AAPT], [aapt], [], "${SDK_BUILD_TOOLS}:$PATH")
   if test "$AAPT" = ""; then
@@ -7717,6 +7715,10 @@ if test "$XCONFIGURE" != "android"; then
       AS_MKDIR_P([lib/deps/malloc])
     fi
   fi
+
+  dnl Make cross/lib, which various Makefiles in cross expect to
+  dnl always exist.
+  AS_MKDIR_P([cross/lib])
 fi
 
 # Make java/Makefile
diff --git a/cross/Makefile.in b/cross/Makefile.in
index 217a08f3b52..897e2333400 100644
--- a/cross/Makefile.in
+++ b/cross/Makefile.in
@@ -18,6 +18,7 @@
 # along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
 top_srcdir = @top_srcdir@
+srcdir = @srcdir@
 top_builddir = @top_builddir@
 
 -include $(top_builddir)/src/verbose.mk
@@ -34,7 +35,7 @@ top_builddir = @top_builddir@
 
 # This is possibly the ugliest Makefile ever written!
 
-LIB_SRCDIR = $(realpath ./lib)
+LIB_SRCDIR = $(realpath $(srcdir)/lib)
 LIB_TOP_SRCDIR = $(realpath $(top_srcdir))
 
 SRC_SRCDIR = $(realpath $(top_srcdir)/src)
@@ -61,9 +62,10 @@ all: lib/libgnu.a src/libemacs.so src/android-emacs 
$(LIBSRC_BINARIES)
 config.status: $(top_srcdir)/config.status
        $(AM_V_GEN) touch config.status
 
-src/verbose.mk: verbose.mk.android
+src/verbose.mk: $(srcdir)/verbose.mk.android
        $(AM_V_GEN) mkdir -p src
-       $(AM_V_SILENT) cp -f verbose.mk.android src/verbose.mk
+       $(AM_V_SILENT) cp -f $(srcdir)/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
@@ -86,21 +88,25 @@ PRE_BUILD_DEPS=$(top_builddir)/lib/libgnu.a         \
               $(top_builddir)/lib-src/make-docfile
 
 lib/config.h: $(top_builddir)/src/config.h.android
-       $(AM_V_GEN) cp -f -p $(top_builddir)/src/config.h.android \
+       $(AM_V_GEN) cp -f -p $(top_builddir)/src/config.h.android       \
          lib/config.h
 
 lib/gnulib.mk: $(top_builddir)/lib/gnulib.mk.android
-       $(AM_V_GEN) cp -f -p $(top_builddir)/lib/gnulib.mk.android \
+       $(AM_V_GEN) cp -f -p $(top_builddir)/lib/gnulib.mk.android      \
          lib/gnulib.mk
        $(AM_V_SILENT) \
-       sed -i 's/srcdir =.*$$/srcdir = $(subst /,\/,$(LIB_SRCDIR))/g' \
+       sed -i 's/srcdir =.*$$/srcdir = $(subst /,\/,$(LIB_SRCDIR))/g'  \
          lib/gnulib.mk
 
 lib/Makefile: $(top_builddir)/lib/Makefile.android
-       $(AM_V_GEN) cp -f -p $(top_builddir)/lib/Makefile.android \
-         lib/Makefile
+       $(AM_V_GEN) cp -f -p $(top_builddir)/lib/Makefile.android       \
+            lib/Makefile
        $(AM_V_SILENT) \
        sed -i 's/top_srcdir =.*$$/top_srcdir = $(subst 
/,\/,$(LIB_TOP_SRCDIR))/g' \
+         lib/Makefile \
+        && sed -i 's/^srcdir =.*$$/srcdir = $(subst /,\/,$(LIB_SRCDIR))/g' \
+         lib/Makefile                                                    \
+       && sed -i 's/VPATH =.*$$/VPATH = $(subst /,\/,$(LIB_SRCDIR))/g' \
          lib/Makefile
 
 # What is needed to build gnulib.
@@ -137,10 +143,10 @@ src/Makefile src/config.h &: 
$(top_builddir)/src/config.h.android \
 # cross-compiled binaries at ./lib-src.
        $(AM_V_SILENT) \
        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)
+# Edit out anything saying -I($(top_srcdir)/lib) into
+# -I$../(srcdir)/lib; that should be covered by -I$(lib)
        $(AM_V_SILENT) \
-       sed -i 's/-I\$$(top_srcdir)\/lib//g' src/Makefile
+       sed -i 's/-I\$$(top_srcdir)\/lib/-I..\/$(subst /,\/,$(srcdir))\/lib/g' 
src/Makefile
 
 .PHONY: src/android-emacs src/libemacs.so
 
@@ -167,6 +173,9 @@ lib-src/Makefile: $(top_builddir)/lib-src/Makefile.android
 # Edit out SCRIPTS, it interferes with the build.
        $(AM_V_SILENT) \
        sed -i 's/^SCRIPTS=.*$$/SCRIPTS=/g' lib-src/Makefile
+# Make BASE_CFLAGS also include cross/lib as well as ../lib.
+       $(AM_V_SILENT) \
+       sed -i 's/-I\.\.\/lib/-I..\/lib -I..\/$(subst /,\/,$(srcdir))\/lib/g' 
lib-src/Makefile
 
 .PHONY: $(LIBSRC_BINARIES)
 $(LIBSRC_BINARIES) &: src/verbose.mk $(top_builddir)/$@ lib/libgnu.a   \
@@ -181,7 +190,8 @@ clean:
          make -C lib clean;            \
        fi
        rm -rf lib/config.h
-       make -C ndk-build clean
+# ndk-build won't have been generated in a non-Android build.
+       -make -C ndk-build clean
 
 distclean bootstrap-clean: clean
        if [ -e lib/Makefile ]; then            \
diff --git a/java/Makefile.in b/java/Makefile.in
index bff021752c7..994ffdd0828 100644
--- a/java/Makefile.in
+++ b/java/Makefile.in
@@ -20,6 +20,7 @@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 srcdir = @srcdir@
+builddir = @builddir@
 version = @version@
 
 # This is the host lib-src and lib, not the cross compiler's lib-src.
@@ -40,7 +41,8 @@ ANDROID_JAR = @ANDROID_JAR@
 ANDROID_ABI = @ANDROID_ABI@
 ANDROID_SDK_18_OR_EARLIER = @ANDROID_SDK_18_OR_EARLIER@
 ANDROID_SDK_8_OR_EARLIER = @ANDROID_SDK_8_OR_EARLIER@
-JAVAFLAGS = @JAVAFLAGS@
+WARN_JAVAFLAGS = @WARN_JAVAFLAGS@
+JAVAFLAGS = $(WARN_JAVAFLAGS) -classpath "$(ANDROID_JAR):$(srcdir)"
 
 # Android 4.3 and earlier require Emacs to be signed with a different
 # digital signature algorithm.
@@ -61,9 +63,11 @@ else
 AAPT_ASSET_ARGS =
 endif
 
-SIGN_EMACS = -keystore emacs.keystore -storepass emacs1 $(JARSIGNER_FLAGS)
-SIGN_EMACS_V2 = sign --v2-signing-enabled --ks emacs.keystore  \
-       --debuggable-apk-permitted --ks-pass pass:emacs1
+SIGN_EMACS = -keystore $(srcdir)/emacs.keystore -storepass     \
+       emacs1 $(JARSIGNER_FLAGS)
+SIGN_EMACS_V2 = sign --v2-signing-enabled --ks                 \
+       $(srcdir)/emacs.keystore -debuggable-apk-permitted      \
+       --ks-pass pass:emacs1
 
 JAVA_FILES := $(wildcard $(srcdir)/org/gnu/emacs/*.java)
 RESOURCE_FILES := $(foreach file,$(wildcard $(srcdir)/res/*),  \
@@ -128,7 +132,7 @@ CROSS_LIBS = $(top_builddir)/cross/src/libemacs.so
 CROSS_ARCHIVES = $(top_builddir)/cross/lib/libgnu.a
 
 # Third party libraries to compile.
-include $(top_builddir)/cross/ndk-build/ndk-build.mk
+-include $(top_builddir)/cross/ndk-build/ndk-build.mk
 
 .PHONY: $(CROSS_BINS) $(CROSS_LIBS) $(CROSS_ARCHIVES)
 
@@ -169,9 +173,9 @@ install_temp: $(CROSS_BINS) $(CROSS_LIBS) $(RESOURCE_FILES)
        $(AM_V_SILENT) mkdir -p install_temp/assets/lisp
        $(AM_V_SILENT) mkdir -p install_temp/assets/info
 # Install architecture independents to assets/etc and assets/lisp
-       $(AM_V_SILENT) cp -r $(top_builddir)/lisp install_temp/assets
-       $(AM_V_SILENT) cp -r $(top_builddir)/etc install_temp/assets
-       $(AM_V_SILENT) cp -r $(top_builddir)/info install_temp/assets
+       $(AM_V_SILENT) cp -r $(top_srcdir)/lisp install_temp/assets
+       $(AM_V_SILENT) cp -r $(top_srcdir)/etc install_temp/assets
+       $(AM_V_SILENT) cp -r $(top_srcdir)/info install_temp/assets
 # Remove undesirable files from those directories.
        $(AM_V_SILENT)                                          \
        for subdir in `find install_temp -type d -print`; do    \
@@ -227,28 +231,29 @@ emacs.apk-in: install_temp 
install_temp/assets/directory-tree \
        $(AM_V_AAPT) $(AAPT) p -I "$(ANDROID_JAR)" -F $@   \
          -f -M AndroidManifest.xml $(AAPT_ASSET_ARGS)     \
          -A install_temp/assets                           \
-         -S res -J install_temp
+         -S $(top_srcdir)/java/res -J install_temp
        $(AM_V_SILENT) pushd install_temp &> /dev/null; \
          $(AAPT) add ../$@ `find lib -type f`;         \
        popd &> /dev/null
        $(AM_V_SILENT) rm -rf install_temp
 
 # Makefile itself.
-.PRECIOUS: ../config.status Makefile
-../config.status: $(top_srcdir)/configure.ac $(top_srcdir)/m4/*.m4
+.PRECIOUS: $(top_srcdir)/config.status Makefile
+$(top_srcdir)/config.status: $(top_srcdir)/configure.ac $(top_srcdir)/m4/*.m4
        $(MAKE) -C $(dir $@) $(notdir $@)
-Makefile: ../config.status $(top_builddir)/java/Makefile.in
+Makefile: $(top_srcdir)/config.status $(top_srcdir)/java/Makefile.in
        $(MAKE) -C .. java/$@
 
 # AndroidManifest.xml:
 AndroidManifest.xml: $(top_srcdir)/configure.ac $(top_srcdir)/m4/*.m4 \
-  AndroidManifest.xml.in
+  $(srcdir)/AndroidManifest.xml.in
        pushd ..; ./config.status java/AndroidManifest.xml; popd
 
 # R.java:
 $(RESOURCE_FILE): $(RESOURCE_FILES)
-       $(AM_V_GEN) $(AAPT) p -I "$(ANDROID_JAR)" -f \
-         -J $(dir $@) -M AndroidManifest.xml -S res
+       $(AM_V_GEN) $(AAPT) p -I "$(ANDROID_JAR)" -f    \
+         -J $(dir $@) -M AndroidManifest.xml           \
+         -S $(top_srcdir)/java/res
 
 # Make all class files depend on R.java being built.
 $(CLASS_FILES): $(RESOURCE_FILE)
@@ -261,8 +266,9 @@ $(CLASS_FILES) &: $(JAVA_FILES)
 # nested classes.
 
 classes.dex: $(CLASS_FILES)
-       $(AM_V_D8) $(D8) --classpath $(ANDROID_JAR) \
-         $(subst $$,\$$,$(shell find . -type f -name *.class))
+       $(AM_V_D8) $(D8) --classpath $(ANDROID_JAR)             \
+         $(subst $$,\$$,$(shell find $(srcdir) -type f         \
+           -name *.class)) --output $(builddir)
 
 # When emacs.keystore expires, regenerate it with:
 #
@@ -271,7 +277,7 @@ classes.dex: $(CLASS_FILES)
 
 .PHONY: clean maintainer-clean
 
-$(APK_NAME): classes.dex emacs.apk-in emacs.keystore
+$(APK_NAME): classes.dex emacs.apk-in $(srcdir)/emacs.keystore
        $(AM_V_GEN)
        $(AM_V_SILENT) cp -f emacs.apk-in $@.unaligned
        $(AM_V_SILENT) $(AAPT) add $@.unaligned classes.dex



reply via email to

[Prev in Thread] Current Thread [Next in Thread]