]>
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 | # | |
47816305 | 12 | # Copyright (c) 2000, 2001 Free Software Foundation. |
b9faa6b6 MM |
13 | # |
14 | # This file is part of GNU CC. | |
15 | # | |
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. | |
20 | # | |
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. | |
25 | # | |
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. | |
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] | |
37ac3c7f | 69 | [bootstrap] |
b9faa6b6 MM |
70 | [build] |
71 | [checkout] | |
37ac3c7f | 72 | [configure] |
b9faa6b6 MM |
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 | # Set up CVS environment variables | |
89 | ||
90 | cvs_setup() { | |
91 | CVSROOT=":${CVS_PROTOCOL}:${CVS_USERNAME}@" | |
92 | CVSROOT="${CVSROOT}${CVS_SERVER}:${CVS_REPOSITORY}" | |
93 | export CVSROOT | |
94 | } | |
95 | ||
96 | # Checkout a fresh copy of the GCC build tree. | |
97 | ||
98 | checkout_gcc() { | |
99 | # Tell CVS where to find everything. | |
100 | cvs_setup | |
101 | ||
102 | # If the destination already exists, don't risk destroying it. | |
103 | test -e ${DESTINATION} && \ | |
104 | error "${DESTINATION} already exists" | |
105 | ||
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} | |
111 | ||
112 | # Checkout the tree | |
113 | cvs -z 9 co -d `basename ${DESTINATION}` gcc || \ | |
114 | error "Could not check out GCC" | |
115 | } | |
116 | ||
117 | # Update GCC. | |
118 | ||
119 | update_gcc() { | |
120 | # Tell CVS where to find everything | |
121 | cvs_setup | |
122 | ||
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} | |
128 | ||
129 | # Update the tree | |
47816305 | 130 | ./contrib/gcc_update -d || \ |
b9faa6b6 MM |
131 | error "Could not update GCC" |
132 | } | |
133 | ||
37ac3c7f | 134 | # Configure for a build of GCC. |
b9faa6b6 | 135 | |
37ac3c7f | 136 | configure_gcc() { |
b9faa6b6 MM |
137 | # Go to the source directory. |
138 | changedir ${DESTINATION} | |
139 | ||
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} | |
147 | ||
148 | # Configure the tree. | |
72e0bae5 | 149 | echo "Configuring: ${DESTINATION}/configure ${CONFIGURE_OPTIONS}" |
c132c0e3 | 150 | eval ${DESTINATION}/configure ${CONFIGURE_OPTIONS} || \ |
37ac3c7f JO |
151 | error "Could not configure the compiler" |
152 | } | |
153 | ||
154 | # Bootstrap GCC. Assume configuration has already occurred. | |
155 | ||
156 | bootstrap_gcc() { | |
157 | # Go to the source directory. | |
158 | changedir ${DESTINATION} | |
159 | # Go to the object directory. | |
160 | changedir ${OBJDIR} | |
b9faa6b6 MM |
161 | |
162 | # Bootstrap the compiler | |
72e0bae5 | 163 | echo "Building: ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap" |
c132c0e3 | 164 | eval ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap || \ |
37ac3c7f | 165 | error "Could not bootstrap the compiler" |
b9faa6b6 MM |
166 | } |
167 | ||
168 | # Test GCC. | |
169 | ||
170 | test_gcc() { | |
171 | # Go to the source directory. | |
172 | changedir ${DESTINATION} | |
173 | # Go to the object directory. | |
174 | changedir ${OBJDIR} | |
175 | ||
176 | echo "Running tests... This will take a while." | |
c132c0e3 MM |
177 | ${MAKE} -k check |
178 | ${DESTINATION}/contrib/test_summary | |
b9faa6b6 MM |
179 | } |
180 | ||
181 | # Export the GCC source tree. | |
182 | ||
183 | export_gcc() { | |
184 | # Go to the source directory. | |
185 | changedir ${DESTINATION} | |
186 | # Go up one level. | |
187 | changedir .. | |
59c341cb | 188 | # Build a tarball of the source directory. |
b9faa6b6 MM |
189 | tar czf ${TARFILE} \ |
190 | --exclude=${OBJDIR} \ | |
191 | --exclude=CVS \ | |
192 | --exclude='.#*' \ | |
193 | --exclude='*~' \ | |
194 | `basename ${DESTINATION}` | |
195 | } | |
196 | ||
197 | # Install GCC. | |
198 | ||
199 | install_gcc() { | |
200 | # Go to the source directory. | |
201 | changedir ${DESTINATION} | |
202 | # Go to the object directory. | |
203 | changedir ${OBJDIR} | |
204 | ||
c132c0e3 | 205 | ${MAKE} install || error "Installation failed" |
b9faa6b6 MM |
206 | } |
207 | ||
208 | ######################################################################## | |
209 | # Initialization | |
210 | ######################################################################## | |
211 | ||
212 | # The CVS server containing the GCC repository. | |
213 | CVS_SERVER="gcc.gnu.org" | |
214 | # The path to the repository on that server. | |
215 | CVS_REPOSITORY="/cvs/gcc" | |
216 | # The CVS protocol to use. | |
217 | CVS_PROTOCOL="pserver" | |
218 | # The username to use when connecting to the server. | |
219 | CVS_USERNAME="anoncvs" | |
220 | ||
221 | # The directory where the checked out GCC will be placed. | |
222 | DESTINATION="${HOME}/dev/gcc" | |
223 | # The relative path from the top of the source tree to the | |
224 | # object directory. | |
225 | OBJDIR="objdir" | |
226 | ||
b9faa6b6 MM |
227 | # The file where the tarred up sources will be placed. |
228 | TARFILE="${HOME}/dev/gcc.tgz" | |
229 | ||
230 | # Options to pass to configure. | |
231 | CONFIGURE_OPTIONS= | |
9f56c004 MM |
232 | # The `make' program. |
233 | MAKE=${MAKE:-make} | |
b9faa6b6 | 234 | # Options to pass to make. |
37ac3c7f | 235 | MAKE_BOOTSTRAP_OPTIONS= |
b9faa6b6 MM |
236 | |
237 | # Modes of operation | |
37ac3c7f | 238 | BOOTSTRAP=0 |
b9faa6b6 | 239 | CHECKOUT=0 |
37ac3c7f | 240 | CONFIGURE=0 |
b9faa6b6 MM |
241 | EXPORT=0 |
242 | INSTALL=0 | |
243 | TEST=0 | |
244 | UPDATE=0 | |
245 | ||
246 | ######################################################################## | |
247 | # Main Program | |
248 | ######################################################################## | |
249 | ||
250 | # Parse the options. | |
8a3d997e | 251 | while getopts "c:d:m:o:p:t:u:" ARG; do |
b9faa6b6 MM |
252 | case $ARG in |
253 | c) CONFIGURE_OPTIONS="${OPTARG}";; | |
254 | d) DESTINATION="${OPTARG}";; | |
37ac3c7f | 255 | m) MAKE_BOOTSTRAP_OPTIONS="${OPTARG}";; |
8a3d997e | 256 | o) OBJDIR="${OPTARG}";; |
b9faa6b6 MM |
257 | p) CVS_PROTOCOL="${OPTARG}";; |
258 | t) CVS_TARGFILE="${OPTARG}";; | |
59c341cb | 259 | u) CVS_USERNAME="${OPTARG}";; |
b9faa6b6 MM |
260 | \?) usage;; |
261 | esac | |
262 | done | |
263 | shift `expr ${OPTIND} - 1` | |
264 | ||
265 | # Handle the major modes. | |
266 | while [ $# -ne 0 ]; do | |
267 | case $1 in | |
37ac3c7f JO |
268 | bootstrap) BOOTSTRAP=1;; |
269 | build) CONFIGURE=1; BOOTSTRAP=1;; | |
b9faa6b6 | 270 | checkout) CHECKOUT=1;; |
37ac3c7f | 271 | configure) CONFIGURE=1;; |
b9faa6b6 MM |
272 | export) EXPORT=1;; |
273 | install) INSTALL=1;; | |
274 | test) TEST=1;; | |
275 | update) UPDATE=1;; | |
276 | *) usage;; | |
277 | esac | |
278 | shift | |
279 | done | |
280 | ||
281 | # Check the arguments for sanity. | |
282 | if [ ${CHECKOUT} -ne 0 ] && [ ${UPDATE} -ne 0 ]; then | |
283 | error "Cannot checkout and update simultaneously" | |
284 | fi | |
285 | ||
b9faa6b6 MM |
286 | # Checkout the tree. |
287 | if [ ${CHECKOUT} -ne 0 ]; then | |
288 | checkout_gcc | |
289 | elif [ ${UPDATE} -ne 0 ]; then | |
290 | update_gcc | |
291 | fi | |
292 | ||
37ac3c7f JO |
293 | # Configure to build the tree. |
294 | if [ ${CONFIGURE} -ne 0 ]; then | |
295 | configure_gcc | |
296 | fi | |
297 | ||
298 | # Bootstrap the compiler. | |
299 | if [ ${BOOTSTRAP} -ne 0 ]; then | |
300 | bootstrap_gcc | |
b9faa6b6 MM |
301 | fi |
302 | ||
303 | # Test the compiler | |
304 | if [ ${TEST} -ne 0 ]; then | |
305 | test_gcc | |
306 | fi | |
307 | ||
308 | # Install the compiler. | |
309 | if [ ${INSTALL} -ne 0 ]; then | |
310 | install_gcc | |
311 | fi | |
312 | ||
313 | # Export the sources | |
314 | if [ ${EXPORT} -ne 0 ]; then | |
315 | export_gcc | |
316 | fi |