COL=80

brand=debian

if test x$brand = "xdebian"; then 
    PKG_GROUP=$PKG_SECTION_DEBIAN
#    PKGTYPE="deb"
fi
if test "x$PKG_GROUP" = "x"; then 
     PKG_GROUP="nose"                 
fi
echo PKGTYPE $PKGTYPE
echo PKG_GROUP $PKG_GROUP


# tambien debiera operar con variable UPACKDROOT como un archivo sources

PKGNAMESE=`echo $PKGNAME |sed -e 's/\.dsc$//'`
PKGNAMESEINT=`echo $PKGNAMESE |sed -e "s/_${VERSION}$/-${VERSION}/"`
ORIG='.orig'
############ misco codigo que en src.rpm , 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
#mv   $TMP_DIR/$PKGNAMESEINT $UPACKDROOT 
#echo "mv   $TMP_DIR/$PKGNAMESEINT $UPACKDROOT "
#ver con links

DEBIAN=debian
mkdir -p $DSCROOT/$PKGNAMESEINT/$DEBIAN 
FILE=$DSCROOT/$PKGNAMESEINT/$DEBIAN/control






## toma de Changelog y prepara info para paquetes
#echo cl2pkgf.pl $PACKAGE - $VERSION - $DISTRO - $URG
#cl2pkgf.pl $PACKAGE $VERSION $DISTRO $URG

cl2pkgf.pl "$DIRSUMA/ChangeLog" deb "$DSCROOT/$PKGNAMESEINT/$DEBIAN/changelog" "$PACKAGE" "$VERSION" "$RELEASE" "testing-unstable-experimental" "low"


# crea /tmp clspec y /tmp cldeb




mkdir -p $DSCROOT/$PKGNAMESEINT/$DEBIAN/source

#echo "3.0 (quilt)"> $UPACKDROOT/$DEBIAN/source/format
echo "1.0"> $DSCROOT/$PKGNAMESEINT/$DEBIAN/source/format
#echo "compression = "bzip2"> $UPACKDROOT/$DEBIAN/sources/options


FILERULES=$DSCROOT/$PKGNAMESEINT/$DEBIAN/rules

echo Source: $PACKAGE>$FILE
echo Maintainer: $MAINTAINER>>$FILE
#echo Uploaders: >>$FILE
echo Section: $PKG_GROUP>>$FILE
echo Priority: $PRIORITY>>$FILE
#echo Build-Depends: $INSTALLEDSIZE>>$FILE
echo Standards-Version: 3.9.1>>$FILE
#echo Homepage:>>$FILE
#echo Description: $SUMMARY>>$FILE
#echo "$DESCRIPTION" | fmt -w $COL | sed -n -e "s/^/ /p " >> $FILE
#cat $FILE

echo "">>$FILE
echo Package: $PACKAGE>>$FILE
echo Architecture: $ARCH>>$FILE
echo Section: $PKG_GROUP>>$FILE
echo Priority: $PRIORITY>>$FILE
#echo Essential: >>$FILE
echo Depends:>>$FILE
echo Description: $SUMMARY>>$FILE
echo "$DESCRIPTION" | fmt -w $COL | sed -n -e "s/^/ /p " >> $FILE
#echo Homepage


#In a source or binary control file, the Description field contains a description of the binary package, consisting of two parts, the synopsis or the short description, and the long description. The field's format is as follows:
#     	Description: <single line synopsis>
#     	 <extended description over several lines>
#The lines in the extended description can have these formats:
#      Those starting with a single space are part of a paragraph. Successive lines of this form will be word-wrapped when displayed. The leading space will usually be stripped off.
#      Those starting with two or more spaces. These will be displayed verbatim. If the display cannot be panned horizontally, the displaying program will line wrap them "hard" (i.e., without taking account of word breaks). If it can they will be allowed to trail off to the right. None, one or two initial spaces may be deleted, but the number of spaces deleted from each line will be the same (so that you can have indenting work correctly, for example).
#      Those containing a single space followed by a single full stop character. These are rendered as blank lines. This is the only way to get a blank line[36].
#      Those containing a space, a full stop and some more characters. These are for future expansion. Do not use them.
#Do not use tab characters. Their effect is not predictable. 

cat >> "$FILERULES" << 'EOF'
#!/usr/bin/make -f
# Sample debian/rules file - for GNU Hello.
#
# modificada para sceptre
#
# Copyright 1994,1995 by Ian Jackson.
# I hereby give you perpetual unlimited permission to copy,
# modify and relicense this file, provided that you do not remove
# my name from the file itself.  (I assert my moral right of
# paternity under the Copyright, Designs and Patents Act 1988.)
# This file may have to be extensively modified

package = $PACKAGE
docdir = debian/tmp/usr/share/doc/$PACKAGE

CC = gcc
CFLAGS = -g -Wall
INSTALL_PROGRAM = install

ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
  INSTALL_PROGRAM += -s
endif

build:
        $(checkdir)
        ./configure --prefix=/usr
        $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)"
        touch build

clean:
        $(checkdir)
        rm -f build
        -$(MAKE) -i distclean
        rm -rf *~ debian/tmp debian/*~ debian/files* debian/substvars

binary-indep:   checkroot build
        $(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch:    checkroot build
        $(checkdir)
        rm -rf debian/tmp
        install -d debian/tmp/DEBIAN $(docdir)
        install -m 755 debian/postinst debian/prerm debian/tmp/DEBIAN
        $(MAKE) INSTALL_PROGRAM="$(INSTALL_PROGRAM)" \
                prefix=$$(pwd)/debian/tmp/usr install
        cd debian/tmp && mv usr/info usr/man usr/share
        cp -a NEWS debian/copyright $(docdir)
        cp -a debian/changelog $(docdir)/changelog.Debian
        cp -a ChangeLog $(docdir)/changelog
        cd $(docdir) && gzip -9 changelog changelog.Debian
        gzip -r9 debian/tmp/usr/share/man
        gzip -9 debian/tmp/usr/share/info/*
        dpkg-shlibdeps debian/tmp/usr/bin/hello
        dpkg-gencontrol -isp
        chown -R root:root debian/tmp
        chmod -R u+w,go=rX debian/tmp
        dpkg --build debian/tmp ..

define checkdir
        test -a -f debian/rules
endef

binary: binary-indep binary-arch

checkroot:
        $(checkdir)
        test $$(id -u) = 0

.PHONY: binary binary-arch binary-indep clean checkroot
EOF


#PACK=sumapack-ini-0.3.813



#echo NOMBRES $PACK - $PKGNAME
#cp  ../sumapack-ini/$PKGNAMESE.tar.gz  $PKGNAMESE.orig.tar.gz
#rm -fr KKKK
#mkdir -p KKKK
#tar -C KKKK -zxf $PKGNAMESE.orig.tar.gz


#cp -r ../sumapack-ini/debian/* KKKK/$PKGNAMESE/debian
# ojo es el fuente

SALIDERA=`dpkg-source -sp -I.svn -b $DSCROOT/$PKGNAMESEINT  ./$PKGNAMESE.orig.tar.gz | awk ' /\.dsc$/ {print $NF}' |sed -e's/\.dsc$//'`
echo MMMMMMM $SALIDERA
#mv $SALIDERA.dsc $PACK.dsc
#mv $SALIDERA.diff.gz $PACK.diff.gz

