Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 Mar 2003 02:31:49 +0000 (UTC)
From:      naddy@mips.inka.de (Christian Weisgerber)
To:        freebsd-ports@freebsd.org
Subject:   Re: USE_AUTOEXTRACT option for bsd.port.mk
Message-ID:  <b4bkml$1f3g$1@kemoauc.mips.inka.de>
References:  <200303060431.h264VAjO082569@green.bikeshed.org> <b4818o$1j3v$1@kemoauc.mips.inka.de> <20030306192318.GB435@rot13.obsecurity.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Kris Kennaway <kris@obsecurity.org> wrote:

> Hey, that's pretty cool.  I'd be happy with a port of this to FreeBSD.

A prototype patch is appended below.  It doesn't include any
documentation yet and is only lightly tested.

extract:
  If you define USE_AUTOEXTRACT, all EXTRACT_ONLY distfiles will
  be extracted.  The most common archive types are handled
  automagically.  If you need to add additional handlers or override
  the default ones, you can do so with EXTRACT_CASES.

  This also obsoletes several traditional variables:
  * USE_BZIP2, USE_ZIP: handled automatically
  * EXTRACT_CMD, EXTRACT_BEFORE_ARG, EXTRACT_AFTER_ARGS: superseded
    by EXTRACT_CASES.

patch:
  This transparently introduces PATCH_CASES, which works analogously
  to EXTRACT_CASES, and fixes the handling of .bz2 patch files which
  is currently broken in a subtle way.


Index: bsd.port.mk
===================================================================
RCS file: /home/pcvs/ports/Mk/bsd.port.mk,v
retrieving revision 1.441
diff -u -r1.441 bsd.port.mk
--- bsd.port.mk	2 Mar 2003 02:06:56 -0000	1.441
+++ bsd.port.mk	8 Mar 2003 02:13:15 -0000
@@ -1055,15 +1055,6 @@
 MANCOMPRESSED?=	no
 .endif
 
-.if defined(PATCHFILES)
-.if ${PATCHFILES:M*.bz2}x != x
-PATCH_DEPENDS+=		bzip2:${PORTSDIR}/archivers/bzip2
-.endif
-.if ${PATCHFILES:M*.zip}x != x
-PATCH_DEPENDS+=		unzip:${PORTSDIR}/archivers/unzip
-.endif
-.endif
-
 .if defined(USE_BZIP2) && !exists(/usr/bin/bzip2)
 EXTRACT_DEPENDS+=	bzip2:${PORTSDIR}/archivers/bzip2
 .endif
@@ -2035,6 +2026,41 @@
 #  by user.
 EXTRACT_ONLY?=	${_DISTFILES}
 
+.if defined(PATCHFILES)
+PATCH_CASES?=
+.  if !empty(PATCHFILES:M*.bz2)
+.    if !exists(/usr/bin/bzip2)
+PATCH_DEPENDS+=	bzip2:${PORTSDIR}/archivers/bzip2
+.    endif
+PATCH_CASES+= *.bz2) ${BZCAT} $$patchfile | ${PATCH} ${PATCH_DIST_ARGS};;
+.  endif
+PATCH_CASES+= *.Z|*.gz) ${GZCAT} $$patchfile | ${PATCH} ${PATCH_DIST_ARGS};;
+PATCH_CASES+= *) ${PATCH} ${PATCH_DIST_ARGS} < $$patchfile;
+.endif
+
+.if defined(USE_AUTOEXTRACT)
+EXTRACT_CASES?=
+
+_FIX_SHAR=	${AWK} '/^#! *\/bin\/sh/ || /# This is a shell archive/ { do print; while(getline) }'
+
+.  if !empty(EXTRACT_ONLY:M*.zip)
+EXTRACT_DEPENDS+=   unzip:${PORTSDIR}/archivers/unzip
+EXTRACT_CASES+= *.zip) ${UNZIP} -q ${_DISTDIR}/$$archive -d ${WRKDIR};;
+.  endif
+.  if !empty(EXTRACT_ONLY:M*.tar.bz2)
+.    if !exists(/usr/bin/bzip2)
+EXTRACT_DEPENDS+=   bzip2:${PORTSDIR}/archivers/bzip2
+.    endif
+EXTRACT_CASES+= *.tar.bz2) ${BZCAT} ${_DISTDIR}/$$archive | ${TAR} -xf -;;
+.  endif
+EXTRACT_CASES+= *.tar) ${TAR} -xf ${_DISTDIR}/$$archive;;
+EXTRACT_CASES+= *.shar.gz|*.shar.Z|*.sh.gz|*.sh.Z) ${GZCAT} ${_DISTDIR}/$$archive | ${_FIX_SHAR} | ${SH};;
+EXTRACT_CASES+= *.shar|*.sh) ${_FIX_SHAR} ${_DISTDIR}/$$archive | ${SH};;
+EXTRACT_CASES+= *.tar.gz) ${GZCAT} ${_DISTDIR}/$$archive | ${TAR} -xf -;;
+EXTRACT_CASES+= *.gz) ${GZCAT} ${_DISTDIR}/$$archive >`basename $$archive .gz`;;
+EXTRACT_CASES+= *) ${GZCAT} ${_DISTDIR}/$$archive | ${TAR} -xf -;;
+.endif	# USE_AUTOEXTRACT
+
 # Documentation
 MAINTAINER?=	ports@FreeBSD.org
 
@@ -2610,12 +2636,21 @@
 do-extract:
 	@${RM} -rf ${WRKDIR}
 	@${MKDIR} ${WRKDIR}
+.if defined(USE_AUTOEXTRACT)
+	@set -e; cd ${WRKDIR}; \
+	for archive in ${EXTRACT_ONLY}; do \
+		case $$archive in \
+			${EXTRACT_CASES} \
+		esac; \
+	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}; \
@@ -2631,20 +2666,12 @@
 .if defined(PATCHFILES)
 	@${ECHO_MSG} "===>  Applying distribution patches for ${PKGNAME}"
 	@(cd ${_DISTDIR}; \
-	  for i in ${_PATCHFILES}; do \
+	  for patchfile in ${_PATCHFILES}; do \
 		if [ ${PATCH_DEBUG_TMP} = yes ]; then \
-			${ECHO_MSG} "===>   Applying distribution patch $$i" ; \
+			${ECHO_MSG} "===>   Applying distribution patch $$patchfile" ; \
 		fi; \
-		case $$i in \
-			*.Z|*.gz) \
-				${GZCAT} $$i | ${PATCH} ${PATCH_DIST_ARGS}; \
-				;; \
-			*.bz2) \
-				${BZCAT} $$i | ${PATCH} ${PATCH_DIST_ARGS}; \
-				;; \
-			*) \
-				${PATCH} ${PATCH_DIST_ARGS} < $$i; \
-				;; \
+		case $$patchfile in \
+			${PATCH_CASES} \
 		esac; \
 	  done)
 .endif
-- 
Christian "naddy" Weisgerber                          naddy@mips.inka.de


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?b4bkml$1f3g$1>