OSDN Git Service

first pass at updated gcc_release, should work for snapshots
[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="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     echo "Would execute ${SVN} cp ${SVNROOT}/${SVNBRANCH} ${SVNROOT}/${TAG}"
184     #${SVN} -m "Tagging source as ${TAG}" cp "${SVNROOT}/${SVNBRANCH}" "${SVNROOT}/${TAG}" || \
185     #  error "Could not tag sources"
186     EXPORTTAG="${SVNBRANCH}"
187   else
188     if [ ${SVNBRANCH} != "/trunk" ]; then
189       EXPORTTAG="/branches/${SVNBRANCH}"
190       # It does not work to use both "-r" and "-D" with
191       # "cvs export" so EXPORTDATE is not set here.
192     else
193       # HEAD is the default branch, no need to specify it.
194       EXPORTTAG=""
195       EXPORTDATE="-D{`date --iso-8601=minutes`}"
196     fi
197   fi
198
199   # Export the current sources.
200   inform "Retrieving sources (svn export ${EXPORTTAG} ${EXPORTDATE} gcc)"
201
202   if [ -z "${EXPORTTAG}" ]; then
203     ${SVN} -q export ${EXPORTDATE} "${SVNROOT}/trunk" "`basename ${SOURCE_DIRECTORY}`" ||\
204       error "Could not retrieve sources"
205   elif [ -z "${EXPORTDATE}" ]; then
206     ${SVN} -q export "${SVNROOT}/${EXPORTTAG}" "`basename ${SOURCE_DIRECTORY}`/" ||\
207       error "Could not retrieve sources"
208   else
209     error "Cannot specify -r and -D at the same time"
210   fi
211
212   # Run gcc_update on them to set up the timestamps nicely, and (re)write
213   # the LAST_UPDATED file containing the CVS tag/date used.
214   changedir "gcc-${RELEASE}"
215   contrib/gcc_update --touch
216   echo "Obtained from SVN: ${EXPORTTAG} ${EXPORTDATE}" > LAST_UPDATED
217
218   # Obtain some documentation files from the wwwdocs module.
219   inform "Retrieving HTML documentation"
220   changedir "${WORKING_DIRECTORY}"
221   for x in bugs faq; do
222     (${CVS} export -r HEAD wwwdocs/htdocs/${x}.html && \
223      cp ${WORKING_DIRECTORY}/wwwdocs/htdocs/${x}.html \
224         ${SOURCE_DIRECTORY}) || \
225       error "Could not retrieve ${x}.html"
226   done
227
228   inform "Generating plain-text documentation from HTML"
229   changedir "${SOURCE_DIRECTORY}"
230   for file in *.html; do
231     newfile=`echo $file | sed -e 's/.html//' | tr "[:lower:]" "[:upper:]"`
232     (${ENV} TERM=vt100 lynx -dump $file \
233        | sed -e "s#file://localhost`/bin/pwd`\(.*\)#http://gcc.gnu.org\1#g" \
234        > $newfile) || \
235      error "Could not generate text-only version of ${file}"
236   done
237
238   # For a prerelease or real release, we need to generate additional
239   # files not present in SVN.
240   changedir "${SOURCE_DIRECTORY}"
241   if [ $SNAPSHOT -ne 1 ]; then
242     # Generate the documentation.
243     inform "Building install docs"
244     SOURCEDIR=${SOURCE_DIRECTORY}/gcc/doc
245     DESTDIR=${SOURCE_DIRECTORY}/INSTALL
246     export SOURCEDIR
247     export DESTDIR
248     ${SOURCE_DIRECTORY}/gcc/doc/install.texi2html
249
250     # Regenerate the NEWS file.
251     contrib/gennews > NEWS || \
252       error "Could not regenerate NEWS files"
253
254     # Now, we must build the compiler in order to create any generated
255     # files that are supposed to go in the source directory.  This is
256     # also a good sanity check to make sure that the release builds
257     # on at least one platform.
258     inform "Building compiler"
259     OBJECT_DIRECTORY=../objdir
260     contrib/gcc_build -d ${SOURCE_DIRECTORY} -o ${OBJECT_DIRECTORY} \
261       -c "--enable-generated-files-in-srcdir" build || \
262       error "Could not rebuild GCC"
263   fi
264
265   # Move message catalogs to source directory.
266   mv ../objdir/gcc/po/*.gmo gcc/po/
267   [ -f libcpp/po/cpplib.pot ] && mv ../objdir/libcpp/po/*.gmo libcpp/po/
268
269   # Create a "MD5SUMS" file to use for checking the validity of the release.
270   echo \
271 "# This file contains the MD5 checksums of the files in the 
272 # gcc-"${RELEASE}".tar.bz2 tarball.
273 #
274 # Besides verifying that all files in the tarball were correctly expanded,
275 # it also can be used to determine if any files have changed since the
276 # tarball was expanded or to verify that a patchfile was correctly applied.
277 #
278 # Suggested usage:
279 # md5sum -c MD5SUMS | grep -v \"OK$\"
280 " > MD5SUMS
281
282   find . -type f |
283   sed -e 's:^\./::' -e '/MD5SUMS/d' |
284   sort |
285   xargs md5sum >>MD5SUMS
286 }
287
288 # Buid a single tarfile.  The first argument is the name of the name
289 # of the tarfile to build, without any suffixes.  They will be added
290 # automatically.  The rest of the arguments are the files or
291 # directories to include, and possibly other arguments to tar.
292
293 build_tarfile() {
294   # Get the name of the destination tar file.
295   TARFILE="$1.tar.bz2"
296   shift
297
298   # Build the tar file itself.
299   (${TAR} cf - "$@" | ${BZIP2} > ${TARFILE}) || \
300     error "Could not build tarfile"
301   FILE_LIST="${FILE_LIST} ${TARFILE}"
302 }
303
304 # Build a single tarfile if any of the directories listed exist,
305 # but not if none of them do (because that component doesn't exist
306 # on this branch).
307 maybe_build_tarfile() {
308   dest=$1
309   shift
310   dir_exists=0
311   for maybe_dir in "$@"; do
312     if [ -d "$maybe_dir" ]; then
313       dir_exists=1
314     fi
315   done
316   if [ $dir_exists = 1 ]; then
317     build_tarfile "$dest" "$@"
318   else
319     echo "Not building $dest tarfile"
320   fi
321 }
322
323 # Build the various tar files for the release.
324
325 build_tarfiles() {
326   inform "Building tarfiles"
327
328   changedir "${WORKING_DIRECTORY}"
329
330   # The GNU Coding Standards specify that all files should
331   # world readable.
332   chmod -R a+r ${SOURCE_DIRECTORY}
333   # And that all directories have mode 777.
334   find ${SOURCE_DIRECTORY} -type d -exec chmod 777 {} \;
335  
336   # Build one huge tarfile for the entire distribution.
337   build_tarfile gcc-${RELEASE} `basename ${SOURCE_DIRECTORY}`
338
339   # Now, build one for each of the languages.
340   maybe_build_tarfile gcc-ada-${RELEASE} ${ADA_DIRS}
341   maybe_build_tarfile gcc-g++-${RELEASE} ${CPLUSPLUS_DIRS}
342   maybe_build_tarfile gcc-g77-${RELEASE} ${FORTRAN_DIRS}
343   maybe_build_tarfile gcc-fortran-${RELEASE} ${FORTRAN95_DIRS}
344   maybe_build_tarfile gcc-java-${RELEASE} ${JAVA_DIRS}
345   maybe_build_tarfile gcc-objc-${RELEASE} ${OBJECTIVEC_DIRS}
346   maybe_build_tarfile gcc-testsuite-${RELEASE} ${TESTSUITE_DIRS}
347    
348   # The core is everything else.
349   EXCLUDES=""
350   for x in ${ADA_DIRS} ${CPLUSPLUS_DIRS} ${FORTRAN_DIRS} ${FORTRAN95_DIRS}\
351            ${JAVA_DIRS} ${OBJECTIVEC_DIRS} ${TESTSUITE_DIRS}; do
352     EXCLUDES="${EXCLUDES} --exclude $x"
353   done
354   build_tarfile gcc-core-${RELEASE} ${EXCLUDES} \
355     `basename ${SOURCE_DIRECTORY}`
356 }
357
358 # Build .gz files.
359 build_gzip() {
360   for f in ${FILE_LIST}; do
361     target=${f%.bz2}.gz
362     (${BZIP2} -d -c $f | ${GZIP} > ${target}) || error "Could not create ${target}"
363   done
364 }
365
366 # Build diffs against an old release.
367 build_diffs() {
368   old_dir=${1%/*}
369   old_file=${1##*/}
370   old_vers=${old_file%.tar.bz2}
371   old_vers=${old_vers#gcc-}
372   inform "Building diffs against version $old_vers"
373   for f in gcc gcc-ada gcc-g++ gcc-g77 gcc-fortran gcc-java gcc-objc gcc-testsuite gcc-core; do
374     old_tar=${old_dir}/${f}-${old_vers}.tar.bz2
375     new_tar=${WORKING_DIRECTORY}/${f}-${RELEASE}.tar.bz2
376     if [ ! -e $old_tar ]; then
377       inform "$old_tar not found; not generating diff file"
378     elif [ ! -e $new_tar ]; then
379       inform "$new_tar not found; not generating diff file"
380     else
381       build_diff $old_tar gcc-${old_vers} $new_tar gcc-${RELEASE} \
382         ${f}-${old_vers}-${RELEASE}.diff.bz2
383     fi
384   done
385 }
386
387 # Build an individual diff.
388 build_diff() {
389   changedir "${WORKING_DIRECTORY}"
390   tmpdir=gccdiff.$$
391   mkdir $tmpdir || error "Could not create directory $tmpdir"
392   changedir $tmpdir
393   (${BZIP2} -d -c $1 | ${TAR} xf - ) || error "Could not unpack $1 for diffs"
394   (${BZIP2} -d -c $3 | ${TAR} xf - ) || error "Could not unpack $3 for diffs"
395   ${DIFF} $2 $4 > ../${5%.bz2}
396   if [ $? -eq 2 ]; then
397     error "Trouble making diffs from $1 to $3"
398   fi
399   ${BZIP2} ../${5%.bz2} || error "Could not generate ../$5"
400   changedir ..
401   rm -rf $tmpdir
402   FILE_LIST="${FILE_LIST} $5"
403 }
404
405 # Upload the files to the FTP server.
406 upload_files() {
407   inform "Uploading files"
408
409   changedir "${WORKING_DIRECTORY}"
410
411   # Make sure the directory exists on the server.
412   if [ $LOCAL -eq 0 ]; then
413     ${SSH} -l ${GCC_USERNAME} ${GCC_HOSTNAME} \
414       mkdir -p "${FTP_PATH}/diffs"
415     UPLOAD_PATH="${GCC_USERNAME}@${GCC_HOSTNAME}:${FTP_PATH}"
416   else
417     mkdir -p "${FTP_PATH}/diffs" \
418       || error "Could not create \`${FTP_PATH}'"
419     UPLOAD_PATH=${FTP_PATH}
420   fi
421
422   # Then copy files to their respective (sub)directories.
423   for x in gcc*.gz gcc*.bz2; do
424     if [ -e ${x} ]; then
425       # Make sure the file will be readable on the server.
426       chmod a+r ${x}
427       # Copy it.
428       case ${x} in
429         *.diff.*)
430           SUBDIR="diffs/";
431           ;;
432         *)
433           SUBDIR="";
434       esac
435       ${SCP} ${x} ${UPLOAD_PATH}/${SUBDIR} \
436         || error "Could not upload ${x}"
437     fi
438   done
439 }
440
441 #Print description if snapshot exists
442 snapshot_print() {
443   if [ -e ${RELEASE}/$1 ]; then
444      printf "%-38s%s\n\n" "$1" "$2" >> ${SNAPSHOT_README}
445      echo "  <tr><td><a href=\"$1\">$1</a></td>" >> ${SNAPSHOT_INDEX}
446      echo "      <td>$2</td></tr>" >> ${SNAPSHOT_INDEX}
447   fi
448 }
449
450 # Announce a snapshot, both on the web and via mail.
451 announce_snapshot() {
452   inform "Updating links and READMEs on the FTP server"
453   
454   TEXT_DATE=`date --date=$DATE +%B\ %d,\ %Y`
455   SNAPSHOT_README=${RELEASE}/README
456   SNAPSHOT_INDEX=${RELEASE}/index.html
457
458   changedir "${SNAPSHOTS_DIR}"
459   echo \
460 "Snapshot gcc-"${RELEASE}" is now available on
461   ftp://gcc.gnu.org/pub/gcc/snapshots/"${RELEASE}"/
462 and on various mirrors, see http://gcc.gnu.org/mirrors.html for details.
463
464 This snapshot has been generated from the GCC "${BRANCH}" SVN branch
465 with the following options: "${EXPORTTAG} ${EXPORTDATE}"
466
467 You'll find:
468 " > ${SNAPSHOT_README}
469
470   echo \
471 "<html>
472
473 <head>
474 <title>GCC "${RELEASE}" Snapshot</title>
475 </head>
476
477 <body>
478 <h1>GCC "${RELEASE}" Snapshot</h1>
479
480 <p>The <a href =\"http://gcc.gnu.org/\">GCC Project</a> makes
481 periodic snapshots of the GCC source tree available to the public
482 for testing purposes.</p>
483         
484 <p>If you are planning to download and use one of our snapshots, then
485 we highly recommend you join the GCC developers list.  Details for
486 how to sign up can be found on the GCC project home page.</p>
487
488 <p>This snapshot has been generated from the GCC "${BRANCH}" SVN branch
489 with the following options: <code>"svn://gcc.gnu.org/svn/gcc/${EXPORTTAG} ${EXPORTDATE}"</code></p>
490
491 <table>" > ${SNAPSHOT_INDEX}
492        
493   snapshot_print gcc-${RELEASE}.tar.bz2 "Complete GCC (includes all of below)"
494   snapshot_print gcc-core-${RELEASE}.tar.bz2 "C front end and core compiler"
495   snapshot_print gcc-ada-${RELEASE}.tar.bz2 "Ada front end and runtime"
496   snapshot_print gcc-fortran-${RELEASE}.tar.bz2 "Fortran front end and runtime"
497   snapshot_print gcc-g++-${RELEASE}.tar.bz2 "C++ front end and runtime"
498   snapshot_print gcc-g77-${RELEASE}.tar.bz2 "Fortran 77 front end and runtime"
499   snapshot_print gcc-java-${RELEASE}.tar.bz2 "Java front end and runtime"
500   snapshot_print gcc-objc-${RELEASE}.tar.bz2 "Objective-C front end and runtime"
501   snapshot_print gcc-testsuite-${RELEASE}.tar.bz2 "The GCC testsuite"
502
503   echo \
504 "Diffs from "${BRANCH}"-"${LAST_DATE}" are available in the diffs/ subdirectory.
505
506 When a particular snapshot is ready for public consumption the LATEST-"${BRANCH}"
507 link is updated and a message is sent to the gcc list.  Please do not use
508 a snapshot before it has been announced that way." >> ${SNAPSHOT_README}
509
510   echo \
511 "</table>
512 <p>Diffs from "${BRANCH}"-"${LAST_DATE}" are available in the
513 <a href=\"diffs/\">diffs/ subdirectory</a>.</p>
514
515 <p>When a particular snapshot is ready for public consumption the LATEST-"${BRANCH}"
516 link is updated and a message is sent to the gcc list.  Please do not use
517 a snapshot before it has been announced that way.</p>
518
519 <hr />
520
521 <address>
522 <a href=\"mailto:gcc@gcc.gnu.org\">gcc@gcc.gnu.org</a>
523 <br />
524 Last modified "${TEXT_DATE}"
525 </address>
526 </body>
527
528 </html>" >> ${SNAPSHOT_INDEX}
529
530   rm -f LATEST-${BRANCH}
531   ln -s ${RELEASE} LATEST-${BRANCH}
532
533   inform "Sending mail"
534
535   export QMAILHOST=gcc.gnu.org
536   mail -s "gcc-${RELEASE} is now available" gcc@gcc.gnu.org < ${SNAPSHOT_README}
537 }
538
539 ########################################################################
540 # Initialization
541 ########################################################################
542
543 # Today's date.
544 DATE=`date "+%Y%m%d"`
545 LONG_DATE=`date "+%Y-%m-%d"`
546
547 SVN=${SVN:-/usr/bin/svn}
548 # The CVS server containing the GCC repository.
549 SVN_SERVER="gcc.gnu.org"
550 # The path to the repository on that server.
551 SVN_REPOSITORY="/svn/gcc"
552 # The username to use when connecting to the server.
553 SVN_USERNAME="${USER}"
554
555 # The machine to which files will be uploaded.
556 GCC_HOSTNAME="gcc.gnu.org"
557 # The name of the account on the machine to which files are uploaded.
558 GCC_USERNAME="gccadmin"
559 # The directory in which the files will be placed (do not use ~user syntax).
560 FTP_PATH=/var/ftp/pub/gcc
561 # The directory in which snapshots will be placed.
562 SNAPSHOTS_DIR=${FTP_PATH}/snapshots
563
564 # The major number for the release.  For release `3.0.2' this would be 
565 # `3'
566 RELEASE_MAJOR=""
567 # The minor number for the release.  For release `3.0.2' this would be
568 # `0'.
569 RELEASE_MINOR=""
570 # The revision number for the release.  For release `3.0.2' this would
571 # be `2'.
572 RELEASE_REVISION=""
573 # The complete name of the release.
574 RELEASE=""
575
576 # The name of the branch from which the release should be made, in a 
577 # user-friendly form.
578 BRANCH=""
579
580 # The name of the branch from which the release should be made, as used
581 # for our version control system.
582 SVNBRANCH=""
583
584 # The tag to apply to the sources used for the release.
585 TAG=""
586
587 # The old tarballs from which to generate diffs.
588 OLD_TARS=""
589
590 # The directory that will be used to construct the release.  The
591 # release itself will be placed in a subdirectory of this diretory.
592 DESTINATION=${HOME}
593 # The subdirectory.
594 WORKING_DIRECTORY=""
595 # The directory that will contain the GCC sources.
596 SOURCE_DIRECTORY=""
597
598 # The directories that should be part of the various language-specific
599 # tar files.  These are all relative to the top of the source tree.
600 ADA_DIRS="gcc/ada libada gnattools"
601 CPLUSPLUS_DIRS="gcc/cp libstdc++-v3"
602 FORTRAN_DIRS="gcc/f libf2c"
603 FORTRAN95_DIRS="gcc/fortran libgfortran"
604 JAVA_DIRS="gcc/java libjava libffi fastjar zlib boehm-gc"
605 OBJECTIVEC_DIRS="gcc/objc libobjc"
606 TESTSUITE_DIRS="gcc/testsuite"
607
608 # Non-zero if this is the final release, rather than a prerelease.
609 FINAL=0
610
611 # Non-zero if we are building a snapshot, and don't build gcc or
612 # include generated files.
613 SNAPSHOT=0
614
615 # Non-zero if we are running locally on gcc.gnu.org, and use local CVS
616 # and copy directly to the FTP directory.
617 LOCAL=0
618
619 # Major operation modes.
620 MODE_GZIP=0
621 MODE_DIFFS=0
622 MODE_SOURCES=0
623 MODE_TARFILES=0
624 MODE_UPLOAD=0
625
626 # List of archive files generated; used to create .gz files from .bz2.
627 FILE_LIST=""
628
629 # Programs we use.
630
631 BZIP2="${BZIP2:-bzip2}"
632 CVS="${CVS:-cvs -f -Q -z9}"
633 DIFF="${DIFF:-diff -Nrcpad}"
634 ENV="${ENV:-env}"
635 GZIP="${GZIP:-gzip --best}"
636 SCP="${SCP:-scp -p}"
637 SSH="${SSH:-ssh}"
638 TAR="${TAR:-tar}"
639
640 ########################################################################
641 # Command Line Processing
642 ########################################################################
643
644 # Parse the options.
645 while getopts "d:fr:u:t:p:s:l" ARG; do
646     case $ARG in
647     d)    DESTINATION="${OPTARG}";;
648     r)    RELEASE="${OPTARG}";;
649     t)    TAG="${OPTARG}";;
650     u)    SVN_USERNAME="${OPTARG}";;
651     f)    FINAL=1;;
652     s)    SNAPSHOT=1
653           BRANCH=${OPTARG%:*}
654           SVNBRANCH=${OPTARG#*:}
655           ;;
656     l)    LOCAL=1
657           SCP=cp
658           PATH=~:/usr/local/bin:$PATH;;
659     p)    OLD_TARS="${OLD_TARS} ${OPTARG}"
660           if [ ! -f ${OPTARG} ]; then
661             error "-p argument must name a tarball"
662           fi;;
663     \?)   usage;;
664     esac
665 done
666 shift `expr ${OPTIND} - 1`
667
668 # Handle the major modes.
669 while [ $# -ne 0 ]; do
670     case $1 in
671     diffs)    MODE_DIFFS=1;;
672     gzip)     MODE_GZIP=1;;
673     sources)  MODE_SOURCES=1;;
674     tarfiles) MODE_TARFILES=1;;
675     upload)   MODE_UPLOAD=1;;
676     all)      MODE_SOURCES=1; MODE_TARFILES=1; MODE_DIFFS=1; MODE_UPLOAD=1;
677               if [ $SNAPSHOT -ne 1 ]; then
678                 # Only for releases and pre-releases.
679                 MODE_GZIP=1;
680               fi
681               ;;
682     *)        error "Unknown mode $1";;
683     esac
684     shift
685 done
686
687 # Perform consistency checking.
688 if [ ${LOCAL} -eq 0 ] && [ -z ${SVN_USERNAME} ]; then
689   error "No username specified"
690 fi
691
692 if [ ! -d ${DESTINATION} ]; then
693   error "\`${DESTINATION}' is not a directory"
694 fi
695
696 if [ $SNAPSHOT -eq 0 ]; then
697   if [ -z ${RELEASE} ]; then
698     error "No release number specified"
699   fi
700
701   # Compute the major and minor release numbers.
702   RELEASE_MAJOR=`echo $RELEASE | awk --assign FS=. '{ print $1; }'`
703   RELEASE_MINOR=`echo $RELEASE | awk --assign FS=. '{ print $2; }'`
704   RELEASE_REVISION=`echo $RELEASE | awk --assign FS=. '{ print $3; }'`
705
706   if [ -z "${RELEASE_MAJOR}" ] || [ -z "${RELEASE_MINOR}" ]; then
707     error "Release number \`${RELEASE}' is invalid"
708   fi
709
710   # Compute the full name of the release.
711   if [ -z "${RELEASE_REVISION}" ]; then
712     RELEASE="${RELEASE_MAJOR}.${RELEASE_MINOR}"
713   else
714     RELEASE="${RELEASE_MAJOR}.${RELEASE_MINOR}.${RELEASE_REVISION}"
715   fi
716
717   # Compute the name of the branch, which is based solely on the major
718   # and minor release numbers.
719   SVNBRANCH="branches/gcc-${RELEASE_MAJOR}_${RELEASE_MINOR}-branch"
720
721   # If this is not a final release, set various parameters acordingly.
722   if [ ${FINAL} -ne 1 ]; then
723     RELEASE="${RELEASE}-${DATE}"
724     FTP_PATH="${FTP_PATH}/prerelease-${RELEASE}/"
725   else
726     FTP_PATH="${FTP_PATH}/releases/gcc-${RELEASE}/"
727   fi
728 else
729   RELEASE=${BRANCH}-${DATE}
730   FTP_PATH="${FTP_PATH}/snapshots/${RELEASE}"
731   if [ ${SVNBRANCH} != "HEAD" ]; then
732     TAG=tags/gcc-ss-`echo ${RELEASE} | tr '.' '_'`
733   fi
734
735   # If diffs are requested when building locally on gcc.gnu.org, we (usually)
736   # know what the last snapshot date was and take the corresponding tarballs,
737   # unless the user specified tarballs explictly.
738   if [ $MODE_DIFFS -ne 0 ] && [ $LOCAL -ne 0 ] && [ -z "${OLD_TARS}" ]; then
739     LAST_DATE=`cat ~/.snapshot_date-${BRANCH}`
740     OLD_TARS=${SNAPSHOTS_DIR}/${BRANCH}-${LAST_DATE}/gcc-${BRANCH}-${LAST_DATE}.tar.bz2
741   fi
742 fi
743
744 # Compute the name of the WORKING_DIRECTORY and the SOURCE_DIRECTORY.
745 WORKING_DIRECTORY="${DESTINATION}/gcc-${RELEASE}"
746 SOURCE_DIRECTORY="${WORKING_DIRECTORY}/gcc-${RELEASE}"
747
748 # Recompute the names of all the language-specific directories,
749 # relative to the WORKING_DIRECTORY.
750 ADA_DIRS=`adjust_dirs ${ADA_DIRS}`
751 CPLUSPLUS_DIRS=`adjust_dirs ${CPLUSPLUS_DIRS}`
752 FORTRAN_DIRS=`adjust_dirs ${FORTRAN_DIRS}`
753 FORTRAN95_DIRS=`adjust_dirs ${FORTRAN95_DIRS}`
754 JAVA_DIRS=`adjust_dirs ${JAVA_DIRS}`
755 OBJECTIVEC_DIRS=`adjust_dirs ${OBJECTIVEC_DIRS}`
756 TESTSUITE_DIRS=`adjust_dirs ${TESTSUITE_DIRS}`
757
758 # Set up SVNROOT.
759 if [ $LOCAL -eq 0 ]; then
760     SVNROOT="svn://${SVN_USERNAME}@${SVN_SERVER}${SVN_REPOSITORY}"
761 else
762     SVNROOT="file:///svn/gcc"
763     CVSROOT="/cvs/gcc"
764 fi
765 export SVNROOT
766 export CVSROOT
767
768 ########################################################################
769 # Main Program
770 ########################################################################
771
772 # Set the timezone to UTC
773 TZ="UTC0"
774 export TZ
775
776 # Build the source directory.
777
778 if [ $MODE_SOURCES -ne 0 ]; then
779   build_sources
780 fi
781
782 # Build the tar files.
783
784 if [ $MODE_TARFILES -ne 0 ]; then
785   build_tarfiles
786 fi
787
788 # Build diffs
789
790 if [ $MODE_DIFFS -ne 0 ]; then
791   # Possibly build diffs.
792   if [ -n "$OLD_TARS" ]; then
793     for old_tar in $OLD_TARS; do
794       build_diffs $old_tar
795     done
796   fi
797 fi
798
799 # Build gzip files
800 if [ $MODE_GZIP -ne 0 ]; then
801   build_gzip
802 fi
803
804 # Upload them to the FTP server.
805 if [ $MODE_UPLOAD -ne 0 ]; then
806   upload_files
807
808   # For snapshots, make some further updates.
809   if [ $SNAPSHOT -ne 0 ] && [ $LOCAL -ne 0 ]; then
810     announce_snapshot
811
812     # Update snapshot date file.
813     changedir ~
814     echo $DATE > .snapshot_date-${BRANCH}
815
816     # Remove working directory
817     rm -rf ${WORKING_DIRECTORY}
818   fi
819 fi