OSDN Git Service

2005-11-05 Daniel Berlin <dberlin@dberlin.org>
[pf3gnuchains/gcc-fork.git] / maintainer-scripts / gcc_release
1 #! /bin/sh
2
3 ########################################################################
4 #
5 # File:   gcc_release
6 # Author: Jeffrey Law, Bernd Schmidt, Mark Mitchell
7 # Date:   2001-05-25
8 #
9 # Contents:
10 #   Script to create a GCC release.
11 #
12 # Copyright (c) 2001, 2002 Free Software Foundation.
13 #
14 # This file is part of GCC.
15 #
16 # GCC is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2, or (at your option)
19 # any later version.
20 #
21 # GCC is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with GCC; see the file COPYING.  If not, write to
28 # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
29 # Boston, MA 02110-1301, USA.
30 #
31 ########################################################################
32
33 ########################################################################
34 # Notes
35 ########################################################################
36
37 # Here is an example usage of this script, to create a GCC 3.0.2
38 # prerelease:
39 #
40 #   gcc_release -r 3.0.2
41 #
42 # This script will automatically use the head of the release branch
43 # to generate the release.
44
45 ########################################################################
46 # Functions
47 ########################################################################
48
49 # Issue the error message given by $1 and exit with a non-zero
50 # exit code.
51
52 error() {
53     echo "gcc_release: error: $1"
54     exit 1
55 }
56
57 # Issue the informational message given by $1.
58
59 inform() {
60     echo "gcc_release: $1"
61 }
62
63 # Issue a usage message explaining how to use this script.
64
65 usage() {
66 cat <<EOF
67 gcc_release -r release [-f] [further options]
68 gcc_release -s name:cvsbranch [further options]
69
70 Options:
71
72   -r release           Version of the form X.Y or X.Y.Z.
73   -s name:cvsbranch    Create a snapshot, not a real release.
74
75   -d destination       Local working directory where we will build the release
76                        (default=${HOME}).
77   -f                   Create a final release (and update ChangeLogs,...).
78   -l                   Indicate that we are running on gcc.gnu.org.
79   -p previous-tarball  Location of a previous tarball (to generate diff files).
80   -t tag               Tag to mark the release in CVS.
81   -u username          Username for upload operations.
82 EOF
83     exit 1
84 }
85
86 # Change to the directory given by $1.
87
88 changedir() {
89   cd $1 || \
90     error "Could not change directory to $1"
91 }
92
93 # Each of the arguments is a directory name, relative to the top
94 # of the source tree.  Return another name for that directory, relative
95 # to the working directory.
96
97 adjust_dirs() {
98   for x in $@; do
99     echo `basename ${SOURCE_DIRECTORY}`/$x
100   done
101 }
102
103 # Build the source tree that will be the basis for the release
104 # in ${WORKING_DIRECTORY}/gcc-${RELEASE}.
105
106 build_sources() {
107   # If the WORKING_DIRECTORY already exists, do not risk destroying it.
108   if [ -r ${WORKING_DIRECTORY} ]; then
109     error "\`${WORKING_DIRECTORY}' already exists"
110   fi
111   # Create the WORKING_DIRECTORY.
112   mkdir "${WORKING_DIRECTORY}" \
113     || error "Could not create \`${WORKING_DIRECTORY}'"
114   changedir "${WORKING_DIRECTORY}"
115
116   # If this is a final release, make sure that the ChangeLogs
117   # and version strings are updated.
118   if [ ${FINAL} -ne 0 ]; then
119     inform "Updating ChangeLogs and version files"
120
121     ${SVN} -q co "${SVNROOT}/${SVNBRANCH}" "`basename ${SOURCE_DIRECTORY}`" ||\
122            error "Could not check out release sources"
123     for x in `find ${SOURCE_DIRECTORY} -name ChangeLog`; do
124       # Update this ChangeLog file only if it does not yet contain the
125       # entry we are going to add.  (This is a safety net for repeated
126       # runs of this script for the same release.)
127       if ! grep "GCC ${RELEASE} released." ${x} > /dev/null ; then       
128         cat - ${x} > ${x}.new <<EOF
129 ${LONG_DATE}  Release Manager
130
131         * GCC ${RELEASE} released.
132
133 EOF
134         mv ${x}.new ${x} || \
135             error "Could not update ${x}"
136         (changedir `dirname ${x}` && \
137             ${SVN} -q ci -m 'Mark ChangeLog' `basename ${x}`) || \
138             error "Could not commit ${x}"
139       fi
140     done
141
142     # Update gcc/DEV-PHASE if it exists, otherwise gcc/version.c.
143
144     if [ -f ${SOURCE_DIRECTORY}/gcc/DEV-PHASE ]; then
145       [ `cat ${SOURCE_DIRECTORY}/gcc/BASE-VER` = ${RELEASE} ] || \
146       error "Release number ${RELEASE} does not match BASE-VER"
147       (changedir ${SOURCE_DIRECTORY}/gcc && \
148        : > DEV-PHASE && \
149        ${SVN} -q ci -m 'Mark as release' DEV-PHASE) || \
150       error "Could not update DEV-PHASE"
151     else
152       for x in gcc/version.c; do 
153         y=`basename ${x}`
154         (changedir `dirname ${SOURCE_DIRECTORY}/${x}` && \
155             sed -e 's|version_string\[\] = \".*\"|version_string\[\] = \"'${RELEASE}'\"|g' < ${y} > ${y}.new && \
156             mv ${y}.new ${y} && \
157             ${SVN} -q ci -m 'Update version' ${y}) || \
158             error "Could not update ${x}"
159       done
160     fi
161
162     # Make sure we tag the sources for a final release.
163     TAG="tags/gcc_`echo ${RELEASE} | tr . _`_release"
164
165     rm -rf ${SOURCE_DIRECTORY}
166   fi
167
168   # Tag the sources.
169   EXPORTDATE=""
170   if [ -n "${TAG}" ]; then
171     inform "Tagging sources as ${TAG}"
172     EXPORTTAG="${TAG}"
173     # Try to check out a file using ${TAG}.  If the command succeeds,
174     # then the sources have already been tagged.  We don't want to 
175     # overwrite an existing tag, so we don't want to use the "-F"
176     # option to "cvs rtag" below.  So, if the tag already exists,
177     # issue an error message; the release manager can manually remove
178     # the tag if appropriate.
179     echo "${SVN} ls ${SVNROOT}/${EXPORTTAG}/ChangeLog" 
180     if ${SVN} ls "${SVNROOT}/${EXPORTTAG}/ChangeLog"; then 
181       error "Tag ${TAG} already exists"
182     fi
183     ${SVN} -m "Tagging source as ${TAG}" cp "${SVNROOT}/${SVNBRANCH}" "${SVNROOT}/${TAG}" || \
184     #  error "Could not tag sources"
185     #EXPORTTAG="${SVNBRANCH}"
186   else
187     if [ ${SVNBRANCH} != "/trunk" ]; then
188       EXPORTTAG="/branches/${SVNBRANCH}"
189       # It does not work to use both "-r" and "-D" with
190       # "cvs export" so EXPORTDATE is not set here.
191     else
192       # HEAD is the default branch, no need to specify it.
193       EXPORTTAG=""
194       EXPORTDATE="-D{`date --iso-8601=minutes`}"
195     fi
196   fi
197
198   # Export the current sources.
199   inform "Retrieving sources (svn export ${EXPORTTAG} ${EXPORTDATE} gcc)"
200
201   if [ -z "${EXPORTTAG}" ]; then
202     ${SVN} -q export ${EXPORTDATE} "${SVNROOT}/trunk" "`basename ${SOURCE_DIRECTORY}`" ||\
203       error "Could not retrieve sources"
204     SVNREV = `${SVN} info ${EXPORTDATE} "${SVNROOT}/trunk"|grep "Revision:"|awk '{print $2}'`
205   elif [ -z "${EXPORTDATE}" ]; then
206     ${SVN} -q export "${SVNROOT}/${EXPORTTAG}" "`basename ${SOURCE_DIRECTORY}`/" ||\
207       error "Could not retrieve sources"
208     SVNREV = `${SVN} info "${SVNROOT}/${EXPORTTAG}"|grep "Revision:"|awk '{print $2}'`
209   else
210     error "Cannot specify -r and -D at the same time"
211   fi
212
213   # Run gcc_update on them to set up the timestamps nicely, and (re)write
214   # the LAST_UPDATED file containing the CVS tag/date used.
215   changedir "gcc-${RELEASE}"
216   contrib/gcc_update --touch
217   echo "Obtained from SVN: ${EXPORTTAG} ${EXPORTDATE}" > LAST_UPDATED
218
219   # Obtain some documentation files from the wwwdocs module.
220   inform "Retrieving HTML documentation"
221   changedir "${WORKING_DIRECTORY}"
222   for x in bugs faq; do
223     (${CVS} export -r HEAD wwwdocs/htdocs/${x}.html && \
224      cp ${WORKING_DIRECTORY}/wwwdocs/htdocs/${x}.html \
225         ${SOURCE_DIRECTORY}) || \
226       error "Could not retrieve ${x}.html"
227   done
228
229   inform "Generating plain-text documentation from HTML"
230   changedir "${SOURCE_DIRECTORY}"
231   for file in *.html; do
232     newfile=`echo $file | sed -e 's/.html//' | tr "[:lower:]" "[:upper:]"`
233     (${ENV} TERM=vt100 lynx -dump $file \
234        | sed -e "s#file://localhost`/bin/pwd`\(.*\)#http://gcc.gnu.org\1#g" \
235        > $newfile) || \
236      error "Could not generate text-only version of ${file}"
237   done
238
239   # For a prerelease or real release, we need to generate additional
240   # files not present in SVN.
241   changedir "${SOURCE_DIRECTORY}"
242   if [ $SNAPSHOT -ne 1 ]; then
243     # Generate the documentation.
244     inform "Building install docs"
245     SOURCEDIR=${SOURCE_DIRECTORY}/gcc/doc
246     DESTDIR=${SOURCE_DIRECTORY}/INSTALL
247     export SOURCEDIR
248     export DESTDIR
249     ${SOURCE_DIRECTORY}/gcc/doc/install.texi2html
250
251     # Regenerate the NEWS file.
252     contrib/gennews > NEWS || \
253       error "Could not regenerate NEWS files"
254
255     # Now, we must build the compiler in order to create any generated
256     # files that are supposed to go in the source directory.  This is
257     # also a good sanity check to make sure that the release builds
258     # on at least one platform.
259     inform "Building compiler"
260     OBJECT_DIRECTORY=../objdir
261     contrib/gcc_build -d ${SOURCE_DIRECTORY} -o ${OBJECT_DIRECTORY} \
262       -c "--enable-generated-files-in-srcdir" build || \
263       error "Could not rebuild GCC"
264   fi
265
266   # Move message catalogs to source directory.
267   mv ../objdir/gcc/po/*.gmo gcc/po/
268   [ -f libcpp/po/cpplib.pot ] && mv ../objdir/libcpp/po/*.gmo libcpp/po/
269
270   # Create a "MD5SUMS" file to use for checking the validity of the release.
271   echo \
272 "# This file contains the MD5 checksums of the files in the 
273 # gcc-"${RELEASE}".tar.bz2 tarball.
274 #
275 # Besides verifying that all files in the tarball were correctly expanded,
276 # it also can be used to determine if any files have changed since the
277 # tarball was expanded or to verify that a patchfile was correctly applied.
278 #
279 # Suggested usage:
280 # md5sum -c MD5SUMS | grep -v \"OK$\"
281 " > MD5SUMS
282
283   find . -type f |
284   sed -e 's:^\./::' -e '/MD5SUMS/d' |
285   sort |
286   xargs md5sum >>MD5SUMS
287 }
288
289 # Buid a single tarfile.  The first argument is the name of the name
290 # of the tarfile to build, without any suffixes.  They will be added
291 # automatically.  The rest of the arguments are the files or
292 # directories to include, and possibly other arguments to tar.
293
294 build_tarfile() {
295   # Get the name of the destination tar file.
296   TARFILE="$1.tar.bz2"
297   shift
298
299   # Build the tar file itself.
300   (${TAR} cf - "$@" | ${BZIP2} > ${TARFILE}) || \
301     error "Could not build tarfile"
302   FILE_LIST="${FILE_LIST} ${TARFILE}"
303 }
304
305 # Build a single tarfile if any of the directories listed exist,
306 # but not if none of them do (because that component doesn't exist
307 # on this branch).
308 maybe_build_tarfile() {
309   dest=$1
310   shift
311   dir_exists=0
312   for maybe_dir in "$@"; do
313     if [ -d "$maybe_dir" ]; then
314       dir_exists=1
315     fi
316   done
317   if [ $dir_exists = 1 ]; then
318     build_tarfile "$dest" "$@"
319   else
320     echo "Not building $dest tarfile"
321   fi
322 }
323
324 # Build the various tar files for the release.
325
326 build_tarfiles() {
327   inform "Building tarfiles"
328
329   changedir "${WORKING_DIRECTORY}"
330
331   # The GNU Coding Standards specify that all files should
332   # world readable.
333   chmod -R a+r ${SOURCE_DIRECTORY}
334   # And that all directories have mode 777.
335   find ${SOURCE_DIRECTORY} -type d -exec chmod 777 {} \;
336  
337   # Build one huge tarfile for the entire distribution.
338   build_tarfile gcc-${RELEASE} `basename ${SOURCE_DIRECTORY}`
339
340   # Now, build one for each of the languages.
341   maybe_build_tarfile gcc-ada-${RELEASE} ${ADA_DIRS}
342   maybe_build_tarfile gcc-g++-${RELEASE} ${CPLUSPLUS_DIRS}
343   maybe_build_tarfile gcc-g77-${RELEASE} ${FORTRAN_DIRS}
344   maybe_build_tarfile gcc-fortran-${RELEASE} ${FORTRAN95_DIRS}
345   maybe_build_tarfile gcc-java-${RELEASE} ${JAVA_DIRS}
346   maybe_build_tarfile gcc-objc-${RELEASE} ${OBJECTIVEC_DIRS}
347   maybe_build_tarfile gcc-testsuite-${RELEASE} ${TESTSUITE_DIRS}
348    
349   # The core is everything else.
350   EXCLUDES=""
351   for x in ${ADA_DIRS} ${CPLUSPLUS_DIRS} ${FORTRAN_DIRS} ${FORTRAN95_DIRS}\
352            ${JAVA_DIRS} ${OBJECTIVEC_DIRS} ${TESTSUITE_DIRS}; do
353     EXCLUDES="${EXCLUDES} --exclude $x"
354   done
355   build_tarfile gcc-core-${RELEASE} ${EXCLUDES} \
356     `basename ${SOURCE_DIRECTORY}`
357 }
358
359 # Build .gz files.
360 build_gzip() {
361   for f in ${FILE_LIST}; do
362     target=${f%.bz2}.gz
363     (${BZIP2} -d -c $f | ${GZIP} > ${target}) || error "Could not create ${target}"
364   done
365 }
366
367 # Build diffs against an old release.
368 build_diffs() {
369   old_dir=${1%/*}
370   old_file=${1##*/}
371   old_vers=${old_file%.tar.bz2}
372   old_vers=${old_vers#gcc-}
373   inform "Building diffs against version $old_vers"
374   for f in gcc gcc-ada gcc-g++ gcc-g77 gcc-fortran gcc-java gcc-objc gcc-testsuite gcc-core; do
375     old_tar=${old_dir}/${f}-${old_vers}.tar.bz2
376     new_tar=${WORKING_DIRECTORY}/${f}-${RELEASE}.tar.bz2
377     if [ ! -e $old_tar ]; then
378       inform "$old_tar not found; not generating diff file"
379     elif [ ! -e $new_tar ]; then
380       inform "$new_tar not found; not generating diff file"
381     else
382       build_diff $old_tar gcc-${old_vers} $new_tar gcc-${RELEASE} \
383         ${f}-${old_vers}-${RELEASE}.diff.bz2
384     fi
385   done
386 }
387
388 # Build an individual diff.
389 build_diff() {
390   changedir "${WORKING_DIRECTORY}"
391   tmpdir=gccdiff.$$
392   mkdir $tmpdir || error "Could not create directory $tmpdir"
393   changedir $tmpdir
394   (${BZIP2} -d -c $1 | ${TAR} xf - ) || error "Could not unpack $1 for diffs"
395   (${BZIP2} -d -c $3 | ${TAR} xf - ) || error "Could not unpack $3 for diffs"
396   ${DIFF} $2 $4 > ../${5%.bz2}
397   if [ $? -eq 2 ]; then
398     error "Trouble making diffs from $1 to $3"
399   fi
400   ${BZIP2} ../${5%.bz2} || error "Could not generate ../$5"
401   changedir ..
402   rm -rf $tmpdir
403   FILE_LIST="${FILE_LIST} $5"
404 }
405
406 # Upload the files to the FTP server.
407 upload_files() {
408   inform "Uploading files"
409
410   changedir "${WORKING_DIRECTORY}"
411
412   # Make sure the directory exists on the server.
413   if [ $LOCAL -eq 0 ]; then
414     ${SSH} -l ${GCC_USERNAME} ${GCC_HOSTNAME} \
415       mkdir -p "${FTP_PATH}/diffs"
416     UPLOAD_PATH="${GCC_USERNAME}@${GCC_HOSTNAME}:${FTP_PATH}"
417   else
418     mkdir -p "${FTP_PATH}/diffs" \
419       || error "Could not create \`${FTP_PATH}'"
420     UPLOAD_PATH=${FTP_PATH}
421   fi
422
423   # Then copy files to their respective (sub)directories.
424   for x in gcc*.gz gcc*.bz2; do
425     if [ -e ${x} ]; then
426       # Make sure the file will be readable on the server.
427       chmod a+r ${x}
428       # Copy it.
429       case ${x} in
430         *.diff.*)
431           SUBDIR="diffs/";
432           ;;
433         *)
434           SUBDIR="";
435       esac
436       ${SCP} ${x} ${UPLOAD_PATH}/${SUBDIR} \
437         || error "Could not upload ${x}"
438     fi
439   done
440 }
441
442 #Print description if snapshot exists
443 snapshot_print() {
444   if [ -e ${RELEASE}/$1 ]; then
445      printf "%-38s%s\n\n" "$1" "$2" >> ${SNAPSHOT_README}
446      echo "  <tr><td><a href=\"$1\">$1</a></td>" >> ${SNAPSHOT_INDEX}
447      echo "      <td>$2</td></tr>" >> ${SNAPSHOT_INDEX}
448   fi
449 }
450
451 # Announce a snapshot, both on the web and via mail.
452 announce_snapshot() {
453   inform "Updating links and READMEs on the FTP server"
454   
455   TEXT_DATE=`date --date=$DATE +%B\ %d,\ %Y`
456   SNAPSHOT_README=${RELEASE}/README
457   SNAPSHOT_INDEX=${RELEASE}/index.html
458
459   changedir "${SNAPSHOTS_DIR}"
460   echo \
461 "Snapshot gcc-"${RELEASE}" is now available on
462   ftp://gcc.gnu.org/pub/gcc/snapshots/"${RELEASE}"/
463 and on various mirrors, see http://gcc.gnu.org/mirrors.html for details.
464
465 This snapshot has been generated from the GCC "${BRANCH}" SVN branch
466 with the following options: "svn://gcc.gnu.org/svn/gcc/${SVNBRANCH} revision ${SVNREV}"
467
468 You'll find:
469 " > ${SNAPSHOT_README}
470
471   echo \
472 "<html>
473
474 <head>
475 <title>GCC "${RELEASE}" Snapshot</title>
476 </head>
477
478 <body>
479 <h1>GCC "${RELEASE}" Snapshot</h1>
480
481 <p>The <a href =\"http://gcc.gnu.org/\">GCC Project</a> makes
482 periodic snapshots of the GCC source tree available to the public
483 for testing purposes.</p>
484         
485 <p>If you are planning to download and use one of our snapshots, then
486 we highly recommend you join the GCC developers list.  Details for
487 how to sign up can be found on the GCC project home page.</p>
488
489 <p>This snapshot has been generated from the GCC "${BRANCH}" SVN branch
490 with the following options: <code>"svn://gcc.gnu.org/svn/gcc/${SVNBRANCH} revision ${SVNREV}"</code></p>
491
492 <table>" > ${SNAPSHOT_INDEX}
493        
494   snapshot_print gcc-${RELEASE}.tar.bz2 "Complete GCC (includes all of below)"
495   snapshot_print gcc-core-${RELEASE}.tar.bz2 "C front end and core compiler"
496   snapshot_print gcc-ada-${RELEASE}.tar.bz2 "Ada front end and runtime"
497   snapshot_print gcc-fortran-${RELEASE}.tar.bz2 "Fortran front end and runtime"
498   snapshot_print gcc-g++-${RELEASE}.tar.bz2 "C++ front end and runtime"
499   snapshot_print gcc-g77-${RELEASE}.tar.bz2 "Fortran 77 front end and runtime"
500   snapshot_print gcc-java-${RELEASE}.tar.bz2 "Java front end and runtime"
501   snapshot_print gcc-objc-${RELEASE}.tar.bz2 "Objective-C front end and runtime"
502   snapshot_print gcc-testsuite-${RELEASE}.tar.bz2 "The GCC testsuite"
503
504   echo \
505 "Diffs from "${BRANCH}"-"${LAST_DATE}" are available in the diffs/ subdirectory.
506
507 When a particular snapshot is ready for public consumption the LATEST-"${BRANCH}"
508 link is updated and a message is sent to the gcc list.  Please do not use
509 a snapshot before it has been announced that way." >> ${SNAPSHOT_README}
510
511   echo \
512 "</table>
513 <p>Diffs from "${BRANCH}"-"${LAST_DATE}" are available in the
514 <a href=\"diffs/\">diffs/ subdirectory</a>.</p>
515
516 <p>When a particular snapshot is ready for public consumption the LATEST-"${BRANCH}"
517 link is updated and a message is sent to the gcc list.  Please do not use
518 a snapshot before it has been announced that way.</p>
519
520 <hr />
521
522 <address>
523 <a href=\"mailto:gcc@gcc.gnu.org\">gcc@gcc.gnu.org</a>
524 <br />
525 Last modified "${TEXT_DATE}"
526 </address>
527 </body>
528
529 </html>" >> ${SNAPSHOT_INDEX}
530
531   rm -f LATEST-${BRANCH}
532   ln -s ${RELEASE} LATEST-${BRANCH}
533
534   inform "Sending mail"
535
536   export QMAILHOST=gcc.gnu.org
537   mail -s "gcc-${RELEASE} is now available" gcc@gcc.gnu.org < ${SNAPSHOT_README}
538 }
539
540 ########################################################################
541 # Initialization
542 ########################################################################
543
544 # Today's date.
545 DATE=`date "+%Y%m%d"`
546 LONG_DATE=`date "+%Y-%m-%d"`
547
548 SVN=${SVN:-/usr/bin/svn}
549 # The CVS server containing the GCC repository.
550 SVN_SERVER="gcc.gnu.org"
551 # The path to the repository on that server.
552 SVN_REPOSITORY="/svn/gcc"
553 # The username to use when connecting to the server.
554 SVN_USERNAME="${USER}"
555
556 # The machine to which files will be uploaded.
557 GCC_HOSTNAME="gcc.gnu.org"
558 # The name of the account on the machine to which files are uploaded.
559 GCC_USERNAME="gccadmin"
560 # The directory in which the files will be placed (do not use ~user syntax).
561 FTP_PATH=/var/ftp/pub/gcc
562 # The directory in which snapshots will be placed.
563 SNAPSHOTS_DIR=${FTP_PATH}/snapshots
564
565 # The major number for the release.  For release `3.0.2' this would be 
566 # `3'
567 RELEASE_MAJOR=""
568 # The minor number for the release.  For release `3.0.2' this would be
569 # `0'.
570 RELEASE_MINOR=""
571 # The revision number for the release.  For release `3.0.2' this would
572 # be `2'.
573 RELEASE_REVISION=""
574 # The complete name of the release.
575 RELEASE=""
576
577 # The name of the branch from which the release should be made, in a 
578 # user-friendly form.
579 BRANCH=""
580
581 # The name of the branch from which the release should be made, as used
582 # for our version control system.
583 SVNBRANCH=""
584
585 # The tag to apply to the sources used for the release.
586 TAG=""
587
588 # The old tarballs from which to generate diffs.
589 OLD_TARS=""
590
591 # The directory that will be used to construct the release.  The
592 # release itself will be placed in a subdirectory of this diretory.
593 DESTINATION=${HOME}
594 # The subdirectory.
595 WORKING_DIRECTORY=""
596 # The directory that will contain the GCC sources.
597 SOURCE_DIRECTORY=""
598
599 # The directories that should be part of the various language-specific
600 # tar files.  These are all relative to the top of the source tree.
601 ADA_DIRS="gcc/ada libada gnattools"
602 CPLUSPLUS_DIRS="gcc/cp libstdc++-v3"
603 FORTRAN_DIRS="gcc/f libf2c"
604 FORTRAN95_DIRS="gcc/fortran libgfortran"
605 JAVA_DIRS="gcc/java libjava libffi fastjar zlib boehm-gc"
606 OBJECTIVEC_DIRS="gcc/objc libobjc"
607 TESTSUITE_DIRS="gcc/testsuite"
608
609 # Non-zero if this is the final release, rather than a prerelease.
610 FINAL=0
611
612 # Non-zero if we are building a snapshot, and don't build gcc or
613 # include generated files.
614 SNAPSHOT=0
615
616 # Non-zero if we are running locally on gcc.gnu.org, and use local CVS
617 # and copy directly to the FTP directory.
618 LOCAL=0
619
620 # Major operation modes.
621 MODE_GZIP=0
622 MODE_DIFFS=0
623 MODE_SOURCES=0
624 MODE_TARFILES=0
625 MODE_UPLOAD=0
626
627 # List of archive files generated; used to create .gz files from .bz2.
628 FILE_LIST=""
629
630 # Programs we use.
631
632 BZIP2="${BZIP2:-bzip2}"
633 CVS="${CVS:-cvs -f -Q -z9}"
634 DIFF="${DIFF:-diff -Nrcpad}"
635 ENV="${ENV:-env}"
636 GZIP="${GZIP:-gzip --best}"
637 SCP="${SCP:-scp -p}"
638 SSH="${SSH:-ssh}"
639 TAR="${TAR:-tar}"
640
641 ########################################################################
642 # Command Line Processing
643 ########################################################################
644
645 # Parse the options.
646 while getopts "d:fr:u:t:p:s:l" ARG; do
647     case $ARG in
648     d)    DESTINATION="${OPTARG}";;
649     r)    RELEASE="${OPTARG}";;
650     t)    TAG="${OPTARG}";;
651     u)    SVN_USERNAME="${OPTARG}";;
652     f)    FINAL=1;;
653     s)    SNAPSHOT=1
654           BRANCH=${OPTARG%:*}
655           SVNBRANCH=${OPTARG#*:}
656           ;;
657     l)    LOCAL=1
658           SCP=cp
659           PATH=~:/usr/local/bin:$PATH;;
660     p)    OLD_TARS="${OLD_TARS} ${OPTARG}"
661           if [ ! -f ${OPTARG} ]; then
662             error "-p argument must name a tarball"
663           fi;;
664     \?)   usage;;
665     esac
666 done
667 shift `expr ${OPTIND} - 1`
668
669 # Handle the major modes.
670 while [ $# -ne 0 ]; do
671     case $1 in
672     diffs)    MODE_DIFFS=1;;
673     gzip)     MODE_GZIP=1;;
674     sources)  MODE_SOURCES=1;;
675     tarfiles) MODE_TARFILES=1;;
676     upload)   MODE_UPLOAD=1;;
677     all)      MODE_SOURCES=1; MODE_TARFILES=1; MODE_DIFFS=1; MODE_UPLOAD=1;
678               if [ $SNAPSHOT -ne 1 ]; then
679                 # Only for releases and pre-releases.
680                 MODE_GZIP=1;
681               fi
682               ;;
683     *)        error "Unknown mode $1";;
684     esac
685     shift
686 done
687
688 # Perform consistency checking.
689 if [ ${LOCAL} -eq 0 ] && [ -z ${SVN_USERNAME} ]; then
690   error "No username specified"
691 fi
692
693 if [ ! -d ${DESTINATION} ]; then
694   error "\`${DESTINATION}' is not a directory"
695 fi
696
697 if [ $SNAPSHOT -eq 0 ]; then
698   if [ -z ${RELEASE} ]; then
699     error "No release number specified"
700   fi
701
702   # Compute the major and minor release numbers.
703   RELEASE_MAJOR=`echo $RELEASE | awk --assign FS=. '{ print $1; }'`
704   RELEASE_MINOR=`echo $RELEASE | awk --assign FS=. '{ print $2; }'`
705   RELEASE_REVISION=`echo $RELEASE | awk --assign FS=. '{ print $3; }'`
706
707   if [ -z "${RELEASE_MAJOR}" ] || [ -z "${RELEASE_MINOR}" ]; then
708     error "Release number \`${RELEASE}' is invalid"
709   fi
710
711   # Compute the full name of the release.
712   if [ -z "${RELEASE_REVISION}" ]; then
713     RELEASE="${RELEASE_MAJOR}.${RELEASE_MINOR}"
714   else
715     RELEASE="${RELEASE_MAJOR}.${RELEASE_MINOR}.${RELEASE_REVISION}"
716   fi
717
718   # Compute the name of the branch, which is based solely on the major
719   # and minor release numbers.
720   SVNBRANCH="branches/gcc-${RELEASE_MAJOR}_${RELEASE_MINOR}-branch"
721
722   # If this is not a final release, set various parameters acordingly.
723   if [ ${FINAL} -ne 1 ]; then
724     RELEASE="${RELEASE}-${DATE}"
725     FTP_PATH="${FTP_PATH}/prerelease-${RELEASE}/"
726   else
727     FTP_PATH="${FTP_PATH}/releases/gcc-${RELEASE}/"
728   fi
729 else
730   RELEASE=${BRANCH}-${DATE}
731   FTP_PATH="${FTP_PATH}/snapshots/${RELEASE}"
732 #  if [ ${SVNBRANCH} != "/trunk" ]; then
733 #    TAG=tags/gcc-ss-`echo ${RELEASE} | tr '.' '_'`
734 #  fi
735
736   # If diffs are requested when building locally on gcc.gnu.org, we (usually)
737   # know what the last snapshot date was and take the corresponding tarballs,
738   # unless the user specified tarballs explictly.
739   if [ $MODE_DIFFS -ne 0 ] && [ $LOCAL -ne 0 ] && [ -z "${OLD_TARS}" ]; then
740     LAST_DATE=`cat ~/.snapshot_date-${BRANCH}`
741     OLD_TARS=${SNAPSHOTS_DIR}/${BRANCH}-${LAST_DATE}/gcc-${BRANCH}-${LAST_DATE}.tar.bz2
742   fi
743 fi
744
745 # Compute the name of the WORKING_DIRECTORY and the SOURCE_DIRECTORY.
746 WORKING_DIRECTORY="${DESTINATION}/gcc-${RELEASE}"
747 SOURCE_DIRECTORY="${WORKING_DIRECTORY}/gcc-${RELEASE}"
748
749 # Recompute the names of all the language-specific directories,
750 # relative to the WORKING_DIRECTORY.
751 ADA_DIRS=`adjust_dirs ${ADA_DIRS}`
752 CPLUSPLUS_DIRS=`adjust_dirs ${CPLUSPLUS_DIRS}`
753 FORTRAN_DIRS=`adjust_dirs ${FORTRAN_DIRS}`
754 FORTRAN95_DIRS=`adjust_dirs ${FORTRAN95_DIRS}`
755 JAVA_DIRS=`adjust_dirs ${JAVA_DIRS}`
756 OBJECTIVEC_DIRS=`adjust_dirs ${OBJECTIVEC_DIRS}`
757 TESTSUITE_DIRS=`adjust_dirs ${TESTSUITE_DIRS}`
758
759 # Set up SVNROOT.
760 if [ $LOCAL -eq 0 ]; then
761     SVNROOT="svn://${SVN_USERNAME}@${SVN_SERVER}${SVN_REPOSITORY}"
762 else
763     SVNROOT="file:///svn/gcc"
764     CVSROOT="/cvs/gcc"
765 fi
766 export SVNROOT
767 export CVSROOT
768
769 ########################################################################
770 # Main Program
771 ########################################################################
772
773 # Set the timezone to UTC
774 TZ="UTC0"
775 export TZ
776
777 # Build the source directory.
778
779 if [ $MODE_SOURCES -ne 0 ]; then
780   build_sources
781 fi
782
783 # Build the tar files.
784
785 if [ $MODE_TARFILES -ne 0 ]; then
786   build_tarfiles
787 fi
788
789 # Build diffs
790
791 if [ $MODE_DIFFS -ne 0 ]; then
792   # Possibly build diffs.
793   if [ -n "$OLD_TARS" ]; then
794     for old_tar in $OLD_TARS; do
795       build_diffs $old_tar
796     done
797   fi
798 fi
799
800 # Build gzip files
801 if [ $MODE_GZIP -ne 0 ]; then
802   build_gzip
803 fi
804
805 # Upload them to the FTP server.
806 if [ $MODE_UPLOAD -ne 0 ]; then
807   upload_files
808
809   # For snapshots, make some further updates.
810   if [ $SNAPSHOT -ne 0 ] && [ $LOCAL -ne 0 ]; then
811     announce_snapshot
812
813     # Update snapshot date file.
814     changedir ~
815     echo $DATE > .snapshot_date-${BRANCH}
816
817     # Remove working directory
818     rm -rf ${WORKING_DIRECTORY}
819   fi
820 fi