OSDN Git Service

2005-10-28 Daniel Berlin <dberlin@dberlin.org>
[pf3gnuchains/gcc-fork.git] / contrib / gcc_build
1 #! /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 <bje@au.ibm.com>, 2005-07-14.
10 #
11 # Contents:
12 #   Script to automatically download and build GCC.
13 #
14 # Copyright (c) 2000, 2001, 2003, 2005 Free Software Foundation.
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 2, 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 error() {
53     echo "gcc_build: error: $1"
54     exit 1
55 }
56
57 # Issue a usage message explaining how to use this script.
58
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
79 }
80
81 # Change to the directory given by $1.
82
83 changedir() {
84     cd $1 || \
85         error "Could not change directory to $1"
86 }
87
88 # Checkout a fresh copy of the GCC build tree.
89
90 checkout_gcc() {
91     # If the destination already exists, don't risk destroying it.
92     test -e ${DESTINATION} && \
93         error "${DESTINATION} already exists"
94
95     # Checkout the tree
96     test -n "${SVN_USERNAME}" && SVN_USERNAME="${SVN_USERNAME}@"
97     SVNROOT="${SVN_PROTOCOL}://${SVN_USERNAME}${SVN_SERVER}${SVN_REPOSITORY}"
98
99     $GCC_SVN co $SVNROOT ${DESTINATION} || \
100         error "Could not check out GCC"
101 }
102
103 # Update GCC.
104
105 update_gcc() {
106     # If the destination does not already exist, complain.
107     test -d ${DESTINATION} || \
108         error "${DESTINATION} does not exist"
109
110     # Enter the destination directory.
111     changedir ${DESTINATION}
112
113     # Update the tree
114     ./contrib/gcc_update -d || \
115         error "Could not update GCC"
116 }
117
118 # Configure for a build of GCC.
119
120 configure_gcc() {
121     # Go to the source directory.
122     changedir ${DESTINATION}
123
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}
131
132     # Configure the tree.
133     echo "Configuring: ${DESTINATION}/configure ${CONFIGURE_OPTIONS}"
134     eval ${DESTINATION}/configure ${CONFIGURE_OPTIONS} || \
135         error "Could not configure the compiler"
136 }
137
138 # Bootstrap GCC.  Assume configuration has already occurred.
139
140 bootstrap_gcc() {
141     # Go to the source directory.
142     changedir ${DESTINATION}
143     # Go to the object directory.
144     changedir ${OBJDIR}
145
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"
150 }
151
152 # Test GCC.
153
154 test_gcc() {
155     # Go to the source directory.
156     changedir ${DESTINATION}
157     # Go to the object directory.
158     changedir ${OBJDIR}
159
160     echo "Running tests...  This will take a while."
161     eval \${MAKE} -k ${MAKE_CHECK_OPTIONS} check
162     ${DESTINATION}/contrib/test_summary
163 }
164
165 # Export the GCC source tree.
166
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}`
179 }
180
181 # Install GCC.
182
183 install_gcc() {
184     # Go to the source directory.
185     changedir ${DESTINATION}
186     # Go to the object directory.
187     changedir ${OBJDIR}
188
189     ${MAKE} install || error "Installation failed"
190 }
191
192 ########################################################################
193 # Initialization
194 ########################################################################
195
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=""
207
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"
213
214 # The file where the tarred up sources will be placed.
215 TARFILE="${HOME}/dev/gcc.tgz"
216
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=
225
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
234
235 ########################################################################
236 # Main Program
237 ########################################################################
238
239 # Issue usage if no parameters are given.
240 test $# -eq 0 && usage
241
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`
257
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
273
274 # Check the arguments for sanity.
275 if [ ${CHECKOUT} -ne 0 ] && [ ${UPDATE} -ne 0 ]; then
276     error "Cannot checkout and update simultaneously"
277 fi
278
279 # Checkout the tree.
280 if [ ${CHECKOUT} -ne 0 ]; then
281     checkout_gcc
282 elif [ ${UPDATE} -ne 0 ]; then
283     update_gcc
284 fi
285
286 # Configure to build the tree.
287 if [ ${CONFIGURE} -ne 0 ]; then
288     configure_gcc
289 fi
290
291 # Bootstrap the compiler.
292 if [ ${BOOTSTRAP} -ne 0 ]; then
293     bootstrap_gcc
294 fi
295
296 # Test the compiler
297 if [ ${TEST} -ne 0 ]; then
298     test_gcc
299 fi
300
301 # Install the compiler.
302 if [ ${INSTALL} -ne 0 ]; then
303     install_gcc
304 fi
305
306 # Export the sources
307 if [ ${EXPORT} -ne 0 ]; then
308     export_gcc
309 fi