summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2020-11-01 19:23:12 -0500
committerZack Weinberg <zackw@panix.com>2020-11-01 19:51:47 -0500
commit33c3a47c04ab70a4dd54963fe433a171bc03747f (patch)
tree906b142092f4fcaeacf0d4ae05d0c9fe31809b85
parentbf19f95cf4766c8a22583dfdbbbbc67a97c4b6b0 (diff)
downloadautoconf-33c3a47c04ab70a4dd54963fe433a171bc03747f.tar.gz
Don’t search for X11 when cross compiling (#110345)
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.
-rw-r--r--NEWS11
-rw-r--r--lib/autoconf/libs.m436
2 files changed, 35 insertions, 12 deletions
diff --git a/NEWS b/NEWS
index 42095344..4e2d5a10 100644
--- 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
diff --git a/lib/autoconf/libs.m4 b/lib/autoconf/libs.m4
index becb2231..7b9bc30d 100644
--- a/lib/autoconf/libs.m4
+++ b/lib/autoconf/libs.m4
@@ -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