gcc_build revision 1.1.1.1.4.2 1 1.1.1.1.4.2 yamt #! /bin/sh
2 1.1.1.1.4.2 yamt
3 1.1.1.1.4.2 yamt ########################################################################
4 1.1.1.1.4.2 yamt #
5 1.1.1.1.4.2 yamt # File: gcc_build
6 1.1.1.1.4.2 yamt # Author: Mark Mitchell
7 1.1.1.1.4.2 yamt # Date: 2000-07-10
8 1.1.1.1.4.2 yamt #
9 1.1.1.1.4.2 yamt # Adapted to Subversion by Ben Elliston <bje (at] au.ibm.com>, 2005-07-14.
10 1.1.1.1.4.2 yamt #
11 1.1.1.1.4.2 yamt # Contents:
12 1.1.1.1.4.2 yamt # Script to automatically download and build GCC.
13 1.1.1.1.4.2 yamt #
14 1.1.1.1.4.2 yamt # Copyright (c) 2000, 2001, 2003, 2005 Free Software Foundation.
15 1.1.1.1.4.2 yamt #
16 1.1.1.1.4.2 yamt # This file is part of GCC.
17 1.1.1.1.4.2 yamt #
18 1.1.1.1.4.2 yamt # GCC is free software; you can redistribute it and/or modify
19 1.1.1.1.4.2 yamt # it under the terms of the GNU General Public License as published by
20 1.1.1.1.4.2 yamt # the Free Software Foundation; either version 3, or (at your option)
21 1.1.1.1.4.2 yamt # any later version.
22 1.1.1.1.4.2 yamt #
23 1.1.1.1.4.2 yamt # GCC is distributed in the hope that it will be useful,
24 1.1.1.1.4.2 yamt # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 1.1.1.1.4.2 yamt # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 1.1.1.1.4.2 yamt # GNU General Public License for more details.
27 1.1.1.1.4.2 yamt #
28 1.1.1.1.4.2 yamt # You should have received a copy of the GNU General Public License
29 1.1.1.1.4.2 yamt # along with GCC; see the file COPYING. If not, write to
30 1.1.1.1.4.2 yamt # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
31 1.1.1.1.4.2 yamt # Boston, MA 02110-1301, USA.
32 1.1.1.1.4.2 yamt #
33 1.1.1.1.4.2 yamt ########################################################################
34 1.1.1.1.4.2 yamt
35 1.1.1.1.4.2 yamt ########################################################################
36 1.1.1.1.4.2 yamt # Notes
37 1.1.1.1.4.2 yamt ########################################################################
38 1.1.1.1.4.2 yamt
39 1.1.1.1.4.2 yamt # You can set the following variables in the environment. They
40 1.1.1.1.4.2 yamt # have no corresponding command-line options because they should
41 1.1.1.1.4.2 yamt # only be needed infrequently:
42 1.1.1.1.4.2 yamt #
43 1.1.1.1.4.2 yamt # MAKE The path to `make'.
44 1.1.1.1.4.2 yamt
45 1.1.1.1.4.2 yamt ########################################################################
46 1.1.1.1.4.2 yamt # Functions
47 1.1.1.1.4.2 yamt ########################################################################
48 1.1.1.1.4.2 yamt
49 1.1.1.1.4.2 yamt # Issue the error message given by $1 and exit with a non-zero
50 1.1.1.1.4.2 yamt # exit code.
51 1.1.1.1.4.2 yamt
52 1.1.1.1.4.2 yamt error() {
53 1.1.1.1.4.2 yamt echo "gcc_build: error: $1"
54 1.1.1.1.4.2 yamt exit 1
55 1.1.1.1.4.2 yamt }
56 1.1.1.1.4.2 yamt
57 1.1.1.1.4.2 yamt # Issue a usage message explaining how to use this script.
58 1.1.1.1.4.2 yamt
59 1.1.1.1.4.2 yamt usage() {
60 1.1.1.1.4.2 yamt cat <<EOF
61 1.1.1.1.4.2 yamt gcc_build [-c configure_options]
62 1.1.1.1.4.2 yamt [-d destination_directory]
63 1.1.1.1.4.2 yamt [-m make_boot_options]
64 1.1.1.1.4.2 yamt [-o objdir]
65 1.1.1.1.4.2 yamt [-b branch_name]
66 1.1.1.1.4.2 yamt [-u username]
67 1.1.1.1.4.2 yamt [-p protocol]
68 1.1.1.1.4.2 yamt [-t tarfile]
69 1.1.1.1.4.2 yamt [-x make_check_options]
70 1.1.1.1.4.2 yamt [bootstrap]
71 1.1.1.1.4.2 yamt [build]
72 1.1.1.1.4.2 yamt [checkout]
73 1.1.1.1.4.2 yamt [configure]
74 1.1.1.1.4.2 yamt [export]
75 1.1.1.1.4.2 yamt [install]
76 1.1.1.1.4.2 yamt [test]
77 1.1.1.1.4.2 yamt [update]
78 1.1.1.1.4.2 yamt EOF
79 1.1.1.1.4.2 yamt exit 1
80 1.1.1.1.4.2 yamt }
81 1.1.1.1.4.2 yamt
82 1.1.1.1.4.2 yamt # Change to the directory given by $1.
83 1.1.1.1.4.2 yamt
84 1.1.1.1.4.2 yamt changedir() {
85 1.1.1.1.4.2 yamt cd $1 || \
86 1.1.1.1.4.2 yamt error "Could not change directory to $1"
87 1.1.1.1.4.2 yamt }
88 1.1.1.1.4.2 yamt
89 1.1.1.1.4.2 yamt # Checkout a fresh copy of the GCC build tree.
90 1.1.1.1.4.2 yamt
91 1.1.1.1.4.2 yamt checkout_gcc() {
92 1.1.1.1.4.2 yamt # If the destination already exists, don't risk destroying it.
93 1.1.1.1.4.2 yamt test -e ${DESTINATION} && \
94 1.1.1.1.4.2 yamt error "${DESTINATION} already exists"
95 1.1.1.1.4.2 yamt
96 1.1.1.1.4.2 yamt # Checkout the tree
97 1.1.1.1.4.2 yamt test -n "${SVN_USERNAME}" && SVN_USERNAME="${SVN_USERNAME}@"
98 1.1.1.1.4.2 yamt SVNROOT="${SVN_PROTOCOL}://${SVN_USERNAME}${SVN_SERVER}${SVN_REPOSITORY}${SVN_BRANCH}"
99 1.1.1.1.4.2 yamt
100 1.1.1.1.4.2 yamt $GCC_SVN co $SVNROOT ${DESTINATION} || \
101 1.1.1.1.4.2 yamt error "Could not check out GCC"
102 1.1.1.1.4.2 yamt }
103 1.1.1.1.4.2 yamt
104 1.1.1.1.4.2 yamt # Update GCC.
105 1.1.1.1.4.2 yamt
106 1.1.1.1.4.2 yamt update_gcc() {
107 1.1.1.1.4.2 yamt # If the destination does not already exist, complain.
108 1.1.1.1.4.2 yamt test -d ${DESTINATION} || \
109 1.1.1.1.4.2 yamt error "${DESTINATION} does not exist"
110 1.1.1.1.4.2 yamt
111 1.1.1.1.4.2 yamt # Enter the destination directory.
112 1.1.1.1.4.2 yamt changedir ${DESTINATION}
113 1.1.1.1.4.2 yamt
114 1.1.1.1.4.2 yamt # Update the tree
115 1.1.1.1.4.2 yamt ./contrib/gcc_update || \
116 1.1.1.1.4.2 yamt error "Could not update GCC"
117 1.1.1.1.4.2 yamt }
118 1.1.1.1.4.2 yamt
119 1.1.1.1.4.2 yamt # Configure for a build of GCC.
120 1.1.1.1.4.2 yamt
121 1.1.1.1.4.2 yamt configure_gcc() {
122 1.1.1.1.4.2 yamt # Go to the source directory.
123 1.1.1.1.4.2 yamt changedir ${DESTINATION}
124 1.1.1.1.4.2 yamt
125 1.1.1.1.4.2 yamt # Remove the object directory.
126 1.1.1.1.4.2 yamt rm -rf ${OBJDIR}
127 1.1.1.1.4.2 yamt # Create it again.
128 1.1.1.1.4.2 yamt mkdir ${OBJDIR} || \
129 1.1.1.1.4.2 yamt error "Could not create ${OBJDIR}"
130 1.1.1.1.4.2 yamt # Enter it.
131 1.1.1.1.4.2 yamt changedir ${OBJDIR}
132 1.1.1.1.4.2 yamt
133 1.1.1.1.4.2 yamt # Configure the tree.
134 1.1.1.1.4.2 yamt echo "Configuring: ${DESTINATION}/configure ${CONFIGURE_OPTIONS}"
135 1.1.1.1.4.2 yamt eval ${DESTINATION}/configure ${CONFIGURE_OPTIONS} || \
136 1.1.1.1.4.2 yamt error "Could not configure the compiler"
137 1.1.1.1.4.2 yamt }
138 1.1.1.1.4.2 yamt
139 1.1.1.1.4.2 yamt # Bootstrap GCC. Assume configuration has already occurred.
140 1.1.1.1.4.2 yamt
141 1.1.1.1.4.2 yamt bootstrap_gcc() {
142 1.1.1.1.4.2 yamt # Go to the source directory.
143 1.1.1.1.4.2 yamt changedir ${DESTINATION}
144 1.1.1.1.4.2 yamt # Go to the object directory.
145 1.1.1.1.4.2 yamt changedir ${OBJDIR}
146 1.1.1.1.4.2 yamt
147 1.1.1.1.4.2 yamt # Bootstrap the compiler
148 1.1.1.1.4.2 yamt echo "Building: ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap"
149 1.1.1.1.4.2 yamt eval ${MAKE} ${MAKE_BOOTSTRAP_OPTIONS} bootstrap || \
150 1.1.1.1.4.2 yamt error "Could not bootstrap the compiler"
151 1.1.1.1.4.2 yamt }
152 1.1.1.1.4.2 yamt
153 1.1.1.1.4.2 yamt # Test GCC.
154 1.1.1.1.4.2 yamt
155 1.1.1.1.4.2 yamt test_gcc() {
156 1.1.1.1.4.2 yamt # Go to the source directory.
157 1.1.1.1.4.2 yamt changedir ${DESTINATION}
158 1.1.1.1.4.2 yamt # Go to the object directory.
159 1.1.1.1.4.2 yamt changedir ${OBJDIR}
160 1.1.1.1.4.2 yamt
161 1.1.1.1.4.2 yamt echo "Running tests... This will take a while."
162 1.1.1.1.4.2 yamt eval \${MAKE} -k ${MAKE_CHECK_OPTIONS} check
163 1.1.1.1.4.2 yamt ${DESTINATION}/contrib/test_summary
164 1.1.1.1.4.2 yamt }
165 1.1.1.1.4.2 yamt
166 1.1.1.1.4.2 yamt # Export the GCC source tree.
167 1.1.1.1.4.2 yamt
168 1.1.1.1.4.2 yamt export_gcc() {
169 1.1.1.1.4.2 yamt # Go to the source directory.
170 1.1.1.1.4.2 yamt changedir ${DESTINATION}
171 1.1.1.1.4.2 yamt # Go up one level.
172 1.1.1.1.4.2 yamt changedir ..
173 1.1.1.1.4.2 yamt # Build a tarball of the source directory.
174 1.1.1.1.4.2 yamt tar czf ${TARFILE} \
175 1.1.1.1.4.2 yamt --exclude=${OBJDIR} \
176 1.1.1.1.4.2 yamt --exclude=.svn \
177 1.1.1.1.4.2 yamt --exclude='.#*' \
178 1.1.1.1.4.2 yamt --exclude='*~' \
179 1.1.1.1.4.2 yamt `basename ${DESTINATION}`
180 1.1.1.1.4.2 yamt }
181 1.1.1.1.4.2 yamt
182 1.1.1.1.4.2 yamt # Install GCC.
183 1.1.1.1.4.2 yamt
184 1.1.1.1.4.2 yamt install_gcc() {
185 1.1.1.1.4.2 yamt # Go to the source directory.
186 1.1.1.1.4.2 yamt changedir ${DESTINATION}
187 1.1.1.1.4.2 yamt # Go to the object directory.
188 1.1.1.1.4.2 yamt changedir ${OBJDIR}
189 1.1.1.1.4.2 yamt
190 1.1.1.1.4.2 yamt ${MAKE} install || error "Installation failed"
191 1.1.1.1.4.2 yamt }
192 1.1.1.1.4.2 yamt
193 1.1.1.1.4.2 yamt ########################################################################
194 1.1.1.1.4.2 yamt # Initialization
195 1.1.1.1.4.2 yamt ########################################################################
196 1.1.1.1.4.2 yamt
197 1.1.1.1.4.2 yamt # SVN command
198 1.1.1.1.4.2 yamt GCC_SVN=${GCC_SVN-${SVN-svn}}
199 1.1.1.1.4.2 yamt # The SVN server containing the GCC repository.
200 1.1.1.1.4.2 yamt SVN_SERVER="gcc.gnu.org"
201 1.1.1.1.4.2 yamt # The path to the repository on that server.
202 1.1.1.1.4.2 yamt SVN_REPOSITORY="/svn/gcc/"
203 1.1.1.1.4.2 yamt # The branch to check out from that server.
204 1.1.1.1.4.2 yamt # Defaults to trunk if no branch is defined with -b.
205 1.1.1.1.4.2 yamt SVN_BRANCH=""
206 1.1.1.1.4.2 yamt # The SVN protocol to use.
207 1.1.1.1.4.2 yamt SVN_PROTOCOL="svn"
208 1.1.1.1.4.2 yamt # The username to use when connecting to the server.
209 1.1.1.1.4.2 yamt # An empty string means anonymous.
210 1.1.1.1.4.2 yamt SVN_USERNAME=""
211 1.1.1.1.4.2 yamt
212 1.1.1.1.4.2 yamt # The directory where the checked out GCC will be placed.
213 1.1.1.1.4.2 yamt DESTINATION="${HOME}/dev/gcc"
214 1.1.1.1.4.2 yamt # The relative path from the top of the source tree to the
215 1.1.1.1.4.2 yamt # object directory.
216 1.1.1.1.4.2 yamt OBJDIR="objdir"
217 1.1.1.1.4.2 yamt
218 1.1.1.1.4.2 yamt # The file where the tarred up sources will be placed.
219 1.1.1.1.4.2 yamt TARFILE="${HOME}/dev/gcc.tgz"
220 1.1.1.1.4.2 yamt
221 1.1.1.1.4.2 yamt # Options to pass to configure.
222 1.1.1.1.4.2 yamt CONFIGURE_OPTIONS=
223 1.1.1.1.4.2 yamt # The `make' program.
224 1.1.1.1.4.2 yamt MAKE=${MAKE:-make}
225 1.1.1.1.4.2 yamt # Options to pass to "make bootstrap".
226 1.1.1.1.4.2 yamt MAKE_BOOTSTRAP_OPTIONS=
227 1.1.1.1.4.2 yamt # Options to pass to "make check".
228 1.1.1.1.4.2 yamt MAKE_CHECK_OPTIONS=
229 1.1.1.1.4.2 yamt
230 1.1.1.1.4.2 yamt # Modes of operation
231 1.1.1.1.4.2 yamt BOOTSTRAP=0
232 1.1.1.1.4.2 yamt CHECKOUT=0
233 1.1.1.1.4.2 yamt CONFIGURE=0
234 1.1.1.1.4.2 yamt EXPORT=0
235 1.1.1.1.4.2 yamt INSTALL=0
236 1.1.1.1.4.2 yamt TEST=0
237 1.1.1.1.4.2 yamt UPDATE=0
238 1.1.1.1.4.2 yamt
239 1.1.1.1.4.2 yamt ########################################################################
240 1.1.1.1.4.2 yamt # Main Program
241 1.1.1.1.4.2 yamt ########################################################################
242 1.1.1.1.4.2 yamt
243 1.1.1.1.4.2 yamt # Issue usage if no parameters are given.
244 1.1.1.1.4.2 yamt test $# -eq 0 && usage
245 1.1.1.1.4.2 yamt
246 1.1.1.1.4.2 yamt # Parse the options.
247 1.1.1.1.4.2 yamt while getopts "c:d:m:o:p:t:b:u:x:" ARG; do
248 1.1.1.1.4.2 yamt case $ARG in
249 1.1.1.1.4.2 yamt c) CONFIGURE_OPTIONS="${OPTARG}";;
250 1.1.1.1.4.2 yamt d) DESTINATION="${OPTARG}";;
251 1.1.1.1.4.2 yamt m) MAKE_BOOTSTRAP_OPTIONS="${OPTARG}";;
252 1.1.1.1.4.2 yamt o) OBJDIR="${OPTARG}";;
253 1.1.1.1.4.2 yamt p) SVN_PROTOCOL="${OPTARG}";;
254 1.1.1.1.4.2 yamt t) TARFILE="${OPTARG}";;
255 1.1.1.1.4.2 yamt x) MAKE_CHECK_OPTIONS="${OPTARG}";;
256 1.1.1.1.4.2 yamt b) SVN_BRANCH="${OPTARG}";;
257 1.1.1.1.4.2 yamt u) SVN_USERNAME="${OPTARG}";;
258 1.1.1.1.4.2 yamt \?) usage;;
259 1.1.1.1.4.2 yamt esac
260 1.1.1.1.4.2 yamt done
261 1.1.1.1.4.2 yamt shift `expr ${OPTIND} - 1`
262 1.1.1.1.4.2 yamt
263 1.1.1.1.4.2 yamt # Handle the major modes.
264 1.1.1.1.4.2 yamt while [ $# -ne 0 ]; do
265 1.1.1.1.4.2 yamt case $1 in
266 1.1.1.1.4.2 yamt bootstrap) BOOTSTRAP=1;;
267 1.1.1.1.4.2 yamt build) CONFIGURE=1; BOOTSTRAP=1;;
268 1.1.1.1.4.2 yamt checkout) CHECKOUT=1;;
269 1.1.1.1.4.2 yamt configure) CONFIGURE=1;;
270 1.1.1.1.4.2 yamt export) EXPORT=1;;
271 1.1.1.1.4.2 yamt install) INSTALL=1;;
272 1.1.1.1.4.2 yamt test) TEST=1;;
273 1.1.1.1.4.2 yamt update) UPDATE=1;;
274 1.1.1.1.4.2 yamt *) usage;;
275 1.1.1.1.4.2 yamt esac
276 1.1.1.1.4.2 yamt shift
277 1.1.1.1.4.2 yamt done
278 1.1.1.1.4.2 yamt
279 1.1.1.1.4.2 yamt # Check the arguments for sanity.
280 1.1.1.1.4.2 yamt if [ ${CHECKOUT} -ne 0 ] && [ ${UPDATE} -ne 0 ]; then
281 1.1.1.1.4.2 yamt error "Cannot checkout and update simultaneously"
282 1.1.1.1.4.2 yamt fi
283 1.1.1.1.4.2 yamt
284 1.1.1.1.4.2 yamt if [ ${CHECKOUT} -eq 0 ] && test -n "${SVN_BRANCH}"; then
285 1.1.1.1.4.2 yamt error "Branch argument only makes sense when doing a checkout"
286 1.1.1.1.4.2 yamt fi
287 1.1.1.1.4.2 yamt
288 1.1.1.1.4.2 yamt # Validate the branch name.
289 1.1.1.1.4.2 yamt if test -n "${SVN_BRANCH}"; then
290 1.1.1.1.4.2 yamt SVN_BRANCH="branches/${SVN_BRANCH}";
291 1.1.1.1.4.2 yamt else
292 1.1.1.1.4.2 yamt SVN_BRANCH="trunk";
293 1.1.1.1.4.2 yamt fi
294 1.1.1.1.4.2 yamt
295 1.1.1.1.4.2 yamt # Checkout the tree.
296 1.1.1.1.4.2 yamt if [ ${CHECKOUT} -ne 0 ]; then
297 1.1.1.1.4.2 yamt checkout_gcc
298 1.1.1.1.4.2 yamt elif [ ${UPDATE} -ne 0 ]; then
299 1.1.1.1.4.2 yamt update_gcc
300 1.1.1.1.4.2 yamt fi
301 1.1.1.1.4.2 yamt
302 1.1.1.1.4.2 yamt # Configure to build the tree.
303 1.1.1.1.4.2 yamt if [ ${CONFIGURE} -ne 0 ]; then
304 1.1.1.1.4.2 yamt configure_gcc
305 1.1.1.1.4.2 yamt fi
306 1.1.1.1.4.2 yamt
307 1.1.1.1.4.2 yamt # Bootstrap the compiler.
308 1.1.1.1.4.2 yamt if [ ${BOOTSTRAP} -ne 0 ]; then
309 1.1.1.1.4.2 yamt bootstrap_gcc
310 1.1.1.1.4.2 yamt fi
311 1.1.1.1.4.2 yamt
312 1.1.1.1.4.2 yamt # Test the compiler
313 1.1.1.1.4.2 yamt if [ ${TEST} -ne 0 ]; then
314 1.1.1.1.4.2 yamt test_gcc
315 1.1.1.1.4.2 yamt fi
316 1.1.1.1.4.2 yamt
317 1.1.1.1.4.2 yamt # Install the compiler.
318 1.1.1.1.4.2 yamt if [ ${INSTALL} -ne 0 ]; then
319 1.1.1.1.4.2 yamt install_gcc
320 1.1.1.1.4.2 yamt fi
321 1.1.1.1.4.2 yamt
322 1.1.1.1.4.2 yamt # Export the sources
323 1.1.1.1.4.2 yamt if [ ${EXPORT} -ne 0 ]; then
324 1.1.1.1.4.2 yamt export_gcc
325 1.1.1.1.4.2 yamt fi
326