#! /bin/sh

# $Id: woody-buildpackage,v 1.12 2003/04/01 16:13:39 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)/' \
    -e 's/ unstable; / stable; /' \
    < debian/changelog > debian/changelog.woody

# control: replace liba52-*-dev with a52dec-dev (>=0.7.3)
#                  libdv*-dev with libdv-dev
#                  kdelibs4-dev with kdelibs-dev
#                  libqt3-mt-dev libqt3-compat-headers with libqt-dev
#                  libarts1-dev with libarts-dev
#                  libdvdread3-dev with libdvdread2-dev
#                  libdvdplay0-dev (>=1.0.1-2) with libdvdplay0-dev
#          remove libwxgtk2.4-dev
#                 libflac-dev
#                 libidl0 (workaround for mozilla-dev's bad deps)
#                 libglib2.0-0 (workaround for mozilla-dev's bad deps)
#          change Section: gnome with Section: graphics
#                 Section: kde with Section: kde
sed -e 's/liba52-[^-]*-dev/a52dec-dev (>=0.7.3)/' \
    -e 's/libdv[0-9]*-dev/libdv-dev/' \
    -e 's/kdelibs[0-9]*-dev/kdelibs-dev/' \
    -e 's/libqt[0-9]*-mt-dev/libqt-dev/' \
    -e 's/, libqt[0-9]*-compat-headers[^,]*//' \
    -e 's/libarts[0-9]*-dev/libarts-dev/' \
    -e 's/libdvdread[0-9]*-dev/libdvdread2-dev/' \
    -e 's/, libdvdplay0-dev[^,]*/, libdvdplay0-dev/' \
    -e 's/, libwx[^,]*//' \
    -e '/Package: wxvlc/,/^ *$/d' \
    -e 's/, libflac-dev[^,]*//' \
    -e 's/, libidl0[^,]*//' \
    -e 's/, libglib2.0-0[^,]*//' \
    -e 's/Section: gnome/Section: graphics/' \
    -e 's/Section: kde/Section: graphics/' \
    < debian/control > debian/control.woody

# rules: remove wxwindows stuff
#        change changelog path
sed -e '/# Package: wxvlc/,/^ *$/d' \
    -e 's,^ARCH_EXCLUDE =,& -Nwxvlc,' \
    -e 's,--enable-wxwindows,--disable-wxwindows,' \
    -e 's,--enable-flac,--disable-flac,' \
    -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"

# Clean up
rm -f debian/rules.woody debian/control.woody debian/changelog.woody

