Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 06 Mar 2003 17:30:15 -0500
From:      "Brian F. Feldman" <green@FreeBSD.org>
To:        Kris Kennaway <kris@obsecurity.org>
Cc:        ports@FreeBSD.org
Subject:   Re: USE_AUTOEXTRACT option for bsd.port.mk 
Message-ID:  <200303062230.h26MUFXB042748@green.bikeshed.org>
In-Reply-To: Your message of "Wed, 05 Mar 2003 23:46:09 PST." <20030306074609.GA95008@rot13.obsecurity.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
Kris Kennaway <kris@obsecurity.org> wrote:
> Interesting idea..taking this a bit further, I would assume that the
> number of ports with a non-standard "extension" is fairly small
> (i.e. most port distfiles that end in .tar.gz are a gzipped tarball :)
> Would it be worthwhile to turn this on its head and automatically
> figure out how to extract all ports, except for the nonstandard ones?
> Of course, then we'd be left with the negative problem of how to
> specify the extraction method for those.  Would this add any
> measurable performance penalty?
>
> I don't know..someone would need to perform tests.

How about this revision?  It should do it how you say, except of course in 
very odd cases.  It should save a line or so in probably half of the 
Makefiles.  Do you have a list of EVERY distfile, and statistics on their 
extensions?  I imagine so, so I'd be interested in stats before determining 
a good way to test the performance :)  I got rid of the expr since I forgot 
I could almost as easily use a case statement, so without external commands 
it truly shouldn't be any slower.

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	6 Mar 2003 22:03:56 -0000
@@ -149,6 +149,7 @@
 # convention these should be set to 'yes', although they only need to be
 # defined.
 #
+# USE_GZIP		- Says that the port tarballs use gzip for compression.
 # USE_BZIP2		- Says that the port tarballs use bzip2, not gzip, for
 #				  compression.
 # USE_ZIP		- Says that the port distfile uses zip, not tar w/[bg]zip
@@ -446,7 +447,7 @@
 #
 # EXTRACT_CMD	- Command for extracting archive (default: "bzip2" if
 #				  USE_BZIP2 is set, "unzip" if USE_ZIP is set, "gzip" 
-#				  otherwise).
+#				  if USE_GZIP is set, and automatically chosen otherwise).
 # EXTRACT_BEFORE_ARGS -
 #				  Arguments to ${EXTRACT_CMD} before filename
 #				  (default: "-dc").
@@ -752,6 +753,9 @@
 EXTRACT_SUFX?=			.zip
 .else
 EXTRACT_SUFX?=			.tar.gz
+.if !defined(USE_GZIP)
+USE_AUTOEXTRACT= yes
+.endif
 .endif
 PACKAGES?=		${PORTSDIR}/packages
 TEMPLATES?=		${PORTSDIR}/Templates
@@ -942,10 +946,10 @@
 .endif
 .endif
 
-.if (defined(USE_BZIP2) || defined(HAVE_BZIP2_PATCHES)) && !exists(/usr/bin/bzip2)
+.if (defined(USE_BZIP2) || defined(HAVE_BZIP2_PATCHES) || defined(USE_AUTOEXTRACT)) && !exists(/usr/bin/bzip2)
 BUILD_DEPENDS+=		bzip2:${PORTSDIR}/archivers/bzip2
 .endif
-.if defined(USE_ZIP)
+.if defined(USE_ZIP) || defined(USE_AUTOEXTRACT)
 BUILD_DEPENDS+=		unzip:${PORTSDIR}/archivers/unzip
 .endif
 .if defined(USE_GMAKE)
@@ -1364,7 +1368,15 @@
 .endif
 
 # EXTRACT_SUFX is defined in .pre.mk section
-.if defined(USE_ZIP)
+.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}
+.elif defined(USE_ZIP)
 EXTRACT_CMD?=			unzip
 EXTRACT_BEFORE_ARGS?=	-q
 EXTRACT_AFTER_ARGS?=	-d ${WRKDIR}
@@ -2485,12 +2497,34 @@
 do-extract:
 	@${RM} -rf ${WRKDIR}
 	@${MKDIR} ${WRKDIR}
+.if defined(USE_AUTOEXTRACT)
+	@for file in ${EXTRACT_ONLY}; do \
+		if ! (cd ${WRKDIR} && \
+			case "$$file" in \
+			*.[Zz][Ii][Pp]) \
+				${UNZIP_EXTRACT_CMD} ${UNZIP_EXTRACT_BEFORE_ARGS} ${_DISTDIR}/$$file ${UNZIP_EXTRACT_AFTER_ARGS};; \
+			*.tbz2|*.tbz|*.tar.bz2|*.tar.bz) \
+				${BZIP2_EXTRACT_CMD} ${TAR_EXTRACT_BEFORE_ARGS} ${_DISTDIR}/$$file ${TAR_EXTRACT_AFTER_ARGS};; \
+			*.tgz|*.taz|*.tar.gz|*.tar.Z) \
+				${GZIP_EXTRACT_CMD} ${TAR_EXTRACT_BEFORE_ARGS} ${_DISTDIR}/$$file ${TAR_EXTRACT_AFTER_ARGS};; \
+			*) \
+				${ECHO_MSG} ">> \"$$file\" file suffix unrecognized."; \
+				${ECHO_MSG} ">> Auto-extraction failed - please specify an archive type."; \
+				false;; \
+			esac \
+		); \
+		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
 .if !defined(EXTRACT_PRESERVE_OWNERSHIP)
 	@if [ `id -u` = 0 ]; then \
 		${CHMOD} -R ug-s ${WRKDIR}; \


-- 
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200303062230.h26MUFXB042748>