src_unpack

Function src_unpack
Purpose Extract source packages.
Sandbox Enabled
Privilege user
Called for ebuild

Default src_unpack

src_unpack() {
	if [[ -n ${A} ]]; then
		unpack ${A}
	fi
}

Sample src_unpack

src_unpack() {
	unpack ${P}.tar.xz
	use foo && unpack ${P}-foo-extension.tar.xz
}

Unpacking tarballs

The unpack function should be used to unpack tarballs, compressed files and so on. Do not use tar, gunzip etc. manually.

The ${A} variable contains all of the SRC_URI components, except for any which are excluded by USE-based conditionals inside SRC_URI itself. If multiple archives require unpacking in a particular order it is usually simpler to avoid working with ${A}.

Known file formats

The unpack function recognizes the following file formats:

  • *.tar
  • *.gz, *.Z, *.tar.gz, *.tgz, *.tar.Z
  • *.bz2, *.bz, *.tar.bz2, *.tbz2, *.tar.bz, *.tbz
  • *.lzma, *.tar.lzma
  • *.xz, *.tar.xz, *.txz
  • *.zip, *.ZIP, *.jar
  • *.a, *.deb

Filename extensions are matched case-insensitively.

Support for the 7-Zip (*.7z), LHA (*.lha, *.lzh) and RAR (*.rar) formats was removed in EAPI 8. Packages distributing such archives have to unpack them by other means, for which unpacker.eclass is recommended.

An argument that contains no slash names a file in ${DISTDIR}. Any other argument is treated as a path, which may be absolute or relative to the current working directory, and needs no leading ./:

unpack sub/dir/${P}-docs.tar.gz

src_unpack actions

The following subsections cover different topics which often occur when writing src_unpack functions.