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