tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Defaults for PKGSRCDIR and MAKECONF in pkg_chk and other tools



pkgsrc itself automatically detects the root of the pkgsrc tree, by
looking for mk/bsd.pkg.mk in ".", "..", and "../..".  However, tools
such as pkg_chk, pkg_rolling-replace, or lintpkgsrc, do not do that;
they require PKGSRCDIR to be set in the environment (or on the command
line, for some tools), failing which they default to /usr/pkgsrc.

The default to /usr/pkgsrc is almost always wrong in my case.  I would
prefer the following behaviour:

    if PKGSRCDIR is set in the environment (or command line), then use it;
    else if PKGSRCDIR is set in ${MAKECONF}, then use that;
    else if  ".", "..", or "../.." appears to be the base of a
           pkgsrc tree, then use that;
    else if /usr/pkgsrc appears to be the base of a pkgsrc tree,
           then use that;
    else error.

Also, tools that use MAKECONF are inconsistent about what default they
use if it's not set in the environment.  For example, pkg_chk has the
following behaviour:

    If MAKECONF is set in the environment, then use it;
    else if @PREFIX@/etc.mk.conf exists, then use it;
    else if /etc/mk.conf exists, then use it;
    else use /dev/null.

pkg_rolling-replace has the following behaviour:

    If MAKECONF is set in the environment, then use it;
    else if @MAKECONF@ exists, then use it;
    else use /dev/null.

I'd suggest changing them all to the following behaviour:

    If MAKECONF is set in the environment (or command line), then use it;
    else if @MAKECONF@ exists, then use it;
    else if @PREFIX/etc.mk.conf exists, then use it;
    else if /etc/mk.conf exists, then use it;
    else use /dev/null.

I append a patch for pkg_rolling-replace.  If this is OK, then I'd like to
commit it and make similar changes in other tools.

--apb (Alan Barrett)

Index: pkgtools/pkg_rolling-replace/Makefile
===================================================================
--- pkgtools/pkg_rolling-replace/Makefile       31 Mar 2008 11:41:09 -0000      
1.18
+++ pkgtools/pkg_rolling-replace/Makefile       26 Apr 2008 10:54:17 -0000
@@ -30,10 +30,16 @@
 SUBST_FILES.tools=     pkg_rolling-replace.sh
 SUBST_VARS.tools=      PKG_INFO_CMD MAKE PKG_CHK AWK
 
+SUBST_CLASSES+=                prefix
+SUBST_STAGE.prefix=    pre-configure
+SUBST_MESSAGE.prefix=  Substituting PREFIX location.
+SUBST_FILES.prefix=    pkg_rolling-replace.8
+SUBST_VARS.prefix=     PREFIX
+
 SUBST_CLASSES+=                makeconf
 SUBST_STAGE.makeconf=  pre-configure
 SUBST_MESSAGE.makeconf=        Recording default path of mk.conf.
-SUBST_FILES.makeconf=  pkg_rolling-replace.sh
+SUBST_FILES.makeconf=  pkg_rolling-replace.sh pkg_rolling-replace.8
 SUBST_SED.makeconf=    -e 
's,@MAKECONF@,${MAKE:T:Mbmake:S/bmake/${PREFIX}/g}/etc/mk.conf,g'
 
 REPLACE_SH+=           pkg_rolling-replace.sh
@@ -43,11 +49,12 @@
 # target exists only to force check-pkgsrc-patch prior to install
 do-extract: check-pkgsrc-patch
        cp ${FILESDIR}/pkg_rolling-replace.sh ${WRKSRC}
+       cp ${FILESDIR}/pkg_rolling-replace.8 ${WRKSRC}
 
 do-install: check-pkgsrc-patch
        ${INSTALL_SCRIPT} ${WRKSRC}/pkg_rolling-replace.sh \
                ${PREFIX}/sbin/pkg_rolling-replace
-       ${INSTALL_MAN} ${FILESDIR}/pkg_rolling-replace.8 \
+       ${INSTALL_MAN} ${WRKSRC}/pkg_rolling-replace.8 \
                ${PREFIX}/${PKGMANDIR}/man8/pkg_rolling-replace.8
 
 check-pkgsrc-patch:
Index: pkgtools/pkg_rolling-replace/files/pkg_rolling-replace.8
===================================================================
--- pkgtools/pkg_rolling-replace/files/pkg_rolling-replace.8    11 Mar 2008 
01:53:05 -0000      1.10
+++ pkgtools/pkg_rolling-replace/files/pkg_rolling-replace.8    26 Apr 2008 
10:54:17 -0000
@@ -1,5 +1,5 @@
 .\" $NetBSD: pkg_rolling-replace.8,v 1.10 2008/03/11 01:53:05 tnn Exp $
-.Dd March 11, 2008
+.Dd April 25, 2008
 .Dt PKG_ROLLING-REPLACE 8
 .Os
 .Sh NAME
@@ -136,15 +138,19 @@
 Path to
 .Pa mk.conf .
 Defaults to
-.Pa /etc/mk.conf
+.Pa @MAKECONF@ , @PREFIX@/etc/mk.conf ,
 or
-.Pa ${PREFIX}/etc/mk.conf
-(if using bmake).
+.Pa /etc/mk.conf .
 .It Ev PKGSRCDIR
 Base of pkgsrc tree.
-Defaults to value configured in MAKECONF or
+If not set in the environment, then this variable is read from
+.Pa ${MAKECONF} .
+If it is still not set, and if the current working directory
+appears to be inside a pkgsrc tree, then this variable
+is set to the base of that pkgsrc tree.
+Finally, if
 .Pa /usr/pkgsrc
-if unset.
+appears to contain a pkgsrc tree, then that is used as a last resort.
 .It Ev PKG_DBDIR
 pkgsrc database directory.
 If not set in environment then defaults to
Index: pkgtools/pkg_rolling-replace/files/pkg_rolling-replace.sh
===================================================================
--- pkgtools/pkg_rolling-replace/files/pkg_rolling-replace.sh   31 Mar 2008 
11:41:09 -0000      1.18
+++ pkgtools/pkg_rolling-replace/files/pkg_rolling-replace.sh   26 Apr 2008 
10:54:18 -0000
@@ -65,14 +65,37 @@
 MAKE="@MAKE@"
 AWK="@AWK@"
 
-test -z "$MAKECONF" && MAKECONF="@MAKECONF@"
+if [ -z "$MAKECONF" ] ; then
+    for mkconf in "@MAKECONF@" "@PREFIX@/etc/mk.conf" /etc/mk.conf ; do
+       if [ -f "$mkconf" ] ; then
+           MAKECONF="$mkconf"
+           break
+       fi
+    done
+fi
+if [ -z "$MAKECONF" -o ! -f "$MAKECONF" ] ; then
+    MAKECONF=/dev/null
+fi
 test -f "$MAKECONF" && test -z "$PKGSRCDIR" && PKGSRCDIR="` \
     printf '.include "%s"\n_print_pkgsrcdir:\n\t@echo "${PKGSRCDIR}"\n' \
     "$MAKECONF" | "$MAKE" -f - BSD_PKG_MK=1 _print_pkgsrcdir`"
-test -z "$PKGSRCDIR" && PKGSRCDIR=/usr/pkgsrc
+if [ -z "$PKGSRCDIR" ] ; then
+    for dir in . .. ../.. /usr/pkgsrc ; do
+       if [ -f "${dir}/mk/bsd.pkg.mk" ]; then
+           case "${dir}" in
+           /*) PKGSRCDIR="${dir}" ;;
+           *)  PKGSRCDIR="$( cd "${dir}" >/dev/null 2>&1 && pwd )" ;;
+           esac
+           break
+       fi
+    done
+fi
+test -z "$PKGSRCDIR" && echo >&2 "Please set PKGSRCDIR" && exit 1
 test -z "$PKG_CHK" && PKG_CHK="@PKG_CHK@"
 test -z "$PKG_INFO" && PKG_INFO="@PKG_INFO_CMD@"
 
+export PKGSRCDIR
+
 unset PKG_PATH || true  #or pkgsrc makefiles will complain
 
 usage()


Home | Main Index | Thread Index | Old Index