Cope without xmkmf

Dan Nicholson dbn.lists at gmail.com
Sun Jul 20 15:22:51 PDT 2008


On Wed, Jul 16, 2008 at 07:12:21AM -0700, Dan Nicholson wrote:
> On Wed, Jul 16, 2008 at 3:04 AM, Stepan Kasal <skasal at redhat.com> wrote:
> >
> > Are we able to make AC_PATH_XTRA ready for xmkmf-less Xorg before the
> > end of summer?
>
> The thing about xmkmf is that it works well because it's knowledgeable
> about X specifics, and it should definitely be kept as a fallback case
> for non-Xorg implementations. I can think of two ways to attack this
> cleanly, and both require upstream support:
>
> 1. Override AC_PATH_X in xorg-macros.m4, adding a preferred method
> where pkg-config is used.
>
> 2. Have Xorg install a non-pkg-config/xmkmf method to determine the
> installation directories and change autoconf AC_PATH_X to check this
> first. Something like $bindir/x-config. This could ship in the same
> util-macros package that xorg-macros.m4 comes in.

Attached are patches to add copies the X macros to xorg's util-macros
package and add a method to search via pkg-config. This isn't ideal
since it requires that the xorg macros are found to override the
autoconf ones, but I couldn't find a satisfactory way to wedge in a
pkg-config check to AC_PATH_X externally.

This approach has the advantage that we still fallback on the xmkmf and
direct approaches whether the xorg macros and pkg-config are available
or not. However, in the case that the xorg macros are available, we can
be smarter about using the X installation. It also makes sense that the
X implementation control the autoconf macros governing its usage.

Let me know what you think. I've cc'd the xorg list to see if this would
be acceptable.

--
Dan
-------------- next part --------------
>From 49db3336fa3244b68bf058469c09b9b4d741ac9e Mon Sep 17 00:00:00 2001
From: Dan Nicholson <dbn.lists at gmail.com>
Date: Sun, 20 Jul 2008 14:30:25 -0700
Subject: [PATCH] Provide local copies of the autoconf X window system macros

Add local copies of the autoconf X window system macros to allow X.Org
overrides to the autoconf defaults. The AC_PATH_X* macros have been
copied from the autoconf repository verbatim. These will be installed as
$(datadir)/aclocal/xorg-path.m4. For previous history, see
http://git.savannah.gnu.org/gitweb/?p=autoconf.git .
---
 Makefile.am  |    2 +-
 xorg-path.m4 |  375 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 376 insertions(+), 1 deletions(-)
 create mode 100644 xorg-path.m4

diff --git a/Makefile.am b/Makefile.am
index fd5c1ea..d3f87af 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -20,7 +20,7 @@
 #  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 aclocaldir = $(datadir)/aclocal
-aclocal_DATA = xorgversion.m4 xorg-macros.m4
+aclocal_DATA = xorgversion.m4 xorg-macros.m4 xorg-path.m4
 
 EXTRA_DIST = $(aclocal_DATA) ChangeLog
 
diff --git a/xorg-path.m4 b/xorg-path.m4
new file mode 100644
index 0000000..41ba6b7
--- /dev/null
+++ b/xorg-path.m4
@@ -0,0 +1,375 @@
+# This file is part of Autoconf.                       -*- Autoconf -*-
+# Checking for libraries.
+# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
+# 2002, 2003, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
+
+# This program 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 2, or (at your option)
+# any later version.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+# As a special exception, the Free Software Foundation gives unlimited
+# permission to copy, distribute and modify the configure scripts that
+# are the output of Autoconf.  You need not follow the terms of the GNU
+# General Public License when using or distributing such scripts, even
+# though portions of the text of Autoconf appear in them.  The GNU
+# General Public License (GPL) does govern all other use of the material
+# that constitutes the Autoconf program.
+#
+# Certain portions of the Autoconf source text are designed to be copied
+# (in certain cases, depending on the input) into the output of
+# Autoconf.  We call these the "data" portions.  The rest of the Autoconf
+# source text consists of comments plus executable code that decides which
+# of the data portions to output in any given case.  We call these
+# comments and executable code the "non-data" portions.  Autoconf never
+# copies any of the non-data portions into its output.
+#
+# This special exception to the GPL applies to versions of Autoconf
+# released by the Free Software Foundation.  When you make and
+# distribute a modified version of Autoconf, you may extend this special
+# exception to the GPL to apply to your modified version as well, *unless*
+# your modified version has the potential to copy into its output some
+# of the text that was the non-data portion of the version that you started
+# with.  (In other words, unless your change moves or copies text from
+# the non-data portions to the data portions.)  If your modification has
+# such potential, you must delete any notice of this special exception
+# to the GPL from your modified version.
+#
+# Written by David MacKenzie, with help from
+# Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
+# Roland McGrath, Noah Friedman, david d zuhn, and many others.
+
+# This file was copied from the autoconf repository to allow X.Org
+# specific alterations to the X window system searches. For previous
+# history, see the file lib/autoconf/libs.m4 in the autoconf repo:
+# http://git.sv.gnu.org/gitweb/?p=autoconf.git
+
+# --------------------- #
+# Checks for X window.  #
+# --------------------- #
+
+
+# _AC_PATH_X_XMKMF
+# ----------------
+# Internal subroutine of _AC_PATH_X.
+# Set ac_x_includes and/or ac_x_libraries.
+m4_define([_AC_PATH_X_XMKMF],
+[AC_ARG_VAR(XMKMF, [Path to xmkmf, Makefile generator for X Window System])dnl
+rm -f -r conftest.dir
+if mkdir conftest.dir; then
+  cd conftest.dir
+  cat >Imakefile <<'_ACEOF'
+incroot:
+	@echo incroot='${INCROOT}'
+usrlibdir:
+	@echo usrlibdir='${USRLIBDIR}'
+libdir:
+	@echo libdir='${LIBDIR}'
+_ACEOF
+  if (export CC; ${XMKMF-xmkmf}) >/dev/null 2>/dev/null && test -f Makefile; then
+    # GNU make sometimes prints "make[1]: Entering...", which would confuse us.
+    for ac_var in incroot usrlibdir libdir; do
+      eval "ac_im_$ac_var=\`\${MAKE-make} $ac_var 2>/dev/null | sed -n 's/^$ac_var=//p'\`"
+    done
+    # Open Windows xmkmf reportedly sets LIBDIR instead of USRLIBDIR.
+    for ac_extension in a so sl dylib la dll; do
+      if test ! -f "$ac_im_usrlibdir/libX11.$ac_extension" &&
+	 test -f "$ac_im_libdir/libX11.$ac_extension"; then
+	ac_im_usrlibdir=$ac_im_libdir; break
+      fi
+    done
+    # Screen out bogus values from the imake configuration.  They are
+    # bogus both because they are the default anyway, and because
+    # using them would break gcc on systems where it needs fixed includes.
+    case $ac_im_incroot in
+	/usr/include) ac_x_includes= ;;
+	*) test -f "$ac_im_incroot/X11/Xos.h" && ac_x_includes=$ac_im_incroot;;
+    esac
+    case $ac_im_usrlibdir in
+	/usr/lib | /usr/lib64 | /lib | /lib64) ;;
+	*) test -d "$ac_im_usrlibdir" && ac_x_libraries=$ac_im_usrlibdir ;;
+    esac
+  fi
+  cd ..
+  rm -f -r conftest.dir
+fi
+])# _AC_PATH_X_XMKMF
+
+
+# _AC_PATH_X_DIRECT
+# -----------------
+# Internal subroutine of _AC_PATH_X.
+# Set ac_x_includes and/or ac_x_libraries.
+m4_define([_AC_PATH_X_DIRECT],
+[# Standard set of common directories for X headers.
+# Check X11 before X11Rn because it is often a symlink to the current release.
+ac_x_header_dirs='
+/usr/X11/include
+/usr/X11R6/include
+/usr/X11R5/include
+/usr/X11R4/include
+
+/usr/include/X11
+/usr/include/X11R6
+/usr/include/X11R5
+/usr/include/X11R4
+
+/usr/local/X11/include
+/usr/local/X11R6/include
+/usr/local/X11R5/include
+/usr/local/X11R4/include
+
+/usr/local/include/X11
+/usr/local/include/X11R6
+/usr/local/include/X11R5
+/usr/local/include/X11R4
+
+/usr/X386/include
+/usr/x386/include
+/usr/XFree86/include/X11
+
+/usr/include
+/usr/local/include
+/usr/unsupported/include
+/usr/athena/include
+/usr/local/x11r5/include
+/usr/lpp/Xamples/include
+
+/usr/openwin/include
+/usr/openwin/share/include'
+
+if test "$ac_x_includes" = no; then
+  # Guess where to find include files, by looking for Xlib.h.
+  # First, try using that file with no special directory specified.
+  AC_PREPROC_IFELSE([AC_LANG_SOURCE([@%:@include <X11/Xlib.h>])],
+[# We can compile using X headers with no special include directory.
+ac_x_includes=],
+[for ac_dir in $ac_x_header_dirs; do
+  if test -r "$ac_dir/X11/Xlib.h"; then
+    ac_x_includes=$ac_dir
+    break
+  fi
+done])
+fi # $ac_x_includes = no
+
+if test "$ac_x_libraries" = no; then
+  # Check for the libraries.
+  # See if we find them without any special options.
+  # Don't add to $LIBS permanently.
+  ac_save_LIBS=$LIBS
+  LIBS="-lX11 $LIBS"
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@include <X11/Xlib.h>],
+				  [XrmInitialize ()])],
+		 [LIBS=$ac_save_LIBS
+# We can link X programs with no special library path.
+ac_x_libraries=],
+		 [LIBS=$ac_save_LIBS
+for ac_dir in `AS_ECHO(["$ac_x_includes $ac_x_header_dirs"]) | sed s/include/lib/g`
+do
+  # Don't even attempt the hair of trying to link an X program!
+  for ac_extension in a so sl dylib la dll; do
+    if test -r "$ac_dir/libX11.$ac_extension"; then
+      ac_x_libraries=$ac_dir
+      break 2
+    fi
+  done
+done])
+fi # $ac_x_libraries = no
+])# _AC_PATH_X_DIRECT
+
+
+# _AC_PATH_X
+# ----------
+# Compute ac_cv_have_x.
+AC_DEFUN([_AC_PATH_X],
+[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_cv_have_x="have_x=yes\
+	ac_x_includes='$ac_x_includes'\
+	ac_x_libraries='$ac_x_libraries'"
+esac])dnl
+])
+
+
+# AC_PATH_X
+# ---------
+# If we find X, set shell vars x_includes and x_libraries to the
+# paths, otherwise set no_x=yes.
+# Uses ac_ vars as temps to allow command line to override cache and checks.
+# --without-x overrides everything else, but does not touch the cache.
+AN_HEADER([X11/Xlib.h],  [AC_PATH_X])
+AC_DEFUN([AC_PATH_X],
+[dnl Document the X abnormal options inherited from history.
+m4_divert_once([HELP_BEGIN], [
+X features:
+  --x-includes=DIR    X include files are in DIR
+  --x-libraries=DIR   X library files are in DIR])dnl
+AC_MSG_CHECKING([for X])
+
+AC_ARG_WITH(x, [  --with-x                use the X Window System])
+# $have_x is `yes', `no', `disabled', or empty when we do not yet know.
+if test "x$with_x" = xno; then
+  # The user explicitly disabled X.
+  have_x=disabled
+else
+  case $x_includes,$x_libraries in #(
+    *\'*) AC_MSG_ERROR([Cannot use X directory names containing ']);; #(
+    *,NONE | NONE,*) _AC_PATH_X;; #(
+    *) have_x=yes;;
+  esac
+  eval "$ac_cv_have_x"
+fi # $with_x != no
+
+if test "$have_x" != yes; then
+  AC_MSG_RESULT([$have_x])
+  no_x=yes
+else
+  # If each of the values was on the command line, it overrides each guess.
+  test "x$x_includes" = xNONE && x_includes=$ac_x_includes
+  test "x$x_libraries" = xNONE && x_libraries=$ac_x_libraries
+  # Update the cache value to reflect the command line values.
+  ac_cv_have_x="have_x=yes\
+	ac_x_includes='$x_includes'\
+	ac_x_libraries='$x_libraries'"
+  AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
+fi
+])# AC_PATH_X
+
+
+
+# AC_PATH_XTRA
+# ------------
+# Find additional X libraries, magic flags, etc.
+AC_DEFUN([AC_PATH_XTRA],
+[AC_REQUIRE([AC_PATH_X])dnl
+if test "$no_x" = yes; then
+  # Not all programs may use this symbol, but it does not hurt to define it.
+  AC_DEFINE([X_DISPLAY_MISSING], 1,
+	    [Define to 1 if the X Window System is missing or not being used.])
+  X_CFLAGS= X_PRE_LIBS= X_LIBS= X_EXTRA_LIBS=
+else
+  if test -n "$x_includes"; then
+    X_CFLAGS="$X_CFLAGS -I$x_includes"
+  fi
+
+  # It would also be nice to do this for all -L options, not just this one.
+  if test -n "$x_libraries"; then
+    X_LIBS="$X_LIBS -L$x_libraries"
+    # For Solaris; some versions of Sun CC require a space after -R and
+    # others require no space.  Words are not sufficient . . . .
+    AC_MSG_CHECKING([whether -R must be followed by a space])
+    ac_xsave_LIBS=$LIBS; LIBS="$LIBS -R$x_libraries"
+    ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
+    ac_[]_AC_LANG_ABBREV[]_werror_flag=yes
+    AC_LINK_IFELSE([AC_LANG_PROGRAM()],
+      [AC_MSG_RESULT([no])
+       X_LIBS="$X_LIBS -R$x_libraries"],
+      [LIBS="$ac_xsave_LIBS -R $x_libraries"
+       AC_LINK_IFELSE([AC_LANG_PROGRAM()],
+	 [AC_MSG_RESULT([yes])
+	  X_LIBS="$X_LIBS -R $x_libraries"],
+	 [AC_MSG_RESULT([neither works])])])
+    ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
+    LIBS=$ac_xsave_LIBS
+  fi
+
+  # Check for system-dependent libraries X programs must link with.
+  # Do this before checking for the system-independent R6 libraries
+  # (-lICE), since we may need -lsocket or whatever for X linking.
+
+  if test "$ISC" = yes; then
+    X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl_s -linet"
+  else
+    # Martyn Johnson says this is needed for Ultrix, if the X
+    # libraries were built with DECnet support.  And Karl Berry says
+    # the Alpha needs dnet_stub (dnet does not exist).
+    ac_xsave_LIBS="$LIBS"; LIBS="$LIBS $X_LIBS -lX11"
+    AC_LINK_IFELSE([AC_LANG_CALL([], [XOpenDisplay])],
+		   [],
+    [AC_CHECK_LIB(dnet, dnet_ntoa, [X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet"])
+    if test $ac_cv_lib_dnet_dnet_ntoa = no; then
+      AC_CHECK_LIB(dnet_stub, dnet_ntoa,
+	[X_EXTRA_LIBS="$X_EXTRA_LIBS -ldnet_stub"])
+    fi])
+    LIBS="$ac_xsave_LIBS"
+
+    # msh at cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
+    # to get the SysV transport functions.
+    # Chad R. Larson says the Pyramis MIS-ES running DC/OSx (SVR4)
+    # needs -lnsl.
+    # The nsl library prevents programs from opening the X display
+    # on Irix 5.2, according to T.E. Dickey.
+    # The functions gethostbyname, getservbyname, and inet_addr are
+    # in -lbsd on LynxOS 3.0.1/i386, according to Lars Hecking.
+    AC_CHECK_FUNC(gethostbyname)
+    if test $ac_cv_func_gethostbyname = no; then
+      AC_CHECK_LIB(nsl, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lnsl")
+      if test $ac_cv_lib_nsl_gethostbyname = no; then
+	AC_CHECK_LIB(bsd, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lbsd")
+      fi
+    fi
+
+    # lieder at skyler.mavd.honeywell.com says without -lsocket,
+    # socket/setsockopt and other routines are undefined under SCO ODT
+    # 2.0.  But -lsocket is broken on IRIX 5.2 (and is not necessary
+    # on later versions), says Simon Leinen: it contains gethostby*
+    # variants that don't use the name server (or something).  -lsocket
+    # must be given before -lnsl if both are needed.  We assume that
+    # if connect needs -lnsl, so does gethostbyname.
+    AC_CHECK_FUNC(connect)
+    if test $ac_cv_func_connect = no; then
+      AC_CHECK_LIB(socket, connect, X_EXTRA_LIBS="-lsocket $X_EXTRA_LIBS", ,
+	$X_EXTRA_LIBS)
+    fi
+
+    # Guillermo Gomez says -lposix is necessary on A/UX.
+    AC_CHECK_FUNC(remove)
+    if test $ac_cv_func_remove = no; then
+      AC_CHECK_LIB(posix, remove, X_EXTRA_LIBS="$X_EXTRA_LIBS -lposix")
+    fi
+
+    # BSDI BSD/OS 2.1 needs -lipc for XOpenDisplay.
+    AC_CHECK_FUNC(shmat)
+    if test $ac_cv_func_shmat = no; then
+      AC_CHECK_LIB(ipc, shmat, X_EXTRA_LIBS="$X_EXTRA_LIBS -lipc")
+    fi
+  fi
+
+  # Check for libraries that X11R6 Xt/Xaw programs need.
+  ac_save_LDFLAGS=$LDFLAGS
+  test -n "$x_libraries" && LDFLAGS="$LDFLAGS -L$x_libraries"
+  # SM needs ICE to (dynamically) link under SunOS 4.x (so we have to
+  # check for ICE first), but we must link in the order -lSM -lICE or
+  # we get undefined symbols.  So assume we have SM if we have ICE.
+  # These have to be linked with before -lX11, unlike the other
+  # libraries we check for below, so use a different variable.
+  # John Interrante, Karl Berry
+  AC_CHECK_LIB(ICE, IceConnectionNumber,
+    [X_PRE_LIBS="$X_PRE_LIBS -lSM -lICE"], , $X_EXTRA_LIBS)
+  LDFLAGS=$ac_save_LDFLAGS
+
+fi
+AC_SUBST(X_CFLAGS)dnl
+AC_SUBST(X_PRE_LIBS)dnl
+AC_SUBST(X_LIBS)dnl
+AC_SUBST(X_EXTRA_LIBS)dnl
+])# AC_PATH_XTRA
-- 
1.5.6.2

-------------- next part --------------
>From c86d7fd63a0bc416944f2b000021c337de0da099 Mon Sep 17 00:00:00 2001
From: Dan Nicholson <dbn.lists at gmail.com>
Date: Sun, 20 Jul 2008 14:37:30 -0700
Subject: [PATCH] Prefer pkg-config when searching for the X installation

Add a new internal subroutine for _AC_PATH_X, _AC_PATH_X_PKGCONFIG,
which sets the X installation directories by searching for the x11
package through pkg-config. If pkg-config is not available, or the x11
package is not found, then it will fall back to using the same checks
in _AC_PATH_XMKMF and _AC_PATH_X_DIRECT.
---
 xorg-path.m4 |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/xorg-path.m4 b/xorg-path.m4
index 41ba6b7..87476ba 100644
--- a/xorg-path.m4
+++ b/xorg-path.m4
@@ -59,6 +59,24 @@
 # --------------------- #
 
 
+# _AC_PATH_X_PKGCONFIG
+# --------------------
+# Internal subroutine of _AC_PATH_X.
+# Set ac_x_includes and/or ac_x_libraries.
+m4_define([_AC_PATH_X_PKGCONFIG],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+PKG_CHECK_EXISTS([x11],
+[case `$PKG_CONFIG --cflags-only-I x11 2>/dev/null` in
+  '') ac_x_includes= ;;
+  *)  ac_x_includes=`$PKG_CONFIG --variable=includedir x11 2>/dev/null` ;;
+esac
+case `$PKG_CONFIG --libs-only-L x11 2>/dev/null` in
+  '') ac_x_libraries= ;;
+  *)  ac_x_libraries=`$PKG_CONFIG --variable=libdir x11 2>/dev/null` ;;
+esac])
+])# _AC_PATH_X_PKGCONFIG
+
+
 # _AC_PATH_X_XMKMF
 # ----------------
 # Internal subroutine of _AC_PATH_X.
@@ -195,6 +213,7 @@ AC_DEFUN([_AC_PATH_X],
 [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_PKGCONFIG
 _AC_PATH_X_XMKMF
 _AC_PATH_X_DIRECT
 case $ac_x_includes,$ac_x_libraries in #(
-- 
1.5.6.2

-------------- next part --------------
>From ab0fda2d1fb4e7810b658869f9316a6dfe8c5c09 Mon Sep 17 00:00:00 2001
From: Dan Nicholson <dbn.lists at gmail.com>
Date: Sun, 20 Jul 2008 15:09:21 -0700
Subject: [PATCH] Use `echo' when AS_ECHO isn't available

Since the AS_ECHO macro is only available on autoconf-2.61a and newer
releases, just use `echo' when it's not available.
---
 xorg-path.m4 |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/xorg-path.m4 b/xorg-path.m4
index 87476ba..e26b149 100644
--- a/xorg-path.m4
+++ b/xorg-path.m4
@@ -54,6 +54,9 @@
 # history, see the file lib/autoconf/libs.m4 in the autoconf repo:
 # http://git.sv.gnu.org/gitweb/?p=autoconf.git
 
+# Compatibility with earlier autoconf
+m4_ifndef([AS_ECHO], m4_define([AS_ECHO], [echo])])
+
 # --------------------- #
 # Checks for X window.  #
 # --------------------- #
-- 
1.5.6.2



More information about the xorg mailing list