]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Don’t search for X11 when cross compiling (#110345)
authorZack Weinberg <zackw@panix.com>
Mon, 2 Nov 2020 00:23:12 +0000 (19:23 -0500)
committerZack Weinberg <zackw@panix.com>
Mon, 2 Nov 2020 00:51:47 +0000 (19:51 -0500)
This is undesirable because X11 development headers and libraries
found by searching /usr are much more likely to belong to the build
operating system than the host operating system (being cross-compiled
for).  A particularly problematic case, from the original bug report,
is “using a sysroot where the target is binary compatible with the
host.  In this case AC_PATH_X will happily look at /usr and say that
yes, X is available, even if the sysroot doesn't have X.”

To cross-compile X client applications, the recommended procedure is
to put X11 headers and libraries for the host system in the cross
compiler’s default search path; alternatively, --x-includes and
--x-libraries can be used.

Fixes bug #110345.  Problem reported by Ross Burton.

 * lib/autoconf/libs.m4 (_AC_PATH_X): Before doing anything else,
   see whether a test compilation with no special options (just -lX11)
   will work.  If it doesn’t, only invoke _AC_PATH_X_XMKMF and
   _AC_PATH_X_DIRECT when not cross compiling.

NEWS
lib/autoconf/libs.m4

diff --git a/NEWS b/NEWS
index 42095344128ae45023335ffe8b87890ef333f8c0..4e2d5a1068c1e1c56ced33d4f5a7d21e1cf7809d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -329,6 +329,17 @@ GNU Autoconf NEWS - User visible changes.
 *** AC_CHECK_DECL and AC_CHECK_DECLS will now detect missing declarations for
     library functions that are also Clang compiler builtins.
 
+*** AC_PATH_X and AC_PATH_XTRA don’t search for X11 when cross-compiling.
+
+  Libraries and headers found by running xmkmf or searching /usr/X11,
+  /usr/X11R7, etc. are likely to belong to a native X11 installation
+  for the build machine and to be inappropriate for cross compilation.
+
+  To cross-compile programs that require X11, we recommend putting the
+  headers and libraries for the host system in your cross-compiler’s
+  default search paths.  Alternatively, use configure’s --x-includes
+  and --x-libraries command line options to tell it where they are.
+
 *** AC_PROG_CC is now defined via AC_DEFUN_ONCE.
 
   This means configure scripts will no longer check repeatedly for the
index becb2231d1874dfc4327c7c141f58e180567a359..7b9bc30de1164b6ba42465bd229df132092e3c6d 100644 (file)
@@ -298,22 +298,34 @@ fi # $ac_x_libraries = no
 # ----------
 # Compute ac_cv_have_x.
 AC_DEFUN([_AC_PATH_X],
+[AC_REQUIRE([AC_PROG_CC])]dnl To ensure that $cross_compiling is finalized.
 [AC_CACHE_VAL(ac_cv_have_x,
 [# One or both of the vars are not set, and there is no cached value.
-ac_x_includes=no ac_x_libraries=no
-_AC_PATH_X_XMKMF
-_AC_PATH_X_DIRECT
-case $ac_x_includes,$ac_x_libraries in #(
-  no,* | *,no | *\'*)
-    # Didn't find X, or a directory has "'" in its name.
-    ac_cv_have_x="have_x=no";; #(
-  *)
-    # Record where we found X for the cache.
+ac_x_includes=no
+ac_x_libraries=no
+# Do we need to do anything special at all?
+ac_save_LIBS=$LIBS
+LIBS="-lX11 $LIBS"
+AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <X11/Xlib.h>],
+                               [XrmInitialize ()])],
+  [# We can compile and link X programs with no special options.
+  ac_x_includes=
+  ac_x_libraries=])
+LIBS="$ac_save_LIBS"
+# If that didn't work, only try xmkmf and filesystem searches
+# for native compilation.
+AS_IF([test x"$ac_x_includes" = xno && test "$cross_compiling" = no],
+  [_AC_PATH_X_XMKMF
+  _AC_PATH_X_DIRECT])
+# Record the results.
+AS_CASE([$ac_x_includes,$ac_x_libraries],
+  [no,* | *,no | *\'*],
+    [# Didn't find X, or a directory has "'" in its name.
+    ac_cv_have_x="have_x=no"],
+    [# Record where we found X for the cache.
     ac_cv_have_x="have_x=yes\
        ac_x_includes='$ac_x_includes'\
-       ac_x_libraries='$ac_x_libraries'"
-esac])dnl
-])
+       ac_x_libraries='$ac_x_libraries'"])])])
 
 
 # AC_PATH_X