1 # $NetBSD: bsd.pkg.extract.mk,v 1.12 2005/08/21 07:29:48 rillig Exp $
3 # This Makefile fragment is included to bsd.pkg.mk and defines the
4 # relevant variables and targets for the "extract" phase.
6 # The following variables may be set by the package Makefile and
7 # specify how extraction happens:
9 # EXTRACT_ONLY is a list of distfiles relative to ${_DISTDIR} to
10 # extract and defaults to ${DISTFILES}.
12 # EXTRACT_SUFX is the suffix for the default distfile to be
13 # extracted. The default suffix is ".tar.gz".
15 # EXTRACT_CMD is a shell command list that extracts the contents of
16 # an archive named by the shell variable "extract_file" based on
17 # the extension of the archive. The extensions understood by
18 # EXTRACT_CMD are listed in _EXTRACT_SUFFIXES.
20 # EXTRACT_CMD.<sufx> is a shell command list that extracts the
21 # contents of an archive named by the shell variable "extract_file"
22 # that ends in <sufx>.
24 # EXTRACT_USING specifies the tool used to extract tar/ustar-format
25 # archives. The possible values are "gtar", "nbtar", and "pax".
26 # By default, we use the "nbtar" tool (NetBSD's pax-as-tar).
28 # EXTRACT_ELEMENTS is a list of files within the distfile to extract.
29 # This variable only takes effect for distfiles that are tarballs.
30 # By default, this is empty, which causes all files within the
31 # tarball to be extracted.
33 # The following targets are defined by bsd.pkg.extract.mk:
35 # do-extract is the target that causes the actual extraction of
36 # the distfiles to occur during the "extract" phase.
39 EXTRACT_ONLY?= ${DISTFILES}
40 EXTRACT_SUFX?= .tar.gz
43 _EXTRACT_SUFFIXES= .tar.gz .tgz .tar.bz2 .tbz .tbz2 .tar.Z .tar _tar.gz
44 _EXTRACT_SUFFIXES+= .shar.gz .shar.bz2 .shar.Z .shar
45 _EXTRACT_SUFFIXES+= .zip
46 _EXTRACT_SUFFIXES+= .lha .lzh
47 _EXTRACT_SUFFIXES+= .Z .bz2 .gz
48 _EXTRACT_SUFFIXES+= .zoo
49 _EXTRACT_SUFFIXES+= .bin
50 _EXTRACT_SUFFIXES+= .rar
52 _EXTRACT_PATTERNS= ${EXTRACT_ONLY} ${EXTRACT_SUFX}
54 .if !empty(_EXTRACT_PATTERNS:M*.tar) || \
55 !empty(_EXTRACT_PATTERNS:M*.tar.*) || \
56 !empty(_EXTRACT_PATTERNS:M*.tbz) || \
57 !empty(_EXTRACT_PATTERNS:M*.tbz2) || \
58 !empty(_EXTRACT_PATTERNS:M*.tgz) || \
59 !empty(_EXTRACT_PATTERNS:M*_tar.gz)
61 . if !empty(EXTRACT_USING:Mgtar)
63 . elif !empty(EXTRACT_USING:Mnbtar)
69 .if !empty(_EXTRACT_PATTERNS:M*.bz2) || \
70 !empty(_EXTRACT_PATTERNS:M*.tbz) || \
71 !empty(_EXTRACT_PATTERNS:M*.tbz2)
74 .if !empty(_EXTRACT_PATTERNS:M*.zip)
77 .if !empty(_EXTRACT_PATTERNS:M*.lzh) || \
78 !empty(_EXTRACT_PATTERNS:M*.lha)
81 .if !empty(_EXTRACT_PATTERNS:M*.gz) || \
82 !empty(_EXTRACT_PATTERNS:M*.tgz) || \
83 !empty(_EXTRACT_PATTERNS:M*.Z)
86 .if !empty(_EXTRACT_PATTERNS:M*.zoo)
89 .if !empty(_EXTRACT_PATTERNS:M*.rar)
93 DECOMPRESS_CMD.tar.gz?= ${GZCAT}
94 DECOMPRESS_CMD.tgz?= ${DECOMPRESS_CMD.tar.gz}
95 DECOMPRESS_CMD.tar.bz2?= ${BZCAT}
96 DECOMPRESS_CMD.tbz?= ${DECOMPRESS_CMD.tar.bz2}
97 DECOMPRESS_CMD.tbz2?= ${DECOMPRESS_CMD.tar.bz2}
98 DECOMPRESS_CMD.tar.Z?= ${GZCAT}
99 DECOMPRESS_CMD.tar?= ${CAT}
101 DECOMPRESS_CMD.shar.gz?= ${GZCAT}
102 DECOMPRESS_CMD.shar.bz2?= ${BZCAT}
103 DECOMPRESS_CMD.shar.Z?= ${GZCAT}
104 DECOMPRESS_CMD.shar?= ${CAT}
106 DECOMPRESS_CMD.Z?= ${GZCAT}
107 DECOMPRESS_CMD.bz2?= ${BZCAT}
108 DECOMPRESS_CMD.gz?= ${GZCAT}
110 DECOMPRESS_CMD?= ${GZCAT}
111 .for __suffix__ in ${_EXTRACT_SUFFIXES}
112 . if !defined(DECOMPRESS_CMD${__suffix__})
113 DECOMPRESS_CMD${__suffix__}?= ${DECOMPRESS_CMD}
117 # If this is empty, then everything gets extracted.
118 EXTRACT_ELEMENTS?= # empty
120 DOWNLOADED_DISTFILE= $${extract_file}
122 EXTRACT_CMD.zip?= ${UNZIP} ${EXTRACT_CMD_OPTS.zip} $${extract_file}
123 EXTRACT_CMD_OPTS.zip?= -Laqo
124 EXTRACT_CMD.lha?= ${LHA} ${EXTRACT_CMD_OPTS.lha} $${extract_file}
125 EXTRACT_CMD_OPTS.lha?= xq
126 EXTRACT_CMD.lzh?= ${EXTRACT_CMD.lha}
127 EXTRACT_CMD_OPTS.lzh?= ${EXTRACT_CMD_OPTS.lha}
128 EXTRACT_CMD.zoo?= ${UNZOO} ${EXTRACT_CMD_OPTS.zoo} $${extract_file}
129 EXTRACT_CMD_OPTS.zoo?= -x
130 EXTRACT_CMD.rar?= ${UNRAR} ${EXTRACT_CMD_OPTS.rar} $${extract_file}
131 EXTRACT_CMD_OPTS.rar?= x -inul
132 EXTRACT_ENV.bin?= # empty
133 EXTRACT_CMD.bin?= ${ECHO} yes | ${SETENV} ${EXTRACT_ENV.bin} $${extract_file} ${EXTRACT_CMD_OPTS.bin} >/dev/null
135 .for __suffix__ in .gz .bz2 .Z
136 EXTRACT_CMD${__suffix__}?= ${DECOMPRESS_CMD${__suffix__}} $${extract_file} > `${BASENAME} $${extract_file} ${__suffix__}`
139 .for __suffix__ in .shar.gz .shar.bz2 .shar.Z .shar
140 EXTRACT_CMD${__suffix__}?= ${DECOMPRESS_CMD${__suffix__}} $${extract_file} | ${SH}
143 .if !empty(EXTRACT_USING:Mgtar)
144 _DFLT_EXTRACT_CMD?= ${DECOMPRESS_CMD} $${extract_file} | ${GTAR} -xf - ${EXTRACT_ELEMENTS}
145 .elif !empty(EXTRACT_USING:Mnbtar)
146 _DFLT_EXTRACT_CMD?= ${DECOMPRESS_CMD} $${extract_file} | ${TAR} -xf - ${EXTRACT_ELEMENTS}
148 _DFLT_EXTRACT_CMD?= ${DECOMPRESS_CMD} $${extract_file} | ${PAX} -O -r ${EXTRACT_ELEMENTS}
151 .for __suffix__ in ${_EXTRACT_SUFFIXES}
152 . if !defined(EXTRACT_CMD${__suffix__})
153 . if !empty(EXTRACT_USING:Mgtar)
154 EXTRACT_CMD${__suffix__}?= ${DECOMPRESS_CMD${__suffix__}} $${extract_file} | ${GTAR} ${EXTRACT_CMD_OPTS${__suffix__}} -xf - ${EXTRACT_ELEMENTS}
155 . elif !empty(EXTRACT_USING:Mnbtar)
156 EXTRACT_CMD${__suffix__}?= ${DECOMPRESS_CMD${__suffix__}} $${extract_file} | ${TAR} ${EXTRACT_CMD_OPTS${__suffix__}} -xf - ${EXTRACT_ELEMENTS}
158 EXTRACT_CMD${__suffix__}?= ${DECOMPRESS_CMD${__suffix__}} $${extract_file} | ${PAX} ${EXTRACT_CMD_OPTS${__suffix__}} -O -r ${EXTRACT_ELEMENTS}
163 # _SHELL_EXTRACT is a "subroutine" for extracting an archive. It extracts
164 # the contents of archive named by the shell variable "extract_file" based
165 # on the file extension of the archive.
167 _SHELL_EXTRACT= case $${extract_file} in
168 .for __suffix__ in ${_EXTRACT_SUFFIXES}
169 _SHELL_EXTRACT+= *${__suffix__}) ${EXTRACT_CMD${__suffix__}} ;;
171 _SHELL_EXTRACT+= *) ${_DFLT_EXTRACT_CMD} ;;
172 _SHELL_EXTRACT+= esac
174 EXTRACT_CMD?= ${_SHELL_EXTRACT}
177 .if !target(do-extract)
178 do-extract: ${WRKDIR}
179 . for __file__ in ${EXTRACT_ONLY}
180 ${_PKG_SILENT}${_PKG_DEBUG} \
181 extract_file="${_DISTDIR}/${__file__}"; export extract_file; \
182 cd ${WRKDIR}; ${EXTRACT_CMD}