]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - pearize.sh
- helper
[packages/rpm-build-tools.git] / pearize.sh
index e2642af9e3a7220b80f59c6b6fb1d762ca1ae4e7..2d8ad944adbbbaadd8a7de5a0e02aa6a49e168b1 100644 (file)
@@ -4,17 +4,24 @@
 # it is still better than nothing. if somebody wishes to add sorting in this
 # script. i'd be just glad :)
 #
-# needs pear makerpm command.
-# requires tarball to exist in ../SOURCES.
-# you should have all pear packages installed to get best results
+# needs 'pear' for 'pear make-rpm-spec' command, ./builder for fetching sources.
+# You should have all PEAR packages installed to get best results (needed for epoch autodetection)
 #
-# todo: adjust similiarily noautoreqdeps
-# bugs: the beta portions in version deps could be wrong (php-4.3.0b1 and alike)
+# To create completely new PEAR package spec, follow something like this:
+# $ pear download RDF-alpha
+# File RDF-0.1.0alpha1.tgz downloaded
+# $ pear make-rpm-spec RDF-0.1.0alpha1.tgz
+# Wrote RPM spec file php-pear-RDF.spec
+# $
+#
+# TODO: adjust similiarily noautoreqdeps
+# BUGS: the beta portions in version deps could be wrong (php-4.3.0b1 and alike)
 # see php-pear-DBA_Relational.spec
-# SOmething strange: Requires: php-common < 4:3:5.1
+# Something strange: Requires: php-common < 4:3:5.1
+#
+# NOTE: old version of this script which was used to convert to new package format is in CVS branch MIGRATE.
 #
-# note: old version pf this script which was used to convert to new package format is in CVS branch MIGRATE
-# send blames and beer\b\b\b\bideas to glen@pld-linux.org
+# Send blames and beer\b\b\b\bideas to glen@pld-linux.org
 
 set -e
 spec="$1"
@@ -26,24 +33,42 @@ if [ ! -f "$spec" ]; then
        echo >&2 "$spec doesn't exist?"
        exit 1
 fi
+
+if [[ "$(rpm -q php-pear-PEAR_Command_Packaging)" == *is?not* ]]; then
+       echo >&2 "Please install php-pear-PEAR_Command_Packaging"
+       exit 1
+fi
 echo "Processing $spec"
 
-rc=$(awk '/^%define.*_rc/{print $NF}' $spec)
-pre=$(awk '/^%define.*_pre/{print $NF}' $spec)
-beta=$(awk '/^%define.*_beta/{print $NF}' $spec)
-tarball=$(rpm -q --qf "../SOURCES/%{name}-%{version}$rc$pre$beta.tgz\n" --specfile "$spec" | head -n 1 | sed -e 's,php-pear-,,')
+getsource() {
+       local spec="$1"
+       local NR="$2"
+       rpmbuild --nodigest --nosignature -bp --define 'prep %dump' $spec 2>&1 | awk  "/SOURCE$NR\t/ {print \$3}"
+}
+
+tarball=$(getsource $spec 0)
+if [ -z "$tarball" ]; then
+       echo >&2 "Spec is missing Source0!"
+       exit 1
+fi
+
+if [ ! -f $tarball ]; then
+       ./builder -g "$spec"
+fi
 
 stmp=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
 cat > $stmp <<'EOF'
 @extra_headers@
 Optional: @optional@
+@optional-pkg@
+@optional-ext@
 License: @release_license@
 State: @release_state@
 EOF
-pear makerpm --spec-template=$stmp $tarball
+pear make-rpm-spec --spec-template=$stmp --output=pearize.spec $tarball
+template=pearize.spec
 rm -f $stmp
 
-template=$(rpm -q --qf "%{name}-%{version}$rc$pre$beta.spec\n" --specfile "$spec" | head -n 1)
 mv $template .$template~
 template=.$template~
 
@@ -103,13 +128,44 @@ optional=$(grep '^Optional:' $template || :)
 if [ -n "$optional" ]; then
        echo "$optional" | while read tag dep; do
                for req in $dep; do
-                       m=$(grep "^%define.*_noautoreq" $spec | fgrep -o "$req" || :)
+                       m=$(grep "^%define.*_noautoreq" $spec || :)
                        if [ -z "$m" ]; then
-                               sed -i -e "/^%define.*_noautoreq/s/$/ $req/" $spec
+                               sed -i -e "/^BuildRoot:/{
+                                       a
+                                       a# exclude optional dependencies
+                                       a%define\       \       _noautoreq\     $req
+                               }
+                               " $spec
+                       else
+                               m=$(echo "$m" | grep -o "$req" || :)
+                               if [ -z "$m" ]; then
+                                       sed -i -e "/^%define.*_noautoreq/s,$, $req," $spec
+                               fi
                        fi
                done
        done
 fi
+has_opt=$(egrep -c '^Optional-(pkg|ext):' $template || :)
+if [ "$has_opt" -gt 0 ]; then
+       if ! grep -q '%{_docdir}/.*/optional-packages.txt' $spec; then
+               sed -i -e '
+               /^%files$/{
+                       i%post
+                       iif [ -f %{_docdir}/%{name}-%{version}/optional-packages.txt ]; then
+                       i\      cat %{_docdir}/%{name}-%{version}/optional-packages.txt
+                       ifi
+                       i
+               }
+               ' $spec
+       fi
+       if ! grep -q '%doc.*optional-packages.txt' $spec; then
+               sed -i -e '
+               /^%doc install.log/{
+               s/$/ optional-packages.txt/
+               }
+               ' $spec
+       fi
+fi
 
 # parse state
 state=$(awk '/^State:/{print $2}' $template)
This page took 0.058985 seconds and 4 git commands to generate.