# eventualmente estos macros podrian ir a automake

# packlet de upack
#TMP_DIR viene  de upack
# hacer tmp_dir com mktemp

 #tambien debiera operar con variable UPACKDROOT como un archivo


PKGNAMESE=`echo $PKGNAME |sed -e 's/\.src\.rpm$//'`

PKGNAMESEINT=$PKGNAMESE
ORIG=''
############ misco codigo que en deb , hacer funcion
DSCROOT=$TMP_DIR/dsc-root
mkdir -p $DSCROOT
rm -fr $DSCROOT/*
mkdir -p $DSCROOT/$PKGNAMESEINT
#echo "mv $UPACKDROOT $DSCROOT/$PKGNAMESEINT"
cp -r $UPACKDROOT/* $DSCROOT/$PKGNAMESEINT
ORIDIR=`pwd`
cd $DSCROOT
echo "tar -zcf $ORIDIR/$PKGNAMESE$ORIG.tar.gz $PKGNAMESEINT"
tar -zcf $ORIDIR/$PKGNAMESE$ORIG.tar.gz $PKGNAMESEINT
cd $ORIDIR
########################################


. $packlet/rpm-base.sh


#y los patches?
# verificar esto esta en .rpmmacros en rpm-base
rpmdir=$HOME/rpmbuild
#/usr/src/packages


#rpmworkdir=${rpmdir}/BUILD
sudo mkdir -p ${rpmdir}/SOURCES
sudo cp $PKGNAMESE.tar.gz $rpmdir/SOURCES
#mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SRPMS,SPECS,TMP}
#mkdir -p ~/rpmbuild/RPMS/{athlon,i386,i586,i686,noarch}

#	mkdir -p ${rpmworkdir}
#	mkdir -p $(rpmdir)/SRPMS
	#cp $(PACKAGE)-$(VERSION).tar.gz ${rpmworkdir}
SALIDAS=`rpmbuild -bs --buildroot  $(cd ${UPACKDROOT} ; pwd)  ${UPACKDINFO}/$PACKAGE.spec  | awk -F' ' '/\/SRPMS\// {print $2}'`
 echo SAL2  $SALIDAS
#echo  mv $SALIDAS $ARGUME.src.rpm


if test x"$SALIDAS" = x ; then
   msg 4 "Error rpmbuild. $SALIDAS";
   exit
fi

 mv $SALIDAS . 
#$PKGNAME
#.src.rpm

# ver target host build
#targets= $(host_cpu)
#i586 i686 x86_64 ppc ppc64 athlon



#Building from a source RPM (SRPM)

#Install the .src.rpm file this way:

#rpm -i somepackage-1.0-1.src.rpm

#This will create files in the SOURCES directory of your RPM building directory tree, and a .spec file in the SPECS directory.

#Then go the SPECS directory and give the command to build the RPM:

#cd /home/your_userid/rpm/SPECS
#rpmbuild -bb somepackage.spec

