]>
Commit | Line | Data |
---|---|---|
b9faa6b6 MM |
1 | #! /bin/sh |
2 | ||
3 | ######################################################################## | |
4 | # | |
96eab8e2 | 5 | # File: gcc_build |
b9faa6b6 MM |
6 | # Author: Mark Mitchell |
7 | # Date: 07/10/2000 | |
8 | # | |
9 | # Contents: | |
10 | # Script to automatically download and build GCC. | |
11 | # | |
487a9427 | 12 | # Copyright (c) 2000, 2001, 2003 Free Software Foundation. |
b9faa6b6 | 13 | # |
487a9427 | 14 | # This file is part of GCC. |
b9faa6b6 | 15 | # |
487a9427 | 16 | # GCC is free software; you can redistribute it and/or modify |
b9faa6b6 MM |
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. | |
20 | # | |
487a9427 | 21 | # GCC is distributed in the hope that it will be useful, |
b9faa6b6 MM |
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. | |
25 | # | |
26 | # You should have received a copy of the GNU General Public License | |
487a9427 | 27 | # along with GCC; see the file COPYING. If not, write to |
b9faa6b6 MM |
28 | # the Free Software Foundation, 59 Temple Place - Suite 330, |
29 | # Boston, MA 02111-1307, USA. | |
30 | # | |
31 | ######################################################################## | |
32 | ||
33 | ######################################################################## | |
34 | # Notes | |
35 | ######################################################################## | |
36 | ||
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. | |
39 | ||
9f56c004 MM |
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: | |
43 | # | |
44 | # MAKE The path to `make'. | |
45 | ||
b9faa6b6 MM |
46 | ######################################################################## |
47 | # Functions | |
48 | ######################################################################## | |
49 | ||
50 | # Issue the error message given by $1 and exit with a non-zero | |
51 | # exit code. | |
52 | ||
53 | error() { | |
90b65165 | 54 | echo "gcc_build: error: $1" |
b9faa6b6 MM |
55 | exit 1 |
56 | } | |
57 | ||
58 | # Issue a usage message explaining how to use this script. | |
59 | ||
60 | usage() { | |
61 | cat <<EOF | |
90b65165 | 62 | gcc_build [-c configure_options] |
b9faa6b6 | 63 | [-d destination_directory] |
37ac3c7f | 64 | [-m make_boot_options] |
8a3d997e | 65 | [-o objdir] |
b9faa6b6 MM |
66 | [-u username] |
67 | [-p protocol] | |
68 | [-t tarfile] | |
9d3d50d2 | 69 | [-x make_check_options] |
37ac3c7f | 70 | [bootstrap] |
b9faa6b6 MM |
71 | [build] |
72 | [checkout] | |
37ac3c7f | 73 | [configure] |
b9faa6b6 MM |
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 | changedir() { | |
85 | cd $1 || \ | |
86 | error "Could not change directory to $1" | |
87 | } | |
88 | ||
89 | # Set up CVS environment variables | |
90 | ||
91 | cvs_setup() { | |
92 | CVSROOT=":${CVS_PROTOCOL}:${CVS_USERNAME}@" | |
93 | CVSROOT="${CVSROOT}${CVS_SERVER}:${CVS_REPOSITORY}" | |
94 | export CVSROOT | |
95 | } | |
96 | ||
97 | # Checkout a fresh copy of the GCC build tree. | |
98 | ||
99 | checkout_gcc() { | |
100 | # Tell CVS where to find everything. | |
101 | cvs_setup | |
102 | ||
103 | # If the destination already exists, don't risk destroying it. | |
104 | test -e ${DESTINATION} && \ | |
105 | error "${DESTINATION} already exists" | |
106 | ||
107 | # CVS doesn't allow an absolute path for the destination directory. | |
108 | DESTINATION_PARENT=`dirname ${DESTINATION}` | |
109 | test -d ${DESTINATION_PARENT} || \ | |
110 | error "${DESTINATION_PARENT} is not a directory" | |
111 | changedir ${DESTINATION_PARENT} | |
112 | ||
113 | # Checkout the tree | |
b47d9efd | 114 | $GCC_CVS -z 9 co -d `basename ${DESTINATION}` gcc || \ |
b9faa6b6 MM |
115 | error "Could not check out GCC" |
116 | } | |
117 | ||
118 | # Update GCC. | |
119 | ||
120 | update_gcc() { | |
121 | # Tell CVS where to find everything | |
122 | cvs_setup | |
123 | ||
124 | # If the destination does not already exist, complain. | |
125 | test -d ${DESTINATION} || \ | |
126 | error "{$DESTINATION} does not exist" | |
127 | # Enter the destination directory. | |
128 | changedir ${DESTINATION} | |
129 | ||
130 | # Update the tree | |
47816305 | 131 | ./contrib/gcc_update -d || \ |
b9faa6b6 MM |
132 | error "Could not update GCC" |
133 | } | |
134 | ||
37ac3c7f | 135 | # Configure for a build of GCC. |
b9faa6b6 | 136 | |
37ac3c7f | 137 | configure_gcc() { |
b9faa6b6 MM |
138 | # Go to the source directory. |
139 | changedir ${DESTINATION} | |
140 | ||
141 | # Remove the object directory. | |
142 | rm -rf ${OBJDIR} | |
143 | # Create it again. | |
144 | mkdir ${OBJDIR} || \ | |
145 | error "Could not create ${OBJDIR}" | |
146 | # Enter it. | |
147 | changedir ${OBJDIR} | |
148 | ||
149 | # Configure the tree. | |
72e0bae5 | 150 | echo "Configuring: ${DESTINATION}/configure ${CONFIGURE_OPTIONS}" |
c132c0e3 | 151 | eval ${DESTINATION}/configure ${CONFIGURE_OPTIONS} || \ |
37ac3c7f JO |
152 | error "Could not configure the compiler" |
153 | } | |
154 | ||
155 | # Bootstrap GCC. Assume configuration has already occurred. | |
156 | ||
157 | bootstrap_gcc() { | |
158 | # Go to the source directory. | |
159 | changedir ${DESTINATION} | |
160 | # Go to the object directory. | |
161 | changedir ${OBJDIR} | |
b9faa6b6 MM |
162 | |
163 | # Bootstrap the compiler | |
72e0bae5 | 164 | echo "Building: ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap" |
c132c0e3 | 165 | eval ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap || \ |
37ac3c7f | 166 | error "Could not bootstrap the compiler" |
b9faa6b6 MM |
167 | } |
168 | ||
169 | # Test GCC. | |
170 | ||
171 | test_gcc() { | |
172 | # Go to the source directory. | |
173 | changedir ${DESTINATION} | |
174 | # Go to the object directory. | |
175 | changedir ${OBJDIR} | |
176 | ||
177 | echo "Running tests... This will take a while." | |
9d3d50d2 | 178 | eval \${MAKE} -k ${MAKE_CHECK_OPTIONS} check |
c132c0e3 | 179 | ${DESTINATION}/contrib/test_summary |
b9faa6b6 MM |
180 | } |
181 | ||
182 | # Export the GCC source tree. | |
183 | ||
184 | export_gcc() { | |
185 | # Go to the source directory. | |
186 | changedir ${DESTINATION} | |
187 | # Go up one level. | |
188 | changedir .. | |
59c341cb | 189 | # Build a tarball of the source directory. |
b9faa6b6 MM |
190 | tar czf ${TARFILE} \ |
191 | --exclude=${OBJDIR} \ | |
192 | --exclude=CVS \ | |
193 | --exclude='.#*' \ | |
194 | --exclude='*~' \ | |
195 | `basename ${DESTINATION}` | |
196 | } | |
197 | ||
198 | # Install GCC. | |
199 | ||
200 | install_gcc() { | |
201 | # Go to the source directory. | |
202 | changedir ${DESTINATION} | |
203 | # Go to the object directory. | |
204 | changedir ${OBJDIR} | |
205 | ||
c132c0e3 | 206 | ${MAKE} install || error "Installation failed" |
b9faa6b6 MM |
207 | } |
208 | ||
209 | ######################################################################## | |
210 | # Initialization | |
211 | ######################################################################## | |
212 | ||
b47d9efd L |
213 | # CVS command |
214 | GCC_CVS=${GCC_CVS-${CVS-cvs}} | |
b9faa6b6 MM |
215 | # The CVS server containing the GCC repository. |
216 | CVS_SERVER="gcc.gnu.org" | |
217 | # The path to the repository on that server. | |
218 | CVS_REPOSITORY="/cvs/gcc" | |
219 | # The CVS protocol to use. | |
220 | CVS_PROTOCOL="pserver" | |
221 | # The username to use when connecting to the server. | |
222 | CVS_USERNAME="anoncvs" | |
223 | ||
224 | # The directory where the checked out GCC will be placed. | |
225 | DESTINATION="${HOME}/dev/gcc" | |
226 | # The relative path from the top of the source tree to the | |
227 | # object directory. | |
228 | OBJDIR="objdir" | |
229 | ||
b9faa6b6 MM |
230 | # The file where the tarred up sources will be placed. |
231 | TARFILE="${HOME}/dev/gcc.tgz" | |
232 | ||
233 | # Options to pass to configure. | |
234 | CONFIGURE_OPTIONS= | |
9f56c004 MM |
235 | # The `make' program. |
236 | MAKE=${MAKE:-make} | |
9d3d50d2 | 237 | # Options to pass to "make bootstrap". |
37ac3c7f | 238 | MAKE_BOOTSTRAP_OPTIONS= |
9d3d50d2 MM |
239 | # Options to pass to "make check". |
240 | MAKE_CHECK_OPTIONS= | |
b9faa6b6 MM |
241 | |
242 | # Modes of operation | |
37ac3c7f | 243 | BOOTSTRAP=0 |
b9faa6b6 | 244 | CHECKOUT=0 |
37ac3c7f | 245 | CONFIGURE=0 |
b9faa6b6 MM |
246 | EXPORT=0 |
247 | INSTALL=0 | |
248 | TEST=0 | |
249 | UPDATE=0 | |
250 | ||
251 | ######################################################################## | |
252 | # Main Program | |
253 | ######################################################################## | |
254 | ||
255 | # Parse the options. | |
9d3d50d2 | 256 | while getopts "c:d:m:o:p:t:u:x:" ARG; do |
b9faa6b6 MM |
257 | case $ARG in |
258 | c) CONFIGURE_OPTIONS="${OPTARG}";; | |
259 | d) DESTINATION="${OPTARG}";; | |
37ac3c7f | 260 | m) MAKE_BOOTSTRAP_OPTIONS="${OPTARG}";; |
8a3d997e | 261 | o) OBJDIR="${OPTARG}";; |
b9faa6b6 | 262 | p) CVS_PROTOCOL="${OPTARG}";; |
9d3d50d2 MM |
263 | t) TARFILE="${OPTARG}";; |
264 | x) MAKE_CHECK_OPTIONS="${OPTARG}";; | |
59c341cb | 265 | u) CVS_USERNAME="${OPTARG}";; |
b9faa6b6 MM |
266 | \?) usage;; |
267 | esac | |
268 | done | |
269 | shift `expr ${OPTIND} - 1` | |
270 | ||
271 | # Handle the major modes. | |
272 | while [ $# -ne 0 ]; do | |
273 | case $1 in | |
37ac3c7f JO |
274 | bootstrap) BOOTSTRAP=1;; |
275 | build) CONFIGURE=1; BOOTSTRAP=1;; | |
b9faa6b6 | 276 | checkout) CHECKOUT=1;; |
37ac3c7f | 277 | configure) CONFIGURE=1;; |
b9faa6b6 MM |
278 | export) EXPORT=1;; |
279 | install) INSTALL=1;; | |
280 | test) TEST=1;; | |
281 | update) UPDATE=1;; | |
282 | *) usage;; | |
283 | esac | |
284 | shift | |
285 | done | |
286 | ||
287 | # Check the arguments for sanity. | |
288 | if [ ${CHECKOUT} -ne 0 ] && [ ${UPDATE} -ne 0 ]; then | |
289 | error "Cannot checkout and update simultaneously" | |
290 | fi | |
291 | ||
b9faa6b6 MM |
292 | # Checkout the tree. |
293 | if [ ${CHECKOUT} -ne 0 ]; then | |
294 | checkout_gcc | |
295 | elif [ ${UPDATE} -ne 0 ]; then | |
296 | update_gcc | |
297 | fi | |
298 | ||
37ac3c7f JO |
299 | # Configure to build the tree. |
300 | if [ ${CONFIGURE} -ne 0 ]; then | |
301 | configure_gcc | |
302 | fi | |
303 | ||
304 | # Bootstrap the compiler. | |
305 | if [ ${BOOTSTRAP} -ne 0 ]; then | |
306 | bootstrap_gcc | |
b9faa6b6 MM |
307 | fi |
308 | ||
309 | # Test the compiler | |
310 | if [ ${TEST} -ne 0 ]; then | |
311 | test_gcc | |
312 | fi | |
313 | ||
314 | # Install the compiler. | |
315 | if [ ${INSTALL} -ne 0 ]; then | |
316 | install_gcc | |
317 | fi | |
318 | ||
319 | # Export the sources | |
320 | if [ ${EXPORT} -ne 0 ]; then | |
321 | export_gcc | |
322 | fi |