* gfortran.texi: Update contributors.
[official-gcc.git] / contrib / gcc_build
blob91091ed43a5ea6ba3ea48476f988f48b19d848c7
1 #! /bin/sh
3 ########################################################################
5 # File: gcc_build
6 # Author: Mark Mitchell
7 # Date: 2000-07-10
9 # Adapted to Subversion by Ben Elliston <bje@au.ibm.com>, 2005-07-14.
11 # Contents:
12 # Script to automatically download and build GCC.
14 # Copyright (c) 2000, 2001, 2003, 2005 Free Software Foundation.
16 # This file is part of GCC.
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 2, or (at your option)
21 # any later version.
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.
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.
33 ########################################################################
35 ########################################################################
36 # Notes
37 ########################################################################
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:
43 # MAKE The path to `make'.
45 ########################################################################
46 # Functions
47 ########################################################################
49 # Issue the error message given by $1 and exit with a non-zero
50 # exit code.
52 error() {
53 echo "gcc_build: error: $1"
54 exit 1
57 # Issue a usage message explaining how to use this script.
59 usage() {
60 cat <<EOF
61 gcc_build [-c configure_options]
62 [-d destination_directory]
63 [-m make_boot_options]
64 [-o objdir]
65 [-u username]
66 [-p protocol]
67 [-t tarfile]
68 [-x make_check_options]
69 [bootstrap]
70 [build]
71 [checkout]
72 [configure]
73 [export]
74 [install]
75 [test]
76 [update]
77 EOF
78 exit 1
81 # Change to the directory given by $1.
83 changedir() {
84 cd $1 || \
85 error "Could not change directory to $1"
88 # Checkout a fresh copy of the GCC build tree.
90 checkout_gcc() {
91 # If the destination already exists, don't risk destroying it.
92 test -e ${DESTINATION} && \
93 error "${DESTINATION} already exists"
95 # Checkout the tree
96 test -n "${SVN_USERNAME}" && SVN_USERNAME="${SVN_USERNAME}@"
97 SVNROOT="${SVN_PROTOCOL}://${SVN_USERNAME}${SVN_SERVER}${SVN_REPOSITORY}"
99 $GCC_SVN co $SVNROOT ${DESTINATION} || \
100 error "Could not check out GCC"
103 # Update GCC.
105 update_gcc() {
106 # If the destination does not already exist, complain.
107 test -d ${DESTINATION} || \
108 error "${DESTINATION} does not exist"
110 # Enter the destination directory.
111 changedir ${DESTINATION}
113 # Update the tree
114 ./contrib/gcc_update || \
115 error "Could not update GCC"
118 # Configure for a build of GCC.
120 configure_gcc() {
121 # Go to the source directory.
122 changedir ${DESTINATION}
124 # Remove the object directory.
125 rm -rf ${OBJDIR}
126 # Create it again.
127 mkdir ${OBJDIR} || \
128 error "Could not create ${OBJDIR}"
129 # Enter it.
130 changedir ${OBJDIR}
132 # Configure the tree.
133 echo "Configuring: ${DESTINATION}/configure ${CONFIGURE_OPTIONS}"
134 eval ${DESTINATION}/configure ${CONFIGURE_OPTIONS} || \
135 error "Could not configure the compiler"
138 # Bootstrap GCC. Assume configuration has already occurred.
140 bootstrap_gcc() {
141 # Go to the source directory.
142 changedir ${DESTINATION}
143 # Go to the object directory.
144 changedir ${OBJDIR}
146 # Bootstrap the compiler
147 echo "Building: ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap"
148 eval ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap || \
149 error "Could not bootstrap the compiler"
152 # Test GCC.
154 test_gcc() {
155 # Go to the source directory.
156 changedir ${DESTINATION}
157 # Go to the object directory.
158 changedir ${OBJDIR}
160 echo "Running tests... This will take a while."
161 eval \${MAKE} -k ${MAKE_CHECK_OPTIONS} check
162 ${DESTINATION}/contrib/test_summary
165 # Export the GCC source tree.
167 export_gcc() {
168 # Go to the source directory.
169 changedir ${DESTINATION}
170 # Go up one level.
171 changedir ..
172 # Build a tarball of the source directory.
173 tar czf ${TARFILE} \
174 --exclude=${OBJDIR} \
175 --exclude=.svn \
176 --exclude='.#*' \
177 --exclude='*~' \
178 `basename ${DESTINATION}`
181 # Install GCC.
183 install_gcc() {
184 # Go to the source directory.
185 changedir ${DESTINATION}
186 # Go to the object directory.
187 changedir ${OBJDIR}
189 ${MAKE} install || error "Installation failed"
192 ########################################################################
193 # Initialization
194 ########################################################################
196 # SVN command
197 GCC_SVN=${GCC_SVN-${SVN-svn}}
198 # The SVN server containing the GCC repository.
199 SVN_SERVER="dberlin.org"
200 # The path to the repository on that server.
201 SVN_REPOSITORY="/trunk"
202 # The SVN protocol to use.
203 SVN_PROTOCOL="svn"
204 # The username to use when connecting to the server.
205 # An empty string means anonymous.
206 SVN_USERNAME=""
208 # The directory where the checked out GCC will be placed.
209 DESTINATION="${HOME}/dev/gcc"
210 # The relative path from the top of the source tree to the
211 # object directory.
212 OBJDIR="objdir"
214 # The file where the tarred up sources will be placed.
215 TARFILE="${HOME}/dev/gcc.tgz"
217 # Options to pass to configure.
218 CONFIGURE_OPTIONS=
219 # The `make' program.
220 MAKE=${MAKE:-make}
221 # Options to pass to "make bootstrap".
222 MAKE_BOOTSTRAP_OPTIONS=
223 # Options to pass to "make check".
224 MAKE_CHECK_OPTIONS=
226 # Modes of operation
227 BOOTSTRAP=0
228 CHECKOUT=0
229 CONFIGURE=0
230 EXPORT=0
231 INSTALL=0
232 TEST=0
233 UPDATE=0
235 ########################################################################
236 # Main Program
237 ########################################################################
239 # Issue usage if no parameters are given.
240 test $# -eq 0 && usage
242 # Parse the options.
243 while getopts "c:d:m:o:p:t:u:x:" ARG; do
244 case $ARG in
245 c) CONFIGURE_OPTIONS="${OPTARG}";;
246 d) DESTINATION="${OPTARG}";;
247 m) MAKE_BOOTSTRAP_OPTIONS="${OPTARG}";;
248 o) OBJDIR="${OPTARG}";;
249 p) SVN_PROTOCOL="${OPTARG}";;
250 t) TARFILE="${OPTARG}";;
251 x) MAKE_CHECK_OPTIONS="${OPTARG}";;
252 u) SVN_USERNAME="${OPTARG}";;
253 \?) usage;;
254 esac
255 done
256 shift `expr ${OPTIND} - 1`
258 # Handle the major modes.
259 while [ $# -ne 0 ]; do
260 case $1 in
261 bootstrap) BOOTSTRAP=1;;
262 build) CONFIGURE=1; BOOTSTRAP=1;;
263 checkout) CHECKOUT=1;;
264 configure) CONFIGURE=1;;
265 export) EXPORT=1;;
266 install) INSTALL=1;;
267 test) TEST=1;;
268 update) UPDATE=1;;
269 *) usage;;
270 esac
271 shift
272 done
274 # Check the arguments for sanity.
275 if [ ${CHECKOUT} -ne 0 ] && [ ${UPDATE} -ne 0 ]; then
276 error "Cannot checkout and update simultaneously"
279 # Checkout the tree.
280 if [ ${CHECKOUT} -ne 0 ]; then
281 checkout_gcc
282 elif [ ${UPDATE} -ne 0 ]; then
283 update_gcc
286 # Configure to build the tree.
287 if [ ${CONFIGURE} -ne 0 ]; then
288 configure_gcc
291 # Bootstrap the compiler.
292 if [ ${BOOTSTRAP} -ne 0 ]; then
293 bootstrap_gcc
296 # Test the compiler
297 if [ ${TEST} -ne 0 ]; then
298 test_gcc
301 # Install the compiler.
302 if [ ${INSTALL} -ne 0 ]; then
303 install_gcc
306 # Export the sources
307 if [ ${EXPORT} -ne 0 ]; then
308 export_gcc