Subject: Re: I want X clients to install under X11BASE
To: None <tech-pkg@netbsd.org>
From: Jeremy C. Reed <reed@reedmedia.net>
List: tech-pkg
Date: 09/24/2003 13:17:11
> I'll try this ...

At first this appeared to be working (for aterm and icewm for example).

But now I see that any package that wants X11 libs uses USE_X11 even if
they would never be installed to /usr/X11R6/. For example, teTeX-bin using
my idea would install to /usr/X11R6/. This is not what I wanted.

Maybe an additional per-package variable is needed. Maybe have an
additional variable: USE_X11_FLAGS. (USE_X11 will automatically imply
USE_X11_FLAGS.)

Then software that is commonly installed to /usr/X11R6 (although not the
default with pkgsrc) will continue to use USE_X11.

And then programs that just need LDFLAGS+= ${X11_LDFLAGS} and would never
install to /usr/X11R6 will define USE_X11_FLAGS instead of USE_X11.

Maybe some examples that would use USE_X11_FLAGS instead include:

print/teTeX*-bin (and split xdvi to separate package)
print/ghostscript*
mk/ghostscript.mk
lang/elk
lang/erlang
lang/icon
lang/kaffe
lang/sather
lang/squeak
maybe a few parallel packages?

I don't think it would be very many.

Any comments on that?

Maybe I should probably rename USE_X11_FLAGS to USE_X11_LIBS.

Again this would never change anything for default pkgsrc usage.

See my diff below. Please share your comments and advice. (Maybe I should
need the BUILD_DEFS part? Plus, I need to add documentation. And add
bsd.pkg.defaults.mk that defaults to not defined.)

Please consider this. It will not be used unless someone defines it.

   Jeremy C. Reed
   http://bsd.reedmedia.net/

Index: mk/bsd.pkg.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.1288
diff -b -u -r1.1288 bsd.pkg.mk
--- mk/bsd.pkg.mk	2003/09/17 02:38:22	1.1288
+++ mk/bsd.pkg.mk	2003/09/24 20:13:43
@@ -149,6 +149,9 @@
 .if defined(USE_X11BASE)
 USE_X11?=		implied
 .endif
+.if defined(USE_X11)
+USE_X11_FLAGS?=		implied
+.endif

 # If xpkgwedge.def is found, then we need to require xpkgwedge as
 # a build dependency for X11 packages.
@@ -160,8 +163,14 @@
 _OPSYS_NEEDS_XPKGWEDGE?=	no
 .endif

+.if defined(INSTALL_X11PREFIX)
+BUILD_DEFS+=	INSTALL_X11PREFIX
+.endif
+
 .if ${PKG_INSTALLATION_TYPE} == "overwrite"
-.  if defined(USE_X11BASE)
+# If INSTALL_X11PREFIX is defined system-wide and individual package
+# has USE_X11, then install to X11BASE too.
+.  if defined(USE_X11BASE) || (defined(INSTALL_X11PREFIX) && defined(USE_X11))
 .    if !empty(_OPSYS_NEEDS_XPKGWEDGE:M[yY][eE][sS])
 BUILD_DEPENDS+=		xpkgwedge>=1.5:../../pkgtools/xpkgwedge
 .    endif
@@ -394,7 +403,7 @@
 .include "../../mk/compiler.mk"

 FIX_RPATH+=		LIBS
-.if defined(USE_X11)
+.if defined(USE_X11_FLAGS)
 X11_LDFLAGS=		# empty
 X11_LDFLAGS+=		-Wl,${RPATH_FLAG}${X11BASE}/lib
 X11_LDFLAGS+=		-L${X11BASE}/lib
@@ -402,7 +411,7 @@
 .if !empty(USE_BUILDLINK2:M[nN][oO]) && !empty(USE_BUILDLINK3:M[nN][oO])
 LDFLAGS+=		-Wl,${RPATH_FLAG}${LOCALBASE}/lib
 LDFLAGS+=		-L${LOCALBASE}/lib
-.  if defined(USE_X11)
+.  if defined(USE_X11_FLAGS)
 LDFLAGS+=		${X11_LDFLAGS}
 .  endif
 .endif
@@ -482,7 +491,7 @@

 # Figure out where the local mtree file is
 .if !defined(MTREE_FILE)
-.  if defined(USE_X11BASE)
+.  if defined(USE_X11BASE) || (defined(INSTALL_X11PREFIX) && defined(USE_X11))
 MTREE_FILE=	${_PKGSRCDIR}/mk/${OPSYS}.x11.dist
 .  else
 MTREE_FILE=	${_PKGSRCDIR}/mk/${OPSYS}.pkg.dist
@@ -1342,7 +1351,7 @@
 PKG_FAIL_REASON+= "${PKGNAME} may not be built, because it utilizes strong cryptography"
 .    endif
 .  endif
-.  if defined(USE_X11) && !exists(${X11BASE})
+.  if defined(USE_X11_FLAGS) && !exists(${X11BASE})
 PKG_FAIL_REASON+= "${PKGNAME} uses X11, but ${X11BASE} not found"
 .  endif
 .  if defined(BROKEN)
Index: mk/buildlink2/bsd.buildlink2.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/buildlink2/bsd.buildlink2.mk,v
retrieving revision 1.98
diff -b -u -r1.98 bsd.buildlink2.mk
--- mk/buildlink2/bsd.buildlink2.mk	2003/09/10 12:58:38	1.98
+++ mk/buildlink2/bsd.buildlink2.mk	2003/09/24 20:13:46
@@ -86,7 +86,7 @@
 .  endif
 .endfor

-.if defined(USE_X11)
+.if defined(USE_X11_FLAGS)
 USE_X11_LINKS?=		YES
 .  if empty(USE_X11_LINKS:M[nN][oO])
 BUILD_DEPENDS+=		x11-links>=0.12:../../pkgtools/x11-links
@@ -166,12 +166,17 @@
 do-buildlink: buildlink-directories
 buildlink-directories:
 	${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${BUILDLINK_DIR}
-.if defined(USE_X11)
+.if defined(USE_X11_FLAGS)
 	${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${BUILDLINK_X11_DIR}
 	${_PKG_SILENT}${_PKG_DEBUG}${LN} -sf ${BUILDLINK_DIR} ${BUILDLINK_X11_DIR}
 .  if empty(USE_X11_LINKS:M[nN][oO])
+# reed -- or the symlinks will be wrong
+.    if ${LOCALBASE} == "/usr"
+	${_PKG_SILENT}${_PKG_DEBUG}${LNDIR} -silent -ignorelinks ${_BLNK_X11_DIR} ${BUILDLINK_X11_DIR}
+.    else
 	${_PKG_SILENT}${_PKG_DEBUG}cd ${_BLNK_X11_DIR} && ${PAX} -rw . ${BUILDLINK_X11_DIR}
 .  endif
+.  endif
 .endif
 	${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${BUILDLINK_DIR}/include
 	${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${BUILDLINK_DIR}/lib
@@ -351,7 +356,7 @@
 # Transform references into ${X11BASE} into ${BUILDLINK_X11_DIR} but if
 # the package doesn't use X11, then just remove these references altogether.
 #
-.if defined(USE_X11)
+.if defined(USE_X11_FLAGS)
 _BLNK_TRANSFORM+=	I:${X11BASE}:${_BLNK_MANGLE_DIR.BUILDLINK_X11_DIR}
 _BLNK_TRANSFORM+=	L:${X11BASE}:${_BLNK_MANGLE_DIR.BUILDLINK_X11_DIR}
 .else
@@ -463,8 +468,9 @@
 PKGSHLIBTOOL=		${BUILDLINK_SHLIBTOOL}
 .endif
 _BLNK_WRAPPEES+=	LIBTOOL SHLIBTOOL
-.if defined(USE_X11)
+.if defined(USE_X11_FLAGS)
 IMAKE?=			${X11BASE}/bin/imake
+LNDIR?=			${X11BASE}/bin/lndir
 _BLNK_WRAPPEES+=	IMAKE
 .endif
 _ALIASES.AS=		as
@@ -594,7 +600,7 @@
 # Don't transform the arguments for imake, which uses the C preprocessor
 # to generate Makefiles, so that imake will find its config files.
 #
-.if defined(USE_X11)
+.if defined(USE_X11_FLAGS)
 _BLNK_WRAP_CACHE_ADD.IMAKE=	${_BLNK_WRAP_CACHE_ADD}
 _BLNK_WRAP_CACHE.IMAKE=		${_BLNK_WRAP_CACHE}
 _BLNK_WRAP_LOGIC.IMAKE=		${_BLNK_WRAP_LOGIC}
Index: mk/buildlink3/bsd.buildlink3.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/buildlink3/bsd.buildlink3.mk,v
retrieving revision 1.17
diff -b -u -r1.17 bsd.buildlink3.mk
--- mk/buildlink3/bsd.buildlink3.mk	2003/09/23 19:48:22	1.17
+++ mk/buildlink3/bsd.buildlink3.mk	2003/09/24 20:13:52
@@ -61,7 +61,7 @@
 BUILDLINK_DEPENDS?=	${BUILDLINK_PACKAGES}

 X11_LINKS_SUBDIR=		share/x11-links
-.if defined(USE_X11)
+.if defined(USE_X11_FLAGS)
 USE_X11_LINKS?=			YES
 .  if empty(USE_X11_LINKS:M[nN][oO])
 BUILDLINK_DEPENDS+=		x11-links
@@ -253,7 +253,7 @@
 # Add the X11 library directory to the runtime library search path if
 # the package uses X11.
 #
-.if defined(USE_X11) && \
+.if defined(USE_X11_FLAGS) && \
     (${_USE_RPATH} == "yes") && \
     empty(BUILDLINK_LDFLAGS:M${_COMPILER_LD_FLAG}${RPATH_FLAG}${X11BASE}/lib)
 BUILDLINK_LDFLAGS+=	${_COMPILER_LD_FLAG}${RPATH_FLAG}${X11BASE}/lib
@@ -296,7 +296,7 @@
 do-buildlink: buildlink-directories
 buildlink-directories:
 	${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${BUILDLINK_DIR}
-.if defined(USE_X11)
+.if defined(USE_X11_FLAGS)
 	${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${BUILDLINK_X11_DIR}
 	${_PKG_SILENT}${_PKG_DEBUG}${LN} -sf ${BUILDLINK_DIR} ${BUILDLINK_X11_DIR}
 .  if empty(USE_X11_LINKS:M[nN][oO])
@@ -565,7 +565,7 @@
 # Add ${X11BASE}/lib to the runtime library search path for USE_X11
 # packages so that X11 libraries can be found.
 #
-.if defined(USE_X11)
+.if defined(USE_X11_FLAGS)
 _BLNK_ALLOWED_RPATHDIRS+=	${X11BASE}/lib
 .endif
 #
@@ -664,7 +664,7 @@
 # ${LOCALBASE} or ${X11BASE} into references into ${BUILDLINK_DIR}.
 #
 .if ${PKG_INSTALLATION_TYPE} == "overwrite"
-.  if defined(USE_X11)
+.  if defined(USE_X11_FLAGS)
 _BLNK_TRANSFORM+=	P:${X11BASE}:${_BLNK_MANGLE_DIR.${BUILDLINK_X11_DIR}}
 .  endif
 _BLNK_TRANSFORM+=	P:${LOCALBASE}:${_BLNK_MANGLE_DIR.${BUILDLINK_DIR}}
@@ -672,7 +672,7 @@
 #
 # Transform references into ${X11BASE} into ${BUILDLINK_X11_DIR}.
 #
-.if defined(USE_X11)
+.if defined(USE_X11_FLAGS)
 _BLNK_TRANSFORM+=       I:${X11BASE}:${_BLNK_MANGLE_DIR.${BUILDLINK_X11_DIR}}
 _BLNK_TRANSFORM+=       L:${X11BASE}:${_BLNK_MANGLE_DIR.${BUILDLINK_X11_DIR}}
 .endif
@@ -780,7 +780,7 @@
 PKGSHLIBTOOL=		${BUILDLINK_SHLIBTOOL}
 .endif
 _BLNK_WRAPPEES+=	LIBTOOL SHLIBTOOL
-.if defined(USE_X11)
+.if defined(USE_X11_FLAGS)
 IMAKE?=			${X11BASE}/bin/imake
 _BLNK_WRAPPEES+=	IMAKE
 .endif
@@ -929,7 +929,7 @@
 # Don't transform the arguments for imake, which uses the C preprocessor
 # to generate Makefiles, so that imake will find its config files.
 #
-.if defined(USE_X11)
+.if defined(USE_X11_FLAGS)
 _BLNK_WRAP_CACHE_ADD.IMAKE=	${_BLNK_WRAP_CACHE_ADD}
 _BLNK_WRAP_CACHE.IMAKE=		${_BLNK_WRAP_CACHE}
 _BLNK_WRAP_LOGIC.IMAKE=		${_BLNK_WRAP_LOGIC}
@@ -1322,7 +1322,7 @@
 	  ${ECHO} "	;;";						\
 	) >> ${.TARGET}
 .    endif
-.    if defined(USE_X11)
+.    if defined(USE_X11_FLAGS)
 	${_PKG_SILENT}${_PKG_DEBUG}					\
 	( ${ECHO} "-I${X11BASE}/*)";					\
 	  ${ECHO} "	arg=\"-I${BUILDLINK_X11_DIR}/\$${arg#-I${X11BASE}/}\""; \