]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - pearize.sh
- bugfix
[packages/rpm-build-tools.git] / pearize.sh
index e725259fb213a311d2ea09c2929d914e4f8759df..cb2717c24f56100ca45fa3f8423f518212806384 100644 (file)
@@ -4,17 +4,17 @@
 # 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 makerpm' command, ./builder for fetching sources.
+# You should have all PEAR packages installed to get best results.
 #
 # 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 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
+# NOTE: old version of 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
 
 set -e
 spec="$1"
@@ -33,24 +33,25 @@ 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-,,')
 
+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
+template=$(pear makerpm --spec-template=$stmp $tarball | awk '/Wrote RPM spec file/{print $NF}{print $0 > "/dev/stderr"}')
 rm -f $stmp
 
-template=$(rpm -q --qf "%{name}-%{version}$rc$pre$beta.spec\n" --specfile "$spec" | head -n 1)
 mv $template .$template~
 template=.$template~
 
-requires=$(grep '^Requires:' $template || :)
-conflicts=$(grep '^Conflicts:' $template || :)
-preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
-# take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things.
-sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble
-
 # take as argument dependency in form NAME EQUALITY VERSION
 # adds rpm epoch to VERSION if the package is installed and has epoch bigger than zero.
 add_epoch() {
@@ -67,15 +68,21 @@ add_epoch() {
        query=$(rpm -q --qf '%{epoch}\n' $pkg || :)
        epoch=$(echo "$query" | grep -v 'installed' || :)
        if [ "$epoch" ] && [ "$epoch" -gt 0 ]; then
-               echo "$dep" | sed -e "s, [<>=] ,&$epoch:,"
+               echo "$dep" | sed -e "s, [<>=]\+ ,&$epoch:,"
        else
                echo "$dep"
        fi
 }
 
+preamble=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
+# take just main package preamble, preamble of tests (and other) subpackage(s) just confuses things.
+sed -ne '/^Name:/,/^BuildRoot/p' $spec > $preamble
+
 # create backup
 bak=$(cp -fbv $spec $spec | awk '{print $NF}' | tr -d "['\`]" )
 
+# parse requires
+requires=$(grep '^Requires:' $template || :)
 if [ -n "$requires" ]; then
        echo "$requires" | while read tag dep; do
                dep=$(add_epoch $dep)
@@ -85,6 +92,8 @@ if [ -n "$requires" ]; then
        done
 fi
 
+# parse conflicts
+conflicts=$(grep '^Conflicts:' $template || :)
 if [ -n "$conflicts" ]; then
        echo "$conflicts" | while read tag dep; do
                dep=$(add_epoch $dep)
@@ -94,6 +103,42 @@ if [ -n "$conflicts" ]; then
        done
 fi
 
+# parse optional deps
+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 | grep -o "$req" || :)
+                       if [ -z "$m" ]; then
+                               sed -i -e "/^%define.*_noautoreq/s,$, $req," $spec
+                       fi
+               done
+       done
+fi
+has_opt=$(egrep -c '^Optional-(pkg|ext):' $template || :)
+if [ "$has_opt" -gt 0 ]; then
+       if ! grep -q optional-packages.txt $spec; then
+               sed -i -e '
+               /^%clean/{
+                       i%post
+                       iif [ -f %{_docdir}/%{name}-%{version}/optional-packages.txt ]; then
+                       i\      cat %{_docdir}/%{name}-%{version}/optional-packages.txt
+                       ifi
+                       i
+               }
+               /^%doc install.log/{
+               s/$/ optional-packages.txt/
+               }
+               ' $spec
+       fi
+fi
+
+# parse state
+state=$(awk '/^State:/{print $2}' $template)
+sed -i -e "/^%define.*_status/{
+       /%define.*_status.*$state/!s/.*/%define\t\t_status\t\t$state/
+}" $spec
+
 rm -f $preamble
 
 diff=$(mktemp "${TMPDIR:-/tmp}/fragXXXXXX")
This page took 0.038726 seconds and 4 git commands to generate.