#! /bin/sh

# $Id: woody-buildpackage,v 1.5 2003/02/03 19:45:29 sam Exp $
# Build VLC for a Woody Debian system

if test ! -d debian
then
  echo "No debian/ directory"
  exit 1
fi

# changelog: replace (1.2.3-4) with (1.2.3-0woody.4)
sed -e 's/^vlc (\([^)]*\)-\([^-)]*\))/vlc (\1-0woody.\2)/' \
    < debian/changelog > debian/changelog.woody

# control: replace liba52-*-dev with a52dec-dev (>=0.7.3)
#                  libdv*-dev with libdv-dev
#          remove libwxgtk2.4-dev
sed -e 's/liba52-[^-]*-dev/a52dec-dev (>=0.7.3)/' \
    -e 's/libdv[0-9]*-dev/libdv-dev/' \
    -e 's/, libwx[^,]*//' \
    -e '/Package: wxvlc/,/^ *$/d' \
    < debian/control > debian/control.woody

# rules: remove wxwindows stuff
#        change changelog path
sed -e '/# Package: wxvlc/,/^ *$/d' \
    -e 's,--enable-wxwindows,--disable-wxwindows,' \
    -e 's, debian/changelog , debian/changelog.woody ,' \
    -e 's,dh_gencontrol[^#]*,& -- -ldebian/changelog.woody,' \
    < debian/rules > debian/rules.woody
chmod a+x debian/rules.woody

# Environment variables - taken from dpkg-buildpackage
curd="`pwd`"
dirn="`basename \"$curd\"`"
package="`dpkg-parsechangelog -ldebian/changelog.woody | sed -n 's/^Source: //p'`"
version="`dpkg-parsechangelog -ldebian/changelog.woody | sed -n 's/^Version: //p'`"
maintainer="`dpkg-parsechangelog -ldebian/changelog.woody | sed -n 's/^Maintainer: //p'`"
eval `dpkg-architecture -a -t -s -f`
arch="`dpkg-architecture -a -t -qDEB_HOST_ARCH`"
sversion=`echo "$version" | perl -pe 's/^\d+://'`
pv="${package}_${sversion}"
pva="${package}_${sversion}_${arch}"
chg=../"$pva.changes"

# Do the real work
dpkg-checkbuilddeps -B debian/control.woody || exit 1
fakeroot debian/rules.woody clean
cd ..; dpkg-source -l"$dirn"/debian/changelog.woody -b "$dirn"; cd "$dirn"
debian/rules.woody build
fakeroot debian/rules.woody binary
dpkg-genchanges -ldebian/changelog.woody -cdebian/control.woody >"$chg"

