toolchain.eclass: fix ada build with lto
[gentoo.git] / eclass / rpm.eclass
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: rpm.eclass
5 # @MAINTAINER:
6 # base-system@gentoo.org
7 # @BLURB: convenience class for extracting RPMs
8
9 inherit estack eutils
10
11 DEPEND=">=app-arch/rpm2targz-9.0.0.3g"
12
13 # @FUNCTION: rpm_unpack
14 # @USAGE: <rpms>
15 # @DESCRIPTION:
16 # Unpack the contents of the specified rpms like the unpack() function.
17 rpm_unpack() {
18         [[ $# -eq 0 ]] && set -- ${A}
19         local a
20         for a in "$@" ; do
21                 echo ">>> Unpacking ${a} to ${PWD}"
22                 if [[ ${a} == ./* ]] ; then
23                         : nothing to do -- path is local
24                 elif [[ ${a} == ${DISTDIR}/* ]] ; then
25                         ewarn 'QA: do not use ${DISTDIR} with rpm_unpack -- it is added for you'
26                 elif [[ ${a} == /* ]] ; then
27                         ewarn 'QA: do not use full paths with rpm_unpack -- use ./ paths instead'
28                 else
29                         a="${DISTDIR}/${a}"
30                 fi
31                 rpm2tar -O "${a}" | tar xf - || die "failure unpacking ${a}"
32         done
33 }
34
35 # @FUNCTION: srcrpm_unpack
36 # @USAGE: <rpms>
37 # @DESCRIPTION:
38 # Unpack the contents of the specified rpms like the unpack() function as well
39 # as any archives that it might contain.  Note that the secondary archive
40 # unpack isn't perfect in that it simply unpacks all archives in the working
41 # directory (with the assumption that there weren't any to start with).
42 srcrpm_unpack() {
43         [[ $# -eq 0 ]] && set -- ${A}
44         rpm_unpack "$@"
45
46         # no .src.rpm files, then nothing to do
47         [[ "$* " != *".src.rpm " ]] && return 0
48
49         eshopts_push -s nullglob
50
51         # unpack everything
52         local a
53         for a in *.tar.{gz,bz2,xz} *.t{gz,bz2,xz,pxz} *.zip *.ZIP ; do
54                 unpack "./${a}"
55                 rm -f "${a}"
56         done
57
58         eshopts_pop
59
60         return 0
61 }
62
63 # @FUNCTION: rpm_src_unpack
64 # @DESCRIPTION:
65 # Automatically unpack all archives in ${A} including rpms.  If one of the
66 # archives in a source rpm, then the sub archives will be unpacked as well.
67 rpm_src_unpack() {
68         local a
69         for a in ${A} ; do
70                 case ${a} in
71                 *.rpm) srcrpm_unpack "${a}" ;;
72                 *)     unpack "${a}" ;;
73                 esac
74         done
75 }
76
77 # @FUNCTION: rpm_spec_epatch
78 # @USAGE: [spec]
79 # @DESCRIPTION:
80 # Read the specified spec (defaults to ${PN}.spec) and attempt to apply
81 # all the patches listed in it.  If the spec does funky things like moving
82 # files around, well this won't handle that.
83 rpm_spec_epatch() {
84         local p spec=$1
85         local dir
86
87         if [[ -z ${spec} ]] ; then
88                 # search likely places for the spec file
89                 for spec in "${PWD}" "${S}" "${WORKDIR}" ; do
90                         spec+="/${PN}.spec"
91                         [[ -e ${spec} ]] && break
92                 done
93         fi
94         [[ ${spec} == */* ]] \
95                 && dir=${spec%/*} \
96                 || dir=
97
98         ebegin "Applying patches from ${spec}"
99
100         grep '^%patch' "${spec}" | \
101         while read line ; do
102                 # expand the %patch line
103                 set -- ${line}
104                 p=$1
105                 shift
106
107                 # process the %patch arguments
108                 local arg
109                 EPATCH_OPTS=
110                 for arg in "$@" ; do
111                         case ${arg} in
112                         -b) EPATCH_OPTS+=" --suffix" ;;
113                         *)  EPATCH_OPTS+=" ${arg}" ;;
114                         esac
115                 done
116
117                 # extract the patch name from the Patch# line
118                 set -- $(grep "^P${p#%p}: " "${spec}")
119                 shift
120                 epatch "${dir:+${dir}/}$*"
121         done
122
123         eend
124 }
125
126 EXPORT_FUNCTIONS src_unpack