#!/bin/sh -x
# 2003-2005 (c) Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# BPH - backport; use hasher
# Public domain
# 06.09.2005, 12.09.2005
# Makes backport package
# TODO: ,           , 

. /etc/rpm/etersoft-build-functions

build_list_and_args "$@"

set_release()
{
	subst "s|\(Release:\).*\$|\1 $2|" $1
}

#detect_target_env $LISTARGS
build_list_and_args "$@"

MDISTR=M24
if [ -n "$MENV" ] ; then
	MDISTR=$MENV
	unset MENV MENVARG
fi

test -z "$MDISTR" && { echog "We need $MDISTR directory for backports" ; exit 1 ; }
ORIGWD=`pwd`
mkdir -p $RPMDIR/SPECS/$MDISTR
cd $RPMDIR/SPECS/$MDISTR || { echog "Error"; exit 1 ; }

for i in $LISTNAMES ; do
	#grep Packager ../$i || { echog "Packager field must be in backported spec"; exit 1 ; }
	DEST=`basename $i`
	cp $ORIGWD/$i $DEST && set_release $DEST alt0.$MDISTR.1
	subst "s|%__python_version|2.3|g" $DEST
	subst "s|%python-dev||g" $DEST
	subst "s|%python-base||g" $DEST
	subst "s|%py_provides \(.*\)$|Provides: python2.4(\1)|g" $DEST
	subst "s|%_pkgconfigdir|%_libdir/pkgconfig|g" $DEST
	subst "s|libstdc++3.4-devel-precompiled||g" $DEST
	subst "s|Development/Documentation|Development/C|g" $DEST
	subst "s|xorg-x11-|XFree86-|g" $DEST
	# do not coexist with X
	subst "s|ttmkfdir|freetype|g" $DEST
	subst "s|pkg-config|pkgconfig|g" $DEST
	subst "s|gcc3.4|gcc3.3|g" $DEST
	add_changelog $DEST -e "- backport to ALT Linux $MDISTR"
	rpmbsh -$MDISTR $LISTARGS $REMOTEBUILD $DEST &&
		rpmbs -$MDISTR --nodeps -s $DEST
done

