]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame_incremental - pearize.sh
on -j define __jobs instead of _smp_mflags
[packages/rpm-build-tools.git] / pearize.sh
... / ...
CommitLineData
1#!/bin/sh
2# updates php-pear .spec with Requires/Conflicts lines.
3# the items are added randomly to the preamble, but once added their order is left intact.
4# it is still better than nothing. if somebody wishes to add sorting in this
5# script. i'd be just glad :)
6#
7# needs 'pear' for 'pear make-rpm-spec' command, ./builder for fetching sources.
8# You should have all PEAR packages installed to get best results (needed for epoch autodetection)
9# So far there are 3 packages with epoch > 0:
10# $ grep ^Epoch:.* php-pear-*.spec | grep -v 'Epoch:.*0'
11# php-pear-MDB2.spec:Epoch: 1
12# php-pear-MDB.spec:Epoch: 1
13# php-pear-PEAR.spec:Epoch: 1
14#
15# To create completely new PEAR package spec, follow something like this:
16# $ pear download RDF-alpha
17# File RDF-0.1.0alpha1.tgz downloaded
18# $ pear make-rpm-spec RDF-0.1.0alpha1.tgz
19# Wrote RPM spec file php-pear-RDF.spec
20# $
21#
22# TODO: adjust similiarily noautoreqdeps
23# BUGS: the beta portions in version deps could be wrong (php-4.3.0b1 and alike)
24# see php-pear-DBA_Relational.spec
25# Something strange: Requires: php-common < 4:3:5.1
26#
27# NOTE: old version of this script which was used to convert to new package format is in CVS branch MIGRATE.
28#
29# Send blames and beer\b\b\b\bideas to glen@pld-linux.org
30
31PROGRAM=${0##*/}
32APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
33
34set -e
35spec="$1"
36if [ -z "$spec" ]; then
37 echo >&2 "Usage: $0 SPECFILE"
38 exit 0
39fi
40if [ ! -f "$spec" ]; then
41 echo >&2 "$spec doesn't exist?"
42 exit 1
43fi
44
45if [[ "$(rpm -q php-pear-PEAR_Command_Packaging)" == *is?not* ]]; then
46 echo >&2 "Please install php-pear-PEAR_Command_Packaging"
47 exit 1
48fi
49echo "Processing $spec"
50
51getsource() {
52 local spec="$1"
53 local NR="$2"
54 rpmbuild --nodigest --nosignature -bp --define 'prep %dump' $spec 2>&1 | awk "/SOURCE$NR\t/ {print \$3}"
55}
56
57tarball=$(getsource $spec 0)
58if [ -z "$tarball" ]; then
59 echo >&2 "Spec is missing Source0!"
60 exit 1
61fi
62
63if [ ! -f $tarball ]; then
64 $APPDIR/builder -g "$spec"
65fi
66
67stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
68template=pearize.spec
69cat > $stmp <<'EOF'
70@extra_headers@
71License: @release_license@
72State: @release_state@
73EOF
74pear make-rpm-spec --spec-template=$stmp --output=$template $tarball
75rm -f $stmp
76
77mv $template .$template~
78template=.$template~
79
80# take as argument dependency in form NAME EQUALITY VERSION
81# adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero.
82add_epoch() {
83 local dep="$@"
84 local pkg="$1"
85 local ver="$3"
86
87 # already have epoch
88 if [[ "$ver" = *:* ]]; then
89 echo "$dep"
90 return
91 fi
92
93 query=$(rpm -q --qf '%{epoch}\n' $pkg || :)
94 epoch=$(echo "$query" | grep -v 'installed' || :)
95 if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then
96 echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:,"
97 else
98 echo "$dep"
99 fi
100}
101
102preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
103# take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things.
104sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble
105
106# create backup
107bak=$(LC_ALL=C cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" )
108
109# ensure rpm-build-macros is present
110if ! grep -q "^BuildRequires:.*rpmbuild(macros)" $preamble; then
111 sed -i -e "/^BuildRequires:.*rpm-php-pearprov/aBuildRequires:\trpmbuild(macros) >= 1.300" $spec
112fi
113# parse requires
114requires=$(grep '^BuildRequires:' $template || :)
115if [ -n "$requires" ]; then
116 echo "$requires" | while read tag dep; do
117 dep=$(add_epoch $dep)
118 if ! grep -q "^BuildRequires:.*$dep" $preamble; then
119 sed -i -e "/^BuildRoot/iBuildRequires:\t$dep" $spec
120 fi
121 done
122fi
123
124requires=$(grep '^Requires:' $template || :)
125if [ -n "$requires" ]; then
126 echo "$requires" | while read tag dep; do
127 dep=$(add_epoch $dep)
128 if ! grep -q "^Requires:.*$dep" $preamble; then
129 dep=$(echo "$dep" | sed -e 's,php-pear-PEAR\b,php-pear-PEAR-core,')
130 sed -i -e "/^BuildRoot/iRequires:\t$dep" $spec
131 fi
132 done
133fi
134
135# parse conflicts
136conflicts=$(grep '^Conflicts:' $template || :)
137if [ -n "$conflicts" ]; then
138 echo "$conflicts" | while read tag dep; do
139 dep=$(add_epoch $dep)
140 if ! grep -q "^Conflicts:.*$req" $preamble; then
141 sed -i -e "/^BuildRoot/iConflicts:\t$dep" $spec
142 fi
143 done
144fi
145
146# parse optional deps
147optional=$(grep '^Suggests:' $template || :)
148if [ -n "$optional" ]; then
149 echo "$optional" | while read tag dep; do
150 dep=$(add_epoch $dep)
151 if ! grep -q "^Suggests:.*$dep" $preamble; then
152 sed -i -e "/^BuildRoot/iSuggests:\t$dep" $spec
153 fi
154
155 for req in $dep; do
156 case "$req" in
157 php-pear-*)
158 # convert pear package name to file pattern
159 req=$(echo "$req" | sed -e 's,^php-pear-,pear(,;y,_,/,;s,$,.*),')
160 ;;
161 *)
162 # process only php-pear-* packages
163 continue
164 ;;
165 esac
166
167 m=$(grep "^%define.*_noautoreq" $spec || :)
168 if [ -z "$m" ]; then
169 sed -i -e "/^BuildRoot:/{
170 a
171 a# exclude optional dependencies
172 a%define\ \ _noautoreq\ $req
173 }
174 " $spec
175 else
176 m=$(echo "$m" | grep -o "$req" || :)
177 if [ -z "$m" ]; then
178 sed -i -e "/^%define.*_noautoreq/s,$, $req," $spec
179 fi
180 fi
181 done
182 done
183fi
184
185optional=$(grep '^Optional-ext:' $template || :)
186if [ -n "$optional" ]; then
187 tmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
188 echo "$optional" | while read tag ext; do
189 grep -q "PHP extension .$ext" && continue
190 cat > $tmp <<-EOF
191 echo '%{name} can optionally use PHP extension "$ext"' >> optional-packages.txt
192 EOF
193 sed -i -e "
194 /%pear_package_setup/ {
195 r $tmp
196 }
197 " $spec
198 done
199 rm -f .ext.tmp
200fi
201
202has_opt=$(grep -Ec '^Optional-(pkg|ext):' $template || :)
203if [ "$has_opt" -gt 0 ]; then
204 if ! grep -q 'rpmbuild(macros)' $spec; then
205 sed -i -e '
206 /rpm-php-pearprov/{
207 aBuildRequires: rpmbuild(macros) >= 1.300
208 }
209 ' $spec
210 fi
211 if ! grep -Eq '%{_docdir}/.*/optional-packages.txt|%pear_package_print_optionalpackages' $spec; then
212 sed -i -e '
213 /^%files$/{
214 i%post -p <lua>
215 i%pear_package_print_optionalpackages
216 i
217 }
218 /rpmbuild(macros)/{
219 s/>=.*/>= 1.571/
220 }
221 ' $spec
222 fi
223 if ! grep -q '%doc.*optional-packages.txt' $spec; then
224 sed -i -e '
225 /^%doc install.log/{
226 s/$/ optional-packages.txt/
227 }
228 ' $spec
229 fi
230fi
231
232# parse state
233state=$(awk '/^State:/{print $2}' $template)
234sed -i -e "/^%define.*_\?status/{
235 s/%define[[:space:]]*_status.*/%define\t\t_status\t\t$state/
236 s/%define[[:space:]]*status.*/%define\t\tstatus\t\t$state/
237}" $spec
238
239# parse license
240#license=$(awk '/^License:/{print $2}' $template)
241#sed -i -e "s/^License:.*/License:\t$license/" $spec
242
243rm -f $preamble
244
245diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
246if ! diff -u $bak $spec > $diff; then
247 vim -o $spec $diff
248 rm -f $diff
249else
250 echo "$spec: No diffs"
251fi
This page took 0.063308 seconds and 4 git commands to generate.