New test
[official-gcc.git] / contrib / gcc_build
blob7e33982e8222c21ea28ec7590629292c59028252
1 #! /bin/sh
3 ########################################################################
5 # File: gcc_build
6 # Author: Mark Mitchell
7 # Date: 07/10/2000
9 # Contents:
10 # Script to automatically download and build GCC.
12 # Copyright (c) 2000, 2001 Free Software Foundation.
14 # This file is part of GNU CC.
16 # GNU CC 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.
21 # GNU CC 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.
26 # You should have received a copy of the GNU General Public License
27 # along with GNU CC; see the file COPYING. If not, write to
28 # the Free Software Foundation, 59 Temple Place - Suite 330,
29 # Boston, MA 02111-1307, USA.
31 ########################################################################
33 ########################################################################
34 # Notes
35 ########################################################################
37 # If you are using password-based CVS, you must manually log in, and
38 # not log out from, the CVS server before running this script.
40 # You can set the following variables in the environment. They
41 # have no corresponding command-line options because they should
42 # only be needed infrequently:
44 # MAKE The path to `make'.
46 ########################################################################
47 # Functions
48 ########################################################################
50 # Issue the error message given by $1 and exit with a non-zero
51 # exit code.
53 error() {
54 echo "gcc_build: error: $1"
55 exit 1
58 # Issue a usage message explaining how to use this script.
60 usage() {
61 cat <<EOF
62 gcc_build [-c configure_options]
63 [-d destination_directory]
64 [-m make_boot_options]
65 [-o objdir]
66 [-u username]
67 [-p protocol]
68 [-t tarfile]
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 # Set up CVS environment variables
90 cvs_setup() {
91 CVSROOT=":${CVS_PROTOCOL}:${CVS_USERNAME}@"
92 CVSROOT="${CVSROOT}${CVS_SERVER}:${CVS_REPOSITORY}"
93 export CVSROOT
96 # Checkout a fresh copy of the GCC build tree.
98 checkout_gcc() {
99 # Tell CVS where to find everything.
100 cvs_setup
102 # If the destination already exists, don't risk destroying it.
103 test -e ${DESTINATION} && \
104 error "${DESTINATION} already exists"
106 # CVS doesn't allow an absolute path for the destination directory.
107 DESTINATION_PARENT=`dirname ${DESTINATION}`
108 test -d ${DESTINATION_PARENT} || \
109 error "${DESTINATION_PARENT} is not a directory"
110 changedir ${DESTINATION_PARENT}
112 # Checkout the tree
113 cvs -z 9 co -d `basename ${DESTINATION}` gcc || \
114 error "Could not check out GCC"
117 # Update GCC.
119 update_gcc() {
120 # Tell CVS where to find everything
121 cvs_setup
123 # If the destination does not already exist, complain.
124 test -d ${DESTINATION} || \
125 error "{$DESTINATION} does not exist"
126 # Enter the destination directory.
127 changedir ${DESTINATION}
129 # Update the tree
130 ./contrib/gcc_update -d || \
131 error "Could not update GCC"
134 # Configure for a build of GCC.
136 configure_gcc() {
137 # Go to the source directory.
138 changedir ${DESTINATION}
140 # Remove the object directory.
141 rm -rf ${OBJDIR}
142 # Create it again.
143 mkdir ${OBJDIR} || \
144 error "Could not create ${OBJDIR}"
145 # Enter it.
146 changedir ${OBJDIR}
148 # Configure the tree.
149 eval ${DESTINATION}/configure ${CONFIGURE_OPTIONS} || \
150 error "Could not configure the compiler"
153 # Bootstrap GCC. Assume configuration has already occurred.
155 bootstrap_gcc() {
156 # Go to the source directory.
157 changedir ${DESTINATION}
158 # Go to the object directory.
159 changedir ${OBJDIR}
161 # Bootstrap the compiler
162 eval ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap || \
163 error "Could not bootstrap the compiler"
166 # Test GCC.
168 test_gcc() {
169 # Go to the source directory.
170 changedir ${DESTINATION}
171 # Go to the object directory.
172 changedir ${OBJDIR}
174 echo "Running tests... This will take a while."
175 ${MAKE} -k check
176 ${DESTINATION}/contrib/test_summary
179 # Export the GCC source tree.
181 export_gcc() {
182 # Go to the source directory.
183 changedir ${DESTINATION}
184 # Go up one level.
185 changedir ..
186 # Build a tarball of the source directory.
187 tar czf ${TARFILE} \
188 --exclude=${OBJDIR} \
189 --exclude=CVS \
190 --exclude='.#*' \
191 --exclude='*~' \
192 `basename ${DESTINATION}`
195 # Install GCC.
197 install_gcc() {
198 # Go to the source directory.
199 changedir ${DESTINATION}
200 # Go to the object directory.
201 changedir ${OBJDIR}
203 ${MAKE} install || error "Installation failed"
206 ########################################################################
207 # Initialization
208 ########################################################################
210 # The CVS server containing the GCC repository.
211 CVS_SERVER="gcc.gnu.org"
212 # The path to the repository on that server.
213 CVS_REPOSITORY="/cvs/gcc"
214 # The CVS protocol to use.
215 CVS_PROTOCOL="pserver"
216 # The username to use when connecting to the server.
217 CVS_USERNAME="anoncvs"
219 # The directory where the checked out GCC will be placed.
220 DESTINATION="${HOME}/dev/gcc"
221 # The relative path from the top of the source tree to the
222 # object directory.
223 OBJDIR="objdir"
225 # The file where the tarred up sources will be placed.
226 TARFILE="${HOME}/dev/gcc.tgz"
228 # Options to pass to configure.
229 CONFIGURE_OPTIONS=
230 # The `make' program.
231 MAKE=${MAKE:-make}
232 # Options to pass to make.
233 MAKE_BOOTSTRAP_OPTIONS=
235 # Modes of operation
236 BOOTSTRAP=0
237 CHECKOUT=0
238 CONFIGURE=0
239 EXPORT=0
240 INSTALL=0
241 TEST=0
242 UPDATE=0
244 ########################################################################
245 # Main Program
246 ########################################################################
248 # Parse the options.
249 while getopts "c:d:m:o:p:t:u:" ARG; do
250 case $ARG in
251 c) CONFIGURE_OPTIONS="${OPTARG}";;
252 d) DESTINATION="${OPTARG}";;
253 m) MAKE_BOOTSTRAP_OPTIONS="${OPTARG}";;
254 o) OBJDIR="${OPTARG}";;
255 p) CVS_PROTOCOL="${OPTARG}";;
256 t) CVS_TARGFILE="${OPTARG}";;
257 u) CVS_USERNAME="${OPTARG}";;
258 \?) usage;;
259 esac
260 done
261 shift `expr ${OPTIND} - 1`
263 # Handle the major modes.
264 while [ $# -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 *) usage;;
275 esac
276 shift
277 done
279 # Check the arguments for sanity.
280 if [ ${CHECKOUT} -ne 0 ] && [ ${UPDATE} -ne 0 ]; then
281 error "Cannot checkout and update simultaneously"
284 # Checkout the tree.
285 if [ ${CHECKOUT} -ne 0 ]; then
286 checkout_gcc
287 elif [ ${UPDATE} -ne 0 ]; then
288 update_gcc
291 # Configure to build the tree.
292 if [ ${CONFIGURE} -ne 0 ]; then
293 configure_gcc
296 # Bootstrap the compiler.
297 if [ ${BOOTSTRAP} -ne 0 ]; then
298 bootstrap_gcc
301 # Test the compiler
302 if [ ${TEST} -ne 0 ]; then
303 test_gcc
306 # Install the compiler.
307 if [ ${INSTALL} -ne 0 ]; then
308 install_gcc
311 # Export the sources
312 if [ ${EXPORT} -ne 0 ]; then
313 export_gcc