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