Home | History | Annotate | Line # | Download | only in contrib
gcc_build revision 1.1.1.2
      1      1.1  mrg #! /bin/sh
      2      1.1  mrg 
      3      1.1  mrg ########################################################################
      4      1.1  mrg #
      5      1.1  mrg # File:   gcc_build
      6      1.1  mrg # Author: Mark Mitchell
      7      1.1  mrg # Date:   2000-07-10
      8      1.1  mrg #
      9      1.1  mrg # Adapted to Subversion by Ben Elliston <bje (at] au.ibm.com>, 2005-07-14.
     10      1.1  mrg #
     11      1.1  mrg # Contents:
     12      1.1  mrg #   Script to automatically download and build GCC.
     13      1.1  mrg #
     14  1.1.1.2  mrg # Copyright (C) 2000-2024 Free Software Foundation, Inc.
     15      1.1  mrg #
     16      1.1  mrg # This file is part of GCC.
     17      1.1  mrg #
     18      1.1  mrg # GCC is free software; you can redistribute it and/or modify
     19      1.1  mrg # it under the terms of the GNU General Public License as published by
     20      1.1  mrg # the Free Software Foundation; either version 3, or (at your option)
     21      1.1  mrg # any later version.
     22      1.1  mrg #
     23      1.1  mrg # GCC is distributed in the hope that it will be useful,
     24      1.1  mrg # but WITHOUT ANY WARRANTY; without even the implied warranty of
     25      1.1  mrg # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     26      1.1  mrg # GNU General Public License for more details.
     27      1.1  mrg #
     28      1.1  mrg # You should have received a copy of the GNU General Public License
     29      1.1  mrg # along with GCC; see the file COPYING.  If not, write to
     30      1.1  mrg # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
     31      1.1  mrg # Boston, MA 02110-1301, USA.
     32      1.1  mrg #
     33      1.1  mrg ########################################################################
     34      1.1  mrg 
     35      1.1  mrg ########################################################################
     36      1.1  mrg # Notes
     37      1.1  mrg ########################################################################
     38      1.1  mrg 
     39      1.1  mrg # You can set the following variables in the environment.  They 
     40      1.1  mrg # have no corresponding command-line options because they should
     41      1.1  mrg # only be needed infrequently:
     42      1.1  mrg #
     43      1.1  mrg #   MAKE                        The path to `make'.
     44      1.1  mrg 
     45      1.1  mrg ########################################################################
     46      1.1  mrg # Functions
     47      1.1  mrg ########################################################################
     48      1.1  mrg 
     49      1.1  mrg # Issue the error message given by $1 and exit with a non-zero
     50      1.1  mrg # exit code.
     51      1.1  mrg 
     52      1.1  mrg error() {
     53      1.1  mrg     echo "gcc_build: error: $1"
     54      1.1  mrg     exit 1
     55      1.1  mrg }
     56      1.1  mrg 
     57      1.1  mrg # Issue a usage message explaining how to use this script.
     58      1.1  mrg 
     59      1.1  mrg usage() {
     60      1.1  mrg cat <<EOF
     61      1.1  mrg gcc_build        [-c configure_options] 
     62      1.1  mrg 		 [-d destination_directory]
     63      1.1  mrg 		 [-m make_boot_options]
     64      1.1  mrg 		 [-o objdir]
     65      1.1  mrg 		 [-b branch_name]
     66      1.1  mrg 		 [-u username]
     67      1.1  mrg 		 [-p protocol]
     68      1.1  mrg 		 [-t tarfile]
     69      1.1  mrg                  [-x make_check_options]
     70      1.1  mrg 		 [bootstrap]
     71      1.1  mrg 		 [build]
     72      1.1  mrg 		 [checkout]
     73      1.1  mrg 		 [configure]
     74      1.1  mrg 		 [export]
     75      1.1  mrg 		 [install]
     76      1.1  mrg 		 [test]
     77      1.1  mrg 		 [update]
     78      1.1  mrg EOF
     79      1.1  mrg     exit 1
     80      1.1  mrg }
     81      1.1  mrg 
     82      1.1  mrg # Change to the directory given by $1.
     83      1.1  mrg 
     84      1.1  mrg changedir() {
     85      1.1  mrg     cd $1 || \
     86      1.1  mrg 	error "Could not change directory to $1"
     87      1.1  mrg }
     88      1.1  mrg 
     89      1.1  mrg # Checkout a fresh copy of the GCC build tree.
     90      1.1  mrg 
     91      1.1  mrg checkout_gcc() {
     92      1.1  mrg     # If the destination already exists, don't risk destroying it.
     93      1.1  mrg     test -e ${DESTINATION} && \
     94      1.1  mrg 	error "${DESTINATION} already exists"
     95      1.1  mrg 
     96      1.1  mrg     # Checkout the tree
     97      1.1  mrg     test -n "${SVN_USERNAME}" && SVN_USERNAME="${SVN_USERNAME}@"
     98      1.1  mrg     SVNROOT="${SVN_PROTOCOL}://${SVN_USERNAME}${SVN_SERVER}${SVN_REPOSITORY}${SVN_BRANCH}"
     99      1.1  mrg 
    100      1.1  mrg     $GCC_SVN co $SVNROOT ${DESTINATION} || \
    101      1.1  mrg 	error "Could not check out GCC"
    102      1.1  mrg }
    103      1.1  mrg 
    104      1.1  mrg # Update GCC.
    105      1.1  mrg 
    106      1.1  mrg update_gcc() {
    107      1.1  mrg     # If the destination does not already exist, complain.
    108      1.1  mrg     test -d ${DESTINATION} || \
    109      1.1  mrg 	error "${DESTINATION} does not exist"
    110      1.1  mrg 
    111      1.1  mrg     # Enter the destination directory.
    112      1.1  mrg     changedir ${DESTINATION}
    113      1.1  mrg 
    114      1.1  mrg     # Update the tree
    115      1.1  mrg     ./contrib/gcc_update || \
    116      1.1  mrg 	error "Could not update GCC"
    117      1.1  mrg }
    118      1.1  mrg 
    119      1.1  mrg # Configure for a build of GCC.
    120      1.1  mrg 
    121      1.1  mrg configure_gcc() {
    122      1.1  mrg     # Go to the source directory.
    123      1.1  mrg     changedir ${DESTINATION}
    124      1.1  mrg 
    125      1.1  mrg     # Remove the object directory.
    126      1.1  mrg     rm -rf ${OBJDIR}
    127      1.1  mrg     # Create it again.
    128      1.1  mrg     mkdir ${OBJDIR} || \
    129      1.1  mrg 	error "Could not create ${OBJDIR}"
    130      1.1  mrg     # Enter it.
    131      1.1  mrg     changedir ${OBJDIR}
    132      1.1  mrg 
    133      1.1  mrg     # Configure the tree.
    134      1.1  mrg     echo "Configuring: ${DESTINATION}/configure ${CONFIGURE_OPTIONS}"
    135      1.1  mrg     eval ${DESTINATION}/configure ${CONFIGURE_OPTIONS} || \
    136      1.1  mrg 	error "Could not configure the compiler"
    137      1.1  mrg }
    138      1.1  mrg 
    139      1.1  mrg # Bootstrap GCC.  Assume configuration has already occurred.
    140      1.1  mrg 
    141      1.1  mrg bootstrap_gcc() {
    142      1.1  mrg     # Go to the source directory.
    143      1.1  mrg     changedir ${DESTINATION}
    144      1.1  mrg     # Go to the object directory.
    145      1.1  mrg     changedir ${OBJDIR}
    146      1.1  mrg 
    147      1.1  mrg     # Bootstrap the compiler
    148      1.1  mrg     echo "Building: ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap"
    149      1.1  mrg     eval ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap || \
    150      1.1  mrg 	error "Could not bootstrap the compiler"
    151      1.1  mrg }
    152      1.1  mrg 
    153      1.1  mrg # Test GCC.
    154      1.1  mrg 
    155      1.1  mrg test_gcc() {
    156      1.1  mrg     # Go to the source directory.
    157      1.1  mrg     changedir ${DESTINATION}
    158      1.1  mrg     # Go to the object directory.
    159      1.1  mrg     changedir ${OBJDIR}
    160      1.1  mrg 
    161      1.1  mrg     echo "Running tests...  This will take a while."
    162      1.1  mrg     eval \${MAKE} -k ${MAKE_CHECK_OPTIONS} check
    163      1.1  mrg     ${DESTINATION}/contrib/test_summary
    164      1.1  mrg }
    165      1.1  mrg 
    166      1.1  mrg # Export the GCC source tree.
    167      1.1  mrg 
    168      1.1  mrg export_gcc() {
    169      1.1  mrg     # Go to the source directory.
    170      1.1  mrg     changedir ${DESTINATION}
    171      1.1  mrg     # Go up one level.
    172      1.1  mrg     changedir ..
    173      1.1  mrg     # Build a tarball of the source directory.
    174      1.1  mrg     tar czf ${TARFILE} \
    175      1.1  mrg 	--exclude=${OBJDIR} \
    176      1.1  mrg 	--exclude=.svn \
    177      1.1  mrg 	--exclude='.#*' \
    178      1.1  mrg 	--exclude='*~' \
    179      1.1  mrg 	`basename ${DESTINATION}`
    180      1.1  mrg }
    181      1.1  mrg 
    182      1.1  mrg # Install GCC.
    183      1.1  mrg 
    184      1.1  mrg install_gcc() {
    185      1.1  mrg     # Go to the source directory.
    186      1.1  mrg     changedir ${DESTINATION}
    187      1.1  mrg     # Go to the object directory.
    188      1.1  mrg     changedir ${OBJDIR}
    189      1.1  mrg 
    190      1.1  mrg     ${MAKE} install || error "Installation failed"
    191      1.1  mrg }
    192      1.1  mrg 
    193      1.1  mrg ########################################################################
    194      1.1  mrg # Initialization
    195      1.1  mrg ########################################################################
    196      1.1  mrg 
    197      1.1  mrg # SVN command
    198      1.1  mrg GCC_SVN=${GCC_SVN-${SVN-svn}}
    199      1.1  mrg # The SVN server containing the GCC repository.
    200      1.1  mrg SVN_SERVER="gcc.gnu.org"
    201      1.1  mrg # The path to the repository on that server.
    202      1.1  mrg SVN_REPOSITORY="/svn/gcc/"
    203      1.1  mrg # The branch to check out from that server.
    204      1.1  mrg # Defaults to trunk if no branch is defined with -b.
    205      1.1  mrg SVN_BRANCH=""
    206      1.1  mrg # The SVN protocol to use.
    207      1.1  mrg SVN_PROTOCOL="svn"
    208      1.1  mrg # The username to use when connecting to the server.
    209      1.1  mrg # An empty string means anonymous.
    210      1.1  mrg SVN_USERNAME=""
    211      1.1  mrg 
    212      1.1  mrg # The directory where the checked out GCC will be placed.
    213      1.1  mrg DESTINATION="${HOME}/dev/gcc"
    214      1.1  mrg # The relative path from the top of the source tree to the 
    215      1.1  mrg # object directory.
    216      1.1  mrg OBJDIR="objdir"
    217      1.1  mrg 
    218      1.1  mrg # The file where the tarred up sources will be placed.
    219      1.1  mrg TARFILE="${HOME}/dev/gcc.tgz"
    220      1.1  mrg 
    221      1.1  mrg # Options to pass to configure.
    222      1.1  mrg CONFIGURE_OPTIONS=
    223      1.1  mrg # The `make' program.
    224      1.1  mrg MAKE=${MAKE:-make}
    225      1.1  mrg # Options to pass to "make bootstrap".
    226      1.1  mrg MAKE_BOOTSTRAP_OPTIONS=
    227      1.1  mrg # Options to pass to "make check".
    228      1.1  mrg MAKE_CHECK_OPTIONS=
    229      1.1  mrg 
    230      1.1  mrg # Modes of operation
    231      1.1  mrg BOOTSTRAP=0
    232      1.1  mrg CHECKOUT=0
    233      1.1  mrg CONFIGURE=0
    234      1.1  mrg EXPORT=0
    235      1.1  mrg INSTALL=0
    236      1.1  mrg TEST=0
    237      1.1  mrg UPDATE=0
    238      1.1  mrg 
    239      1.1  mrg ########################################################################
    240      1.1  mrg # Main Program
    241      1.1  mrg ########################################################################
    242      1.1  mrg 
    243      1.1  mrg # Issue usage if no parameters are given.
    244      1.1  mrg test $# -eq 0 && usage
    245      1.1  mrg 
    246      1.1  mrg # Parse the options.
    247      1.1  mrg while getopts "c:d:m:o:p:t:b:u:x:" ARG; do
    248      1.1  mrg     case $ARG in
    249      1.1  mrg     c)    CONFIGURE_OPTIONS="${OPTARG}";;
    250      1.1  mrg     d)    DESTINATION="${OPTARG}";;
    251      1.1  mrg     m)    MAKE_BOOTSTRAP_OPTIONS="${OPTARG}";;
    252      1.1  mrg     o)    OBJDIR="${OPTARG}";;
    253      1.1  mrg     p)    SVN_PROTOCOL="${OPTARG}";;
    254      1.1  mrg     t)    TARFILE="${OPTARG}";;
    255      1.1  mrg     x)    MAKE_CHECK_OPTIONS="${OPTARG}";;
    256      1.1  mrg     b)    SVN_BRANCH="${OPTARG}";;
    257      1.1  mrg     u)    SVN_USERNAME="${OPTARG}";;
    258      1.1  mrg     \?)   usage;;
    259      1.1  mrg     esac
    260      1.1  mrg done
    261      1.1  mrg shift `expr ${OPTIND} - 1`
    262      1.1  mrg 
    263      1.1  mrg # Handle the major modes.
    264      1.1  mrg while [ $# -ne 0 ]; do
    265      1.1  mrg     case $1 in
    266      1.1  mrg     bootstrap) BOOTSTRAP=1;;
    267      1.1  mrg     build)    CONFIGURE=1; BOOTSTRAP=1;;
    268      1.1  mrg     checkout) CHECKOUT=1;;
    269      1.1  mrg     configure) CONFIGURE=1;;
    270      1.1  mrg     export)   EXPORT=1;;
    271      1.1  mrg     install)  INSTALL=1;;
    272      1.1  mrg     test)     TEST=1;;
    273      1.1  mrg     update)   UPDATE=1;;
    274      1.1  mrg     *)        usage;;
    275      1.1  mrg     esac
    276      1.1  mrg     shift
    277      1.1  mrg done
    278      1.1  mrg 
    279      1.1  mrg # Check the arguments for sanity.
    280      1.1  mrg if [ ${CHECKOUT} -ne 0 ] && [ ${UPDATE} -ne 0 ]; then
    281      1.1  mrg     error "Cannot checkout and update simultaneously"
    282      1.1  mrg fi
    283      1.1  mrg 
    284      1.1  mrg if [ ${CHECKOUT} -eq 0 ] && test -n "${SVN_BRANCH}"; then
    285      1.1  mrg     error "Branch argument only makes sense when doing a checkout"
    286      1.1  mrg fi
    287      1.1  mrg 
    288      1.1  mrg # Validate the branch name.
    289      1.1  mrg if test -n "${SVN_BRANCH}"; then
    290      1.1  mrg     SVN_BRANCH="branches/${SVN_BRANCH}";
    291      1.1  mrg else
    292      1.1  mrg     SVN_BRANCH="trunk";
    293      1.1  mrg fi
    294      1.1  mrg 
    295      1.1  mrg # Checkout the tree.
    296      1.1  mrg if [ ${CHECKOUT} -ne 0 ]; then
    297      1.1  mrg     checkout_gcc
    298      1.1  mrg elif [ ${UPDATE} -ne 0 ]; then
    299      1.1  mrg     update_gcc
    300      1.1  mrg fi
    301      1.1  mrg 
    302      1.1  mrg # Configure to build the tree.
    303      1.1  mrg if [ ${CONFIGURE} -ne 0 ]; then
    304      1.1  mrg     configure_gcc
    305      1.1  mrg fi
    306      1.1  mrg 
    307      1.1  mrg # Bootstrap the compiler.
    308      1.1  mrg if [ ${BOOTSTRAP} -ne 0 ]; then
    309      1.1  mrg     bootstrap_gcc
    310      1.1  mrg fi
    311      1.1  mrg 
    312      1.1  mrg # Test the compiler
    313      1.1  mrg if [ ${TEST} -ne 0 ]; then
    314      1.1  mrg     test_gcc
    315      1.1  mrg fi
    316      1.1  mrg 
    317      1.1  mrg # Install the compiler.
    318      1.1  mrg if [ ${INSTALL} -ne 0 ]; then
    319      1.1  mrg     install_gcc
    320      1.1  mrg fi
    321      1.1  mrg 
    322      1.1  mrg # Export the sources
    323      1.1  mrg if [ ${EXPORT} -ne 0 ]; then
    324      1.1  mrg     export_gcc
    325      1.1  mrg fi
    326