r2099: Committing for 3.5.4
[ctsim.git] / make-upstream.sh
1 #!/bin/bash 
2 #
3 # Creates upstream packages
4 # Programmer: Kevin Rosenberg
5
6 set -e # abort on error
7
8 usage () {
9     progname="`basename \"$0\"`"
10
11     cat >&2 <<EOF
12 Usage: $progname [options]
13 Creates upstream archives
14 Options:
15   -t   Tag CVS tree with current version numbers
16   -c   Commit all files to CVS server
17   -h   Print this brief help
18 EOF
19 }
20
21 # Command line
22 while [ $# != 0 ]; do
23     value="`echo x\"$1\" | sed -e 's/^x-.//'`"
24     case "$1" in
25         -h)  usage; exit 0           ;;
26         -t)  opt_tag=1               ;;
27         -c)  opt_commit=1            ;;
28          *)  usage; exit 0           ;;
29     esac
30     shift
31 done
32
33 DEBPKG=ctsim
34 PKG=ctsim
35 TOPDIR=`pwd`
36
37 VERSION=`sed -n -e "s/${DEBPKG} (\(.*\)-[0-9.]).*/\1/p" < debian/changelog  |head -1`
38
39 PACKAGE_DIR=/usr/local/src/Packages/${DEBPKG}
40 DISTDIR=${PKG}-${VERSION}
41 DEBDIR=${DEBPKG}-${VERSION}
42
43 if [ -f ${PACKAGE_DIR}/${DEBPKG}_${VERSION}.orig.tar.gz ]; then
44   echo "File ${PACKAGE_DIR}/${DEBPKG}_${VERSION}.orig.tar.gz already exists."
45   echo -n "Are you sure that you want to create a new upstream archive? (y/N): "
46   read answer
47   case $answer in
48       [Yy]*) nop= ;;
49       *) echo "Not building"
50          exit 1
51           ;;
52   esac
53 fi
54
55 if [ ! -z ${opt_commit} ]; then
56     echo "Committing to CVS server"
57     cvs commit -m "Committing for ${VERSION}"
58 fi
59
60 if [ ! -z ${opt_tag} ]; then
61     UPSTREAM_TAG=upstream_version_`echo ${VERSION} | tr . _`
62     echo "(Re-)tagging with Upstream tag '${UPSTREAM_TAG}'"
63     cvs -q rtag -d $UPSTREAM_TAG $PKG > /dev/null
64     cvs -q tag -F $UPSTREAM_TAG > /dev/null
65 fi
66
67
68 if [ ! -f docs/${PKG}.htb -o ! -f docs/html/${PKG}_contents.html -o ! -f docs/${PKG}.pdf ]; then
69   echo "Making documentation"
70   ../make-doc.sh
71 fi
72
73 # Prepare for archive
74 cd ..
75 rm -f ${PKG}_${VERSION}.tar.gz ${DEBPKG}_${VERSION}.orig.tar.gz
76 rm -rf ${DISTDIR} ${DEBDIR} ${DISTDIR}.zip
77 cp -a ${TOPDIR} ${DISTDIR}
78
79 echo "Cleaning distribution directory ${DISTDIR}"
80 cd ${DISTDIR}
81 rm -f upload.sh make-debian.sh make-upstream.sh cvsbp-prepare.sh make-doc.sh 
82 rm -f `find . -type f -name .cvsignore`
83 rm -rf `find . -type d -name CVS -or -name .deps`
84 rm -f `find . -type f -name '*~' -or -name '.#*'  -or -name '#*#' -or -name ".*~" -or -name "*.o" -or -name "*.a"`
85 rm -f `find doc -type f -name \*.tex -or -name \*.aux -or \
86   -name \*.log -or -name \*.out -or -name \*.dvi`
87 rm -rf images doc stamp-h.in build-stamp stamp-h configure-stamp autom4te.cache do-autoconf config.log config.status config.h
88 cd ..
89
90 echo "Creating upstream archives"
91 rm -rf ${DISTDIR}/debian
92 GZIP=-9 tar czf ${DISTDIR}.tar.gz ${DISTDIR}
93
94 if [ "${DISTDIR}" != "${DEBDIR}" ]; then 
95   cp -a ${DISTDIR} ${DEBDIR}
96 else
97   cp -a ${DISTDIR} ${DEBDIR}-copy
98 fi
99
100 unix2dos `find ${DISTDIR} -type f -and -name '*.c' -or -name '*.h' -or \
101   -name '*.cpp' -or -name '*.sh' -or -name '*.in' -or \
102   -name 'Makefile*' -or -name ChangeLog -or -name COPYRIGHT -or -name TODO -or \
103   -name README -or -name INSTALL -or -name NEWS -or -name '*.tex' -or \
104   -name '*.hhc' -or -name '*.hhk' -or -name '*.hpj' -or -name '*.ini' -or \
105   -name COPYING* -or -name catalog` 
106 zip -rq ${DISTDIR}.zip ${DISTDIR}
107 rm -r ${DISTDIR}
108
109 if [ "${DISTDIR}" == "${DEBDIR}" ]; then 
110   mv ${DEBDIR}-copy ${DEBDIR}
111 fi
112 GZIP=-9 tar czf ${DEBPKG}_${VERSION}.orig.tar.gz ${DEBDIR}
113
114 cp -a ${TOPDIR}/debian ${DEBDIR}
115 rm -f ${DEBDIR}/debian/.cvsignore 
116 rm -rf ${DEBDIR}/debian/CVS
117
118 rm -rf ${DEBDIR}
119
120 echo "Moving upstream archives to ${PACKAGE_DIR}"
121 mkdir -p /usr/local/src/Packages/${DEBPKG}
122 rm -f ${PACKAGE_DIR}/${DISTDIR}.zip ${PACKAGE_DIR}/${DEBPKG}_${VERSION}.orig.tar.gz
123 mv ${DISTDIR}.zip ${DEBPKG}_${VERSION}.orig.tar.gz ${DISTDIR}.tar.gz ${PACKAGE_DIR}
124
125 cd ${TOPDIR}
126 exit 0