/[gentoo-x86]/eclass/rpm.eclass
Gentoo

Diff of /eclass/rpm.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 Revision 1.21
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2009 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.2 2003/06/21 13:42:42 liquidx Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.21 2011/12/10 08:50:47 vapier Exp $
4 4
5# Author : Alastair Tse <liquidx@gentoo.org> (21 Jun 2003) 5# @ECLASS: rpm.eclass
6# 6# @MAINTAINER:
7# base-system@gentoo.org
7# Convienence class for extracting RPMs 8# @BLURB: convenience class for extracting RPMs
8#
9# Basically, rpm_src_unpack does:
10#
11# 1. convert all *.rpm in ${A} to tar.gz, non rpm files are passed through
12# unpack()
13# 2. unpacks the tar.gz into ${WORKDIR}
14# 3. if it is a source rpm, it finds all .tar .tar.gz, .tgz, .tbz2, .tar.bz2,
15# .zip, .ZIP and unpacks them using unpack() (with a little hackery)
16# 4. deletes all the unpacked tarballs and zip files from ${WORKDIR}
17#
18# Warning !!
19#
20# Sometimes, pure rpm2targz will fail on certain RPMs (eg: scim-chinese)
21# because their code for detecting RPM header offset is not good enough.
22# In that case, you need to add app-arch/rpm to your DEPEND. rpm2targz
23# will automatically find rpm2cpio and use it instead of its own rpmoffset.
24#
25# In addition, rpm2targz-8.0 behaves differently from rpm2targz-9.0. The newer
26# versions will autodetect rpm2cpio whereas 8.0 doesn't.
27#
28# Also, 9.0 wil# detect if it is a source rpm and place files in
29# ${prefix%.src} whereas 8.0 will just place them in the current directory.
30# As of writing, the current rpm2targz-9.0 in portage has been patched to
31# remove this behaviour for backwards compatibility.
32 9
33ECLASS="rpm" 10inherit eutils
34INHERITED="$INHERITED $ECLASS"
35 11
36newdepend ">=app-arch/rpm2targz-0.9" 12DEPEND=">=app-arch/rpm2targz-9.0.0.3g"
37 13
14# @FUNCTION: rpm_unpack
15# @USAGE: <rpms>
16# @DESCRIPTION:
17# Unpack the contents of the specified rpms like the unpack() function.
18rpm_unpack() {
19 [[ $# -eq 0 ]] && set -- ${A}
20 local a
21 for a in "$@" ; do
22 echo ">>> Unpacking ${a} to ${PWD}"
23 if [[ ${a} == ./* ]] ; then
24 : nothing to do -- path is local
25 elif [[ ${a} == ${DISTDIR}/* ]] ; then
26 ewarn 'QA: do not use ${DISTDIR} with rpm_unpack -- it is added for you'
27 elif [[ ${a} == /* ]] ; then
28 ewarn 'QA: do not use full paths with rpm_unpack -- use ./ paths instead'
29 else
30 a="${DISTDIR}/${a}"
31 fi
32 rpm2tar -O "${a}" | tar xf - || die "failure unpacking ${a}"
33 done
34}
35
36# @FUNCTION: srcrpm_unpack
37# @USAGE: <rpms>
38# @DESCRIPTION:
39# Unpack the contents of the specified rpms like the unpack() function as well
40# as any archives that it might contain. Note that the secondary archive
41# unpack isn't perfect in that it simply unpacks all archives in the working
42# directory (with the assumption that there weren't any to start with).
43srcrpm_unpack() {
44 [[ $# -eq 0 ]] && set -- ${A}
45 rpm_unpack "$@"
46
47 # no .src.rpm files, then nothing to do
48 [[ "$* " != *".src.rpm " ]] && return 0
49
50 eshopts_push -s nullglob
51
52 # unpack everything
53 local a
54 for a in *.tar.{gz,bz2} *.t{gz,bz2} *.zip *.ZIP ; do
55 unpack "./${a}"
56 rm -f "${a}"
57 done
58
59 eshopts_pop
60
61 return 0
62}
63
64# @FUNCTION: rpm_src_unpack
65# @DESCRIPTION:
66# Automatically unpack all archives in ${A} including rpms. If one of the
67# archives in a source rpm, then the sub archives will be unpacked as well.
38rpm_src_unpack() { 68rpm_src_unpack() {
39 local x prefix ext myfail OLD_DISTDIR 69 local a
40
41 for x in ${A}; do 70 for a in ${A} ; do
42 myfail="failure unpacking ${x}" 71 case ${a} in
43 ext=${x##*.} 72 *.rpm) srcrpm_unpack "${a}" ;;
44 case "$ext" in 73 *) unpack "${a}" ;;
45 rpm)
46 echo ">>> Unpacking ${x}"
47 prefix=${x%.rpm}
48 cd ${WORKDIR}
49 # convert rpm to tar.gz and then extract
50 rpm2targz ${DISTDIR}/${x} || die "${myfail}"
51 if [ "$(tar tzvf ${WORKDIR}/${prefix}.tar.gz | wc -l)" -lt 2 ]; then
52 die "rpm2targz failed, produced an empty tar.gz"
53 fi
54 tar xz --no-same-owner -f ${WORKDIR}/${prefix}.tar.gz || die "${myfail}"
55 rm -f ${WORKDIR}/${prefix}.tar.gz
56
57 # find all tar.gz files and extract for srpms
58 if [ "${prefix##*.}" = "src" ]; then
59 OLD_DISTDIR=${DISTDIR}
60 DISTDIR=${WORKDIR}
61 findopts="-name *.tar"
62 for t in *.tar.gz *.tgz *.tbz2 *.tar.bz2 *.zip *.ZIP; do
63 findopts="${findopts} -o -name ${t}"
64 done
65 for t in $(find * ${findopts} | xargs); do
66 unpack ${t}
67 rm -f ${t}
68 done
69 DISTDIR=${OLD_DISTDIR}
70 fi
71 ;;
72 *)
73 unpack ${x}
74 ;;
75 esac 74 esac
76 done 75 done
77 76}
77
78# @FUNCTION: rpm_spec_epatch
79# @USAGE: [spec]
80# @DESCRIPTION:
81# Read the specified spec (defaults to ${PN}.spec) and attempt to apply
82# all the patches listed in it. If the spec does funky things like moving
83# files around, well this won't handle that.
84rpm_spec_epatch() {
85 local p spec=$1
86 local dir
87
88 if [[ -z ${spec} ]] ; then
89 # search likely places for the spec file
90 for spec in "${PWD}" "${S}" "${WORKDIR}" ; do
91 spec+="/${PN}.spec"
92 [[ -e ${spec} ]] && break
93 done
94 fi
95 [[ ${spec} == */* ]] \
96 && dir=${spec%/*} \
97 || dir=
98
99 ebegin "Applying patches from ${spec}"
100
101 grep '^%patch' "${spec}" | \
102 while read line ; do
103 # expand the %patch line
104 set -- ${line}
105 p=$1
106 shift
107
108 # process the %patch arguments
109 local arg
110 EPATCH_OPTS=
111 for arg in "$@" ; do
112 case ${arg} in
113 -b) EPATCH_OPTS+=" --suffix" ;;
114 *) EPATCH_OPTS+=" ${arg}" ;;
115 esac
116 done
117
118 # extract the patch name from the Patch# line
119 set -- $(grep "^P${p#%p}: " "${spec}")
120 shift
121 epatch "${dir:+${dir}/}$*"
122 done
123
124 eend
78} 125}
79 126
80EXPORT_FUNCTIONS src_unpack 127EXPORT_FUNCTIONS src_unpack

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.20