Subject: xsrc/12935: Fixes to library build rules in XF4
To: None <gnats-bugs@gnats.netbsd.org>
From: Johnny C. Lam <lamj@stat.cmu.edu>
List: netbsd-bugs
Date: 05/14/2001 09:48:16
>Number:         12935
>Category:       xsrc
>Synopsis:       library build rules are incorrect if X11ProjectRoot defined
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    xsrc-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 14 06:48:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Johnny C. Lam
>Release:        NetBSD-20010406 i386 snapshot
>Organization:
	Department of Statistics, Carnegie Mellon University
>Environment:
System: NetBSD localhost 1.5U NetBSD 1.5U (HOBBES) #0: Sat Apr 28 18:49:54 EDT 2001 jlam@localhost:/usr/obj/usr/src/sys/arch/i386/compile/HOBBES i386
Architecture: i386
Machine: i386
>Description:
The library build rules on BSD systems in bsdLib.* in XFree86-4.x are
broken when X11ProjectRoot is defined.  The current rules only pass
-L$(USRLIBDIR) and -R$(USRLIBDIR) to the linker regardless of the definition
of X11ProjectRoot.  The X11.rules file conditionally sets UsrLibDirPath
and LdPreLibs to the correct paths which include $(X11PROJECTROOT)/lib when
X11ProjectRoot is defined, but the bsdLib.* files don't use these values
when linking libraries.  This causes anything that links against X11
libraries to break when X11ProjectRoot != ProjectRoot, as is the case if
one uses xpkgwedge in pkgsrc.

For the patch to bsdLib.rules, if X11ProjectRoot is defined,
USRLIBDIRPATH is set to $(USRLIBDIR):$(XPROJECTROOT)/lib, which is
correct if we are linking against X11 libraries.

For the patch to bsdLib.tmpl, if X11ProjectRoot is defined, LDPRELIBS
is set to "-L$(USRLIBDIR) -L$(XPROJECTROOT)/lib", while LDPRELIB is
always only set to -L$(USRLIBDIR), which is wrong if we need to link
against X11 libraries.

These changes only affect people who define X11ProjectRoot in their
host.def file, which is what xpkgwedge does.  For all stock XFree86
users, this makes no visible change.

>How-To-Repeat:
	Using XFree86-4.0.2, a -current pkgsrc, and xpkgwedge installed,
try compiling pkgsrc/x11/Xaw3d.  The library will fail to link as the
only library search path passed to the linker is /usr/pkg/lib.
>Fix:
	The following patch fixes bsdLib.rules and bsdLib.tmpl to use the
proper Makefile variables when building libraries.  In bsdLib.rules, instead
of passing $(USRLIBDIR) to the linker for the rpath, $(USRLIBDIRPATH) is
passed instead, which is already conditionally set to the correct value
depending on the definition of X11ProjectRoot.  In bsdLib.tmpl, instead of
using $(LDPRELIB), use $(LDPRELIBS) instead, which is a superset of the
value of $(LDPRELIB), but also conditionally contains linker directives to
search in $(X11PROJECT)/lib for libraries when X11Project is defined.

--- bsdLib.rules.orig	Mon Mar 19 00:00:09 2001
+++ bsdLib.rules
@@ -185,7 +185,7 @@
 #define ShLibIncludeFile <bsdLib.tmpl>
 #endif
 #ifndef SharedLibraryLoadFlags
-#define SharedLibraryLoadFlags -shared -Wl,-rpath,$(USRLIBDIR)
+#define SharedLibraryLoadFlags -shared -Wl,-rpath,$(USRLIBDIRPATH)
 #endif
 #ifndef PositionIndependentCFlags
 #define PositionIndependentCFlags -fPIC
--- bsdLib.tmpl.orig	Mon Mar 19 00:00:09 2001
+++ bsdLib.tmpl
@@ -46,18 +46,18 @@
 #if !defined(SharedX11Reqs)
 #define SharedX11Reqs
 #endif
-#define SharedOldXReqs	$(LDPRELIB) $(XLIBONLY)
-#define SharedXtReqs	$(LDPRELIB) $(XLIBONLY) $(SMLIB) $(ICELIB)
-#define SharedXawReqs	$(LDPRELIB) $(XMULIB) $(XTOOLLIB) $(XPMLIB) $(XLIB)
-#define SharedXaw6Reqs	$(LDPRELIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
-#define SharedXmuReqs	$(LDPRELIB) $(XTOOLLIB) $(XLIB)
-#define SharedXextReqs	$(LDPRELIB) $(XLIBONLY)
-#define SharedXiReqs	$(LDPRELIB) $(XLIB)
-#define SharedPexReqs	$(LDPRELIB) $(XLIBONLY) MathLibrary
-#define SharedXtstReqs	$(LDPRELIB) $(XLIB)
-#define SharedXieReqs	$(LDPRELIB) $(XLIBONLY)
-#define SharedSMReqs	$(LDPRELIB) $(ICELIB)
-#define SharedFrescoReqs	$(LDPRELIB) $(XLIBONLY) FrescoSysLibs
-#define SharedXtfReqs	$(LDPRELIB) $(FRESCOLIB) $(XTOOLLIB) $(XLIB) FrescoSysLibs
+#define SharedOldXReqs	$(LDPRELIBS) $(XLIBONLY)
+#define SharedXtReqs	$(LDPRELIBS) $(XLIBONLY) $(SMLIB) $(ICELIB)
+#define SharedXawReqs	$(LDPRELIBS) $(XMULIB) $(XTOOLLIB) $(XPMLIB) $(XLIB)
+#define SharedXaw6Reqs	$(LDPRELIBS) $(XMULIB) $(XTOOLLIB) $(XLIB)
+#define SharedXmuReqs	$(LDPRELIBS) $(XTOOLLIB) $(XLIB)
+#define SharedXextReqs	$(LDPRELIBS) $(XLIBONLY)
+#define SharedXiReqs	$(LDPRELIBS) $(XLIB)
+#define SharedPexReqs	$(LDPRELIBS) $(XLIBONLY) MathLibrary
+#define SharedXtstReqs	$(LDPRELIBS) $(XLIB)
+#define SharedXieReqs	$(LDPRELIBS) $(XLIBONLY)
+#define SharedSMReqs	$(LDPRELIBS) $(ICELIB)
+#define SharedFrescoReqs	$(LDPRELIBS) $(XLIBONLY) FrescoSysLibs
+#define SharedXtfReqs	$(LDPRELIBS) $(FRESCOLIB) $(XTOOLLIB) $(XLIB) FrescoSysLibs
 
 #endif /* UseElfFormat */
>Release-Note:
>Audit-Trail:
>Unformatted: