Subject: Re: pkg/17776
To: Julien T. Letessier <mezis@free.fr>
From: grant beattie <grant@netbsd.org>
List: tech-pkg
Date: 07/31/2003 20:26:52
On Fri, Jul 11, 2003 at 09:13:21AM +0200, Julien T. Letessier wrote:

> The advantage is that it's generalizable to more tools as necessary. For
> instance, I remember stumbling on a package that requires GNU 'tr' (I can find
> which if you need me to). 'grep' might be a good example too.

I've put together a tools.mk to do this - see below. it does nothing
on platforms which aren't listed in INCOMPAT_<tool> or
USE_OPSYS_<tool>. this also eliminates the need for the separate
buildlink2.mk files.

> If SunOS is the only OS where these problems occur, a simple though ugly
> solution is possible to just inconditionnaly link *all* of the GNU coreutils,
> gawk and gsed into .buildlink/bin for (every?) package, just on SunOS.

heh, coreutils is huge! and the number of packages which really need the
GNU tools are limited, most just want working tools. if a package really
needs GNU awk/grep/sed, it can define USE_GNU_<tool>..

I'll commit this, perhaps with some minor changes, after I've tested a
bit more.

g.

Index: bsd.pkg.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.1226
diff -u -r1.1226 bsd.pkg.mk
--- bsd.pkg.mk	2003/07/30 15:04:21	1.1226
+++ bsd.pkg.mk	2003/07/31 10:21:59
@@ -360,6 +360,8 @@
 .  include "../../mk/gcc.buildlink2.mk"
 .endif
 
+.include "../../mk/tools.mk"
+
 # export the flags needed to compile and link pthreaded code
 MAKE_ENV+=		PTHREAD_CFLAGS="${PTHREAD_CFLAGS}"
 MAKE_ENV+=		PTHREAD_LDFLAGS="${PTHREAD_LDFLAGS}"


--- /dev/null	Thu Jul 31 20:04:39 2003
+++ tools.mk	Thu Jul 31 20:14:03 2003
@@ -0,0 +1,134 @@
+# $NetBSD$
+#
+# handle platforms with broken tools in the base system, such as sed
+# and awk.
+#
+# allow packages to either use the "upgraded" versions (default) or to
+# force the use of the GNU tools.
+#
+
+.if !defined(TOOLS_MK)
+TOOLS_MK=	# defined
+
+.if defined(USE_BUILDLINK2)
+
+.include "../../mk/bsd.prefs.mk"
+
+TOOLS=			AWK GREP SED
+
+# where said tool is completely unusable, and no suitable replacement
+# is available.
+INCOMPAT_AWK?=		# empty
+INCOMPAT_GREP?=		# empty
+INCOMPAT_SED?=		# empty
+
+# a suitable replacement is available in the base system.
+USE_OPSYS_AWK?=		SunOS-*-*
+USE_OPSYS_GREP?=	SunOS-*-*
+USE_OPSYS_SED?=		SunOS-*-*
+
+# decide whether we need to bring in pkgsrc versions or whether to
+# use a suitable replacement in the base system.
+.for _tool_ in ${TOOLS}
+_NEED_GNU_${_tool_}?=		NO
+_REPLACE_OPSYS_${_tool_}?=	NO
+.  if defined(USE_GNU_${_tool_})
+_NEED_GNU_${_tool_}=		YES
+.  else
+.    for _pattern_ in ${_INCOMPAT_${_tool_}} ${INCOMPAT_${_tool_}}
+.      if !empty(MACHINE_PLATFORM:M${_pattern_})
+_NEED_GNU_${_tool_}=		YES
+.      endif
+.    endfor
+.    for _pattern_ in ${USE_OPSYS_${_tool_}}
+.      if !empty(MACHINE_PLATFORM:M${_pattern_})
+_REPLACE_OPSYS_${_tool_}=	YES
+.      endif
+.    endfor
+.  endif
+.endfor
+
+.if ${_NEED_GNU_AWK} == "YES" && empty(PKGPATH:Mlang/gawk)
+BUILDLINK_DEPENDS.gawk?=	gawk>=3.1.1nb1
+BUILDLINK_PKGSRCDIR.gawk?=	../../lang/gawk
+BUILDLINK_DEPMETHOD.gawk?=      build
+BUILDLINK_PACKAGES+=            gawk
+BUILDLINK_PREFIX.gawk_DEFAULT=  ${LOCALBASE}
+BUILDLINK_FILES.gawk=           bin/${GNU_PROGRAM_PREFIX}awk
+EVAL_PREFIX+=                   BUILDLINK_PREFIX.gawk=gawk
+.endif
+
+.if ${_NEED_GNU_AWK} == "YES" || ${_REPLACE_OPSYS_AWK} == "YES"
+BUILDLINK_TARGETS+=     gawk-buildlink gawk-buildlink-bin
+.endif
+
+.if ${_NEED_GNU_GREP} == "YES" && empty(PKGPATH:Mtextproc/grep)
+BUILDLINK_DEPENDS.grep?=	grep>=3.1.1
+BUILDLINK_PKGSRCDIR.grep?=	../../textproc/grep
+BUILDLINK_DEPMETHOD.grep?=      build
+BUILDLINK_PACKAGES+=            grep
+BUILDLINK_PREFIX.grep=		${LOCALBASE}
+BUILDLINK_FILES.grep=           bin/${GNU_PROGRAM_PREFIX}grep
+EVAL_PREFIX+=                   BUILDLINK_PREFIX.grep=grep
+.endif
+
+.if ${_NEED_GNU_GREP} == "YES" || ${_REPLACE_OPSYS_GREP} == "YES"
+BUILDLINK_TARGETS+=     grep-buildlink grep-buildlink-bin
+.endif
+
+.if ${_NEED_GNU_SED} == "YES" && empty(PKGPATH:Mtextproc/sed)
+BUILDLINK_DEPENDS.gsed?=	gsed>=3.0.2
+BUILDLINK_PKGSRCDIR.gsed?=	../../textproc/gsed
+BUILDLINK_DEPMETHOD.gsed?=      build
+BUILDLINK_PACKAGES+=            gsed
+BUILDLINK_PREFIX.gsed_DEFAULT=  ${LOCALBASE}
+BUILDLINK_FILES.gsed=           bin/${GNU_PROGRAM_PREFIX}sed
+EVAL_PREFIX+=                   BUILDLINK_PREFIX.gsed=gsed
+.endif
+
+.if ${_NEED_GNU_SED} == "YES" || ${_REPLACE_OPSYS_SED} == "YES"
+BUILDLINK_TARGETS+=     gsed-buildlink gsed-buildlink-bin
+.endif
+
+gawk-buildlink: _BUILDLINK_USE
+gawk-buildlink-bin:
+.if ${_NEED_GNU_AWK} == "YES" && empty(PKGPATH:Mlang/gawk)
+	${_PKG_SILENT}${_PKG_DEBUG}                             \
+	[ ! -f ${BUILDLINK_DIR}/bin/awk ] &&                    \
+	  ${LN} -fs ${LOCALBASE}/bin/${GNU_PROGRAM_PREFIX}awk \
+	  ${BUILDLINK_DIR}/bin/awk
+.elif ${_REPLACE_OPSYS_AWK} == "YES"
+	${_PKG_SILENT}${_PKG_DEBUG}                             \
+	[ ! -f ${BUILDLINK_DIR}/bin/awk ] &&                    \
+	${LN} -fs ${AWK} ${BUILDLINK_DIR}/bin/awk
+.endif
+
+grep-buildlink: _BUILDLINK_USE
+grep-buildlink-bin:
+.if ${_NEED_GNU_GREP} == "YES" && empty(PKGPATH:Mtextproc/grep)
+	${_PKG_SILENT}${_PKG_DEBUG}                             \
+	[ ! -f ${BUILDLINK_DIR}/bin/grep ] &&                    \
+	  ${LN} -fs ${LOCALBASE}/bin/${GNU_PROGRAM_PREFIX}grep \
+	  ${BUILDLINK_DIR}/bin/grep
+.elif ${_REPLACE_OPSYS_GREP} == "YES"
+	${_PKG_SILENT}${_PKG_DEBUG}                             \
+	[ ! -f ${BUILDLINK_DIR}/bin/grep ] &&                    \
+	${LN} -fs ${GREP} ${BUILDLINK_DIR}/bin/grep
+.endif
+
+gsed-buildlink: _BUILDLINK_USE
+gsed-buildlink-bin:
+.if ${_NEED_GNU_SED} == "YES" && empty(PKGPATH:Mtextproc/gsed)
+	${_PKG_SILENT}${_PKG_DEBUG}                             \
+	[ ! -f ${BUILDLINK_DIR}/bin/sed ] &&                    \
+	  ${LN} -fs ${LOCALBASE}/bin/${GNU_PROGRAM_PREFIX}sed	\
+	  ${BUILDLINK_DIR}/bin/sed
+.elif ${_REPLACE_OPSYS_SED} == "YES"
+	${_PKG_SILENT}${_PKG_DEBUG}                             \
+	[ ! -f ${BUILDLINK_DIR}/bin/sed ] &&                    \
+	${LN} -fs ${SED} ${BUILDLINK_DIR}/bin/sed
+.endif
+
+.endif	# USE_BUILDLINK2
+
+.endif	# TOOLS_MK