Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 05 Mar 2003 23:31:10 -0500
From:      Brian Fundakowski Feldman <green@FreeBSD.org>
To:        ports@FreeBSD.org
Subject:   USE_AUTOEXTRACT option for bsd.port.mk
Message-ID:  <200303060431.h264VAjO082569@green.bikeshed.org>

next in thread | raw e-mail | index | archive | help
   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




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