Subject: Re: CVS commit: pkgsrc/mk
To: None <tech-pkg@NetBSD.org>
From: Johnny C. Lam <jlam@jgrind.org>
List: tech-pkg
Date: 01/21/2004 12:34:38
On Wed, Jan 21, 2004 at 08:30:35PM +0100, Thomas Klausner wrote:
> On Wed, Jan 21, 2004 at 06:13:27PM +0000, Johnny C. Lam wrote:
> > Modified Files:
> > 	pkgsrc/mk: bsd.pkg.mk bsd.prefs.mk
> > 
> > Log Message:
> > Introduce concept of the "phase" that we're in as we progress through
> > fetching, extracting, configuring, building, etc. of a package.  We
> > can check what phase we're in by examining the value of ${PKG_PHASE}
> > and comparing against PHASES_AFTER_<phase>, which list phases that
> > are "greater than or equal to" <phase>.
> > 
> > One useful example of how to use PKG_PHASE is:
> > 
> > .if !empty(PHASES_AFTER_EXTRACT:${PKG_PHASE})
> > #
> > # Some variable settings or targets here that rely on dependencies to
> > # already be installed, or ${WRKDIR} to be created, etc., as these are
> > # things that should have happened by the time "make extract" is
> > # completed.
> > #
> > .endif
> 
> What does this fix? In particular, this sounds like something normal
> Makefile dependencies should be able to handle.

Revision 1.54 of pkgsrc/mk/buildlink3/bsd.buildlink.mk contains an
example:

.if !empty(PHASES_AFTER_BUILDLINK:M${PKG_PHASE})
...
# Resolve the path to ${WRKDIR} completely in case it's a symlink.
.if !defined(_BLNK_WRKDIR)
_BLNK_WRKDIR!=  if [ -d ${WRKDIR} ]; then                               \
                        cd ${WRKDIR}; ${PWD_CMD};                       \
                else                                                    \
                        ${ECHO} ${WRKDIR};                              \
                fi
MAKEFLAGS+=     _BLNK_WRKDIR="${_BLNK_WRKDIR}"
.endif
...
.endif # PHASES_AFTER_BUILDLINK

The computation of the value of _BLNK_WRKDIR should actually be
tightened up to just:

_BLNK_WRKDIR!=	cd ${WRKDIR}; ${PWD_CMD}

It's not possible to get the value of this variable at all times since
${WRKDIR} doesn't exist until the package has been extracted.  However,
_BLNK_WRKDIR needs to be used by other make(1) variable definitions, so
it needs to be computed some time after "make extract" has been done.
By wrapping the definition in a section that is only available for
"buildlink-or-later" targets, we can solve this difficulty.  To
summarize, the important new ability gained is the ability to set a
variable at a particular time during the package build process.

I plan on using PKG_PHASE to simplify a lot of the buildlink3 code.  It
can also be used to optimize the Makefile parsing performed by make(1)
by switching on or off whole sections of bsd.pkg.mk that are relevant
for specific phases of the package build.

	Cheers,

	-- Johnny Lam <jlam@jgrind.org>