Subject: bsd.pkg.mk proposal 3: flexible extract handling
To: None <tech-pkg@netbsd.org>
From: Todd Vierling <tv@pobox.com>
List: tech-pkg
Date: 05/21/1999 12:05:03
Comments, please.

=====

$Revision: 1.1 $

This proposal defines the following replacement for the handling of
extraction of distfiles.  These changes depend on proposal 1, recursive make
overhaul, to prevent executing the evaluation code several times.

Each distfile listed in ${DISTFILES} will be extracted based on file
extension.  bsd.pkg.mk will define the following (which may be expanded into
a larger list of extensions in a later draft of this proposal).

DECOMPRESS_CMD.Z ?=	${ZCAT} @DISTFILE@
DECOMPRESS_CMD.gz ?=	${GZCAT} @DISTFILE@
DECOMPRESS_CMD.bz2 ?=	bzcat @DISTFILE@

DECOMPRESS_CMD_gz ?=	${DECOMPRESS_CMD.gz}

.if defined(EXTRACT_USING_PAX)
EXTRACT_CMD.tar ?=	@DECOMPRESS@ | ${PAX} -r ${EXTRACT_ELEMENTS}
.else
EXTRACT_CMD.tar ?=	@DECOMPRESS@ | /usr/bin/tar xf - ${EXTRACT_ELEMENTS}
.endif
EXTRACT_CMD.zip ?=	unzip -Loq @DISTFILE@ ${EXTRACT_ELEMENTS}
EXTRACT_CMD.cpio ?=	@DECOMPRESS@ | ${CPIO} -i ${EXTRACT_ELEMENTS}
EXTRACT_CMD.shar ?=	@DECOMPRESS@ | ${SH}

EXTRACT_CMD.tgz ?=	${EXTRACT_CMD.tar:S/@DECOMPRESS@/${DECOMPRESS_CMD.gz}/}
EXTRACT_CMD.taz ?=	${EXTRACT_CMD.tar:S/@DECOMPRESS@/${DECOMPRESS_CMD.Z}/}

DECOMPRESS_DEP.bz2 ?=	bzcat:${PKGSRCDIR}/archivers/bzip
EXTRACT_DEP.zip ?=	unzip:${PKGSRCDIR}/archivers/unzip

DECOMPRESS_EXTS +=	.Z .gz .bz2 _gz
EXTRACT_EXTS +=		.tar .shar .cpio .zip .tgz .taz

EXTRACT_ONLY ?= ${DISTFILES}
EXTRACT_CMDS = ${DO_NADA} # begin list of extract commands

.for _file_ in ${DISTFILES}
.if ${EXTRACT_ONLY:M${_file_}} != ""

_dfile_ := ${_file_}
_decomp_ := ${CAT} ${_file_}

.for _ext_ in ${DECOMPRESS_EXTS}
.if ${_dfile_:M*${_ext_}} != ""
_decomp_ := ${DECOMPRESS_CMD${_ext_}:S/@DISTFILE@/${_DISTDIR}\/${_file_}/}
BUILD_DEPENDS += ${DECOMPRESS_DEP${_ext_}}
_dfile_ := ${_dfile_:S/${_ext_}$//}
.endif
.endfor

_extract_ := ${_decomp_} > ${WRKDIR}/${_dfile_}

.for _ext_ in ${EXTRACT_EXTS}
.if ${_dfile_:M*${_ext_}} != ""
_extract_ := ${EXTRACT_CMD${_ext_}:S/@DECOMPRESS@/${_decomp_}/:S/@DISTFILE@/${_DISTDIR}\/${_file_}/}
BUILD_DEPENDS += ${EXTRACT_DEP${_ext_}}
.endif
.endfor

EXTRACT_CMDS := ${_extract_} && ${EXTRACT_CMDS}

.endif
.endfor

-----

In the above, EXTRACT_CMDS will be set to a list of commands, separated by
&&, which will be run as part of the default "do-install" rule.  Files which
have unrecognized extensions will default to a copy (using "cat").  A
Makefile may define additional/replacement EXTRACT_CMD/DECOMPRESS_CMD
entries, though ones with global usefulness should appear in bsd.pkg.mk.

Note the following variable changes:

- EXTRACT_CMD is gone.  Special extractions must be done using either
  "post-extract" or a custom EXTRACT_CMD.ext rule.

- EXTRACT_SUFX is gone.  Makefiles which used this to determine a value to
  place in ${DISTFILES} should use ${DISTNAME}.ext instead.

- EXTRACT_ONLY still exists, and defaults to ${DISTFILES}.  This logic
  could, as a modification to this proposal, be inverted, but would need
  a name other than NO_EXTRACT (as that is already in use).

=====

-- 
-- Todd Vierling (Personal tv@pobox.com; Bus. todd_vierling@xn.xerox.com)