From owner-freebsd-ports Wed Mar 5 20:31:14 2003 Delivered-To: freebsd-ports@freebsd.org Received: from green.bikeshed.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 984C137B401 for ; Wed, 5 Mar 2003 20:31:11 -0800 (PST) Received: from green.bikeshed.org (ksrtpykigx6eoudq@green.bikeshed.org [10.0.0.1] (may be forged)) by green.bikeshed.org (8.12.7/8.12.6) with ESMTP id h264VA97082573 for ; Wed, 5 Mar 2003 23:31:11 -0500 (EST) (envelope-from green@green.bikeshed.org) Received: from localhost (green@localhost) by green.bikeshed.org (8.12.7/8.12.6/Submit) with ESMTP id h264VAjO082569 for ; Wed, 5 Mar 2003 23:31:10 -0500 (EST) Message-Id: <200303060431.h264VAjO082569@green.bikeshed.org> X-Mailer: exmh version 2.5 07/13/2001 with nmh-1.0.4 To: ports@FreeBSD.org Subject: USE_AUTOEXTRACT option for bsd.port.mk From: Brian Fundakowski Feldman Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 05 Mar 2003 23:31:10 -0500 Sender: owner-freebsd-ports@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org I have a need to extract both tar.gz and zip files (one source tarball and one patchset) in a port a created for jdk 1.4.1, but there's no good way to be able to extract both of them, but I don't think it's very clean to have a do-extract target when the existing extract targets work fine, but not for more than one archive at once. I implemented a USE_AUTOEXTRACT option which extracts files just like normal, except it would use the suffix to determine the extraction method, and thus be able to support more than one distribution file format in the same port without any further work by the port maintainer. Am I nutty for thinking of it, or is it possibly a good idea? Another would be something like the MASTER_SITES_N and a suffix for "archive type", but that's getting much more complicated :-) Here's my implementation. Obviously, it could be improved by people who have better ideas on how to do it, but I'd like to know if it looks nice conceptually. Thanks, everybody! Index: bsd.port.mk =================================================================== RCS file: /usr2/ncvs/ports/Mk/bsd.port.mk,v retrieving revision 1.440 diff -u -r1.440 bsd.port.mk --- bsd.port.mk 16 Feb 2003 21:22:15 -0000 1.440 +++ bsd.port.mk 1 Mar 2003 02:25:23 -0000 @@ -1377,6 +1377,15 @@ EXTRACT_CMD?= ${GZIP_CMD} .endif .endif +.if defined(USE_AUTOEXTRACT) +UNZIP_EXTRACT_CMD?= unzip +UNZIP_EXTRACT_BEFORE_ARGS?= -q +UNZIP_EXTRACT_AFTER_ARGS?= -d ${WRKDIR} +TAR_EXTRACT_BEFORE_ARGS?= -dc +TAR_EXTRACT_AFTER_ARGS?= | ${TAR} -xf - +BZIP2_EXTRACT_CMD?= ${BZIP2_CMD} +GZIP_EXTRACT_CMD?= ${GZIP_CMD} +.endif # Figure out where the local mtree file is .if !defined(MTREE_FILE) && !defined(NO_MTREE) @@ -2485,12 +2494,29 @@ do-extract: @${RM} -rf ${WRKDIR} @${MKDIR} ${WRKDIR} +.if defined(USE_AUTOEXTRACT) + @for file in ${EXTRACT_ONLY}; do \ + if ! (cd ${WRKDIR} && \ + if ${EXPR} "$$file" : '.*\.zip' >/dev/null; then \ + ${UNZIP_EXTRACT_CMD} ${UNZIP_EXTRACT_BEFORE_ARGS} ${_DISTDIR}/$$file ${UNZIP_EXTRACT_AFTER_ARGS}; \ + elif ${EXPR} "$$file" : '.*bz2\{0,1\}' >/dev/null; then \ + ${BZIP2_EXTRACT_CMD} ${TAR_EXTRACT_BEFORE_ARGS} ${_DISTDIR}/$$file ${TAR_EXTRACT_AFTER_ARGS}; \ + else \ + ${GZIP_EXTRACT_CMD} ${TAR_EXTRACT_BEFORE_ARGS} ${_DISTDIR}/$$file ${TAR_EXTRACT_AFTER_ARGS}; \ + fi \ + ); \ + then \ + exit 1; \ + fi \ + done +.else @for file in ${EXTRACT_ONLY}; do \ if ! (cd ${WRKDIR} && ${EXTRACT_CMD} ${EXTRACT_BEFORE_ARGS} ${_DISTDIR}/$$file ${EXTRACT_AFTER_ARGS});\ then \ exit 1; \ fi \ done +.endif -- Brian Fundakowski Feldman \'[ FreeBSD ]''''''''''\ <> green@FreeBSD.org \ The Power to Serve! \ Opinions expressed are my own. \,,,,,,,,,,,,,,,,,,,,,,\ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message