Subject: more missing library dependencies, e.g. libXaw needs libXpm, sometimes
To: NetBSD Packages Technical Discussion List <tech-pkg@NetBSD.ORG>
From: Greg A. Woods <woods@weird.com>
List: tech-pkg
Date: 01/16/2005 02:24:14
As you might remember I've said several times that static linking
reveals a great deal of ignorance and misperception amongst software
authors and maintainers about common library dependencies, even in quite
"simple" cases.

On i386 and other users of xsrc/xfree/xc it seems libXaw needs libXpm:

	$ nm /usr/X11R6/lib/libXaw.a | fgrep Xpm                            
	         U XpmReadFileToPixmap

However on alpha, an old xsrc/xc user (at least on the netbsd-1-6
branch), doesn't need -lXpm with -lXaw:

	$ nm /usr/X11R6/lib/libXaw.a | fgrep Xpm                         >
	ksh: exit code: 1


Now one might think it OK to blindly have libXaw use bits from libXpm on
xsrc/xfree/xc systems since they provide libXpm as part of the base
system.  If all the X11-users of the world used Imake, it would be.

Unfortunately it seems an incredible number of third-party software
doesn't take into account this dependency even when they _MUST_,
e.g. when they use GNU Autoconf instead of Imake, since the standard
tricks used by GNU Autoconf et al don't make note of this dependency in
a usable way either.  Also there's no pkg-config file for Xaw (or for
any of the other base X11 core components).  In fact most Autoconf
scipts seem to hard-code whatever library lists the developer happened
to see on his or her primary system.

One quite interesting case is graphics/plotutils, who's maintainers have
half-way realized that use of libXm (Motif) might require libXpm, but
they didn't seem to notice that some newer libXaw releases might also
require libXpm.  Given the comments in their configure.in file though it
seems they don't even really fathom why Motif needs Xpm, and they still
require the person running config to "approve" the use of Xpm with a
specific command-line flag (--with-xpm[=DIR]).

The following patch "fixes" this for xsrc/xfree/xc systems, assuming one
also puts "XAW_TYPE=xpm" in one's /etc/mk.conf or similar, by making the
--with-xpm feature generic and then using XAW_TYPE to turn it on.

Is it really true that XAW_TYPE isn't a user-choice but rather a
declaration of what type of libXaw one is using?  If so then isn't there
a better way to set it properly without leading pkgsrc users into
believing that they get to make a choice?  What about non-NetBSD
systems, or even NetBSD systems where X11 is installed from pkgsrc?

Another reason for posting this tale is to ask if there's a better
solution known in any other circles -- perhaps one that might be pointed
out to the maintainers of the packages which get it wrong.

Personally I think this is just yet one more example of why it is/was a
really bad idea to try to mix GNU Autoconf and Imake.  X11 add-ons
should really have just used Imake and kept things simple.  At least the
Imake rules for XFree86 do get this right (note the XPMLIB):

  #define XawClientLibs $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XPMLIB) $(XLIB)


Sadly while the following patch fixes plotutils, it doesn't do anything
for other users of plotutils, such as gnuplot, since of course now
libplot.a also requires libXpm.  (and of course plotutils doesn't (yet)
use pkg-config either)


Maybe the right thing is to write a libplot.pc file for plotutils and to
then modify gnuplot to use it, but do we/I really want to go down that
road?  Maybe it would be better to add a proper set of X11 rules for
Autoconf which can use imake internally to learn the right things and
then get them out in the public in the next autoconf release, but that
doesn't help much with packages like plotutils that are stuck with
dinosaur versions of Autoconf.  Maybe using pkg-config _is_ the best fix
for pkgsrc in the near term.

Another package I've encountered this same problem in is teTeX-bin.
Unfortunately it has a somewhat more convoluted configuration mess.


cvs diff: Diffing graphics/plotutils
Index: graphics/plotutils/Makefile
===================================================================
RCS file: /cvs/master/m-NetBSD/main/pkgsrc/graphics/plotutils/Makefile,v
retrieving revision 1.33
diff -u -r1.33 Makefile
--- graphics/plotutils/Makefile	13 Nov 2004 22:04:53 -0000	1.33
+++ graphics/plotutils/Makefile	16 Jan 2005 06:27:32 -0000
@@ -26,5 +26,17 @@
 USE_LIBTOOL=		YES
 LTCONFIG_OVERRIDE=	${WRKSRC}/ltconfig ${WRKSRC}/libxmi/ltconfig
 
+.include "../../mk/bsd.prefs.mk"
+
+# XXX this isn't exactly right -- it seems any use of libXaw needs
+# libXpm if the host platform uses Xfree86-4.x or newer.
+#
+.if $(XAW_TYPE) == "xpm"
+CONFIGURE_ARGS+=	--with-xpm
+.endif
+
+AUTOCONF_REQD =		2.13
+.include "../../mk/autoconf.mk"
+
 .include "../../graphics/png/buildlink3.mk"
 .include "../../mk/bsd.pkg.mk"
Index: graphics/plotutils/distinfo
===================================================================
RCS file: /cvs/master/m-NetBSD/main/pkgsrc/graphics/plotutils/distinfo,v
retrieving revision 1.3
diff -u -r1.3 distinfo
--- graphics/plotutils/distinfo	9 Sep 2003 14:52:54 -0000	1.3
+++ graphics/plotutils/distinfo	16 Jan 2005 06:05:37 -0000
@@ -7,3 +7,4 @@
 SHA1 (patch-ac) = 8257da8eecfe299495f956401c5ecf0a7071cf0d
 SHA1 (patch-ad) = 09e4300025b7d10ce79cdade94d2e0f10f7d624f
 SHA1 (patch-ae) = fe78adacfd5e96ffdad2315c1d318f8d8e3fd0de
+SHA1 (patch-zz) = c26f14d7c5f07455f8c8c83c8f5134ab287d2121
cvs diff: Diffing graphics/plotutils/patches
Index: graphics/plotutils/patches/patch-zz
===================================================================
RCS file: graphics/plotutils/patches/patch-zz
diff -N graphics/plotutils/patches/patch-zz
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ graphics/plotutils/patches/patch-zz	16 Jan 2005 06:05:11 -0000
@@ -0,0 +1,48 @@
+--- configure.in.orig	Sat Jul  1 16:59:34 2000
++++ configure.in	Sun Jan 16 01:04:18 2005
+@@ -171,6 +171,22 @@
+ 
+ AC_ARG_WITH(xpm, [  --with-xpm[=DIR]        use Xpm with Motif: include and library in DIR])
+ 
++our_saved_LDFLAGS="$LDFLAGS"
++LDFLAGS="$LDFLAGS $X_LIBS"
++case "x$with_xpm" in
++  xno|x)
++    AC_CHECK_LIB(Xpm, XpmReadFileToPixmap, X_BASIC_LIBS="-lXpm $X_BASIC_LIBS", , -lXext -lX11) 
++    ;;
++  xyes)
++    AC_CHECK_LIB(Xpm, XpmReadFileToPixmap, X_BASIC_LIBS="-lXpm $X_BASIC_LIBS", , -lXext -lX11) 
++    ;;
++  *)
++    LDFLAGS="$LDFLAGS -L$with_xpm/lib"
++    AC_CHECK_LIB(Xpm, XpmReadFileToPixmap, X_CFLAGS="$X_CFLAGS -I$with_xpm/include"; X_LIBS="$X_LIBS -L$with_xpm/lib"; X_BASIC_LIBS="-lXpm $X_BASIC_LIBS", , -lXext -lX11) 
++    ;;
++esac
++LDFLAGS="$our_saved_LDFLAGS"
++
+ dnl NOTE: Motif 2.x also seems to require the extension library -lXp for
+ dnl printing, so if --with-motif is specified we always check for libXp.
+ dnl If we find it, we'll place `-lXp' before `-lXext -lX11' in
+@@ -209,22 +225,6 @@
+   fi
+ 
+   X_TOOLKIT_LIBS="-lXm $X_TOOLKIT_LIBS"
+-
+-  our_saved_LDFLAGS="$LDFLAGS"
+-  LDFLAGS="$LDFLAGS $X_LIBS"
+-  case "x$with_xpm" in
+-    xno|x)
+-      AC_CHECK_LIB(Xpm, XpmReadFileToPixmap, X_BASIC_LIBS="-lXpm $X_BASIC_LIBS", , -lXext -lX11) 
+-      ;;
+-    xyes)
+-      AC_CHECK_LIB(Xpm, XpmReadFileToPixmap, X_BASIC_LIBS="-lXpm $X_BASIC_LIBS", , -lXext -lX11) 
+-      ;;
+-    *)
+-      LDFLAGS="$LDFLAGS -L$with_xpm/lib"
+-      AC_CHECK_LIB(Xpm, XpmReadFileToPixmap, X_CFLAGS="$X_CFLAGS -I$with_xpm/include"; X_LIBS="$X_LIBS -L$with_xpm/lib"; X_BASIC_LIBS="-lXpm $X_BASIC_LIBS", , -lXext -lX11) 
+-      ;;
+-  esac
+-  LDFLAGS="$our_saved_LDFLAGS"
+ 
+   our_saved_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $X_LIBS"

-- 
						Greg A. Woods

H:+1 416 218-0098  W:+1 416 489-5852 x122  VE3TCP  RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>          Secrets of the Weird <woods@weird.com>