OSDN Git Service

9cae43d0f074361ce2d78dc6394ce6a2d5fec148
[pf3gnuchains/gcc-fork.git] / contrib / gcc_build
1 #! /bin/sh
2
3 ########################################################################
4 #
5 # File:   gcc_build
6 # Author: Mark Mitchell
7 # Date:   07/10/2000
8 #
9 # Contents:
10 #   Script to automatically download and build GCC.
11 #
12 # Copyright (c) 2000 Free Software Foundation.
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
40 ########################################################################
41 # Functions
42 ########################################################################
43
44 # Issue the error message given by $1 and exit with a non-zero
45 # exit code.
46
47 error() {
48     echo "gcc_build: error: $1"
49     exit 1
50 }
51
52 # Issue a usage message explaining how to use this script.
53
54 usage() {
55 cat <<EOF
56 gcc_build        [-c configure_options] 
57                  [-d destination_directory]
58                  [-m make_options]
59                  [-u username]
60                  [-p protocol]
61                  [-t tarfile]
62                  [build]
63                  [checkout]
64                  [export]
65                  [install]
66                  [test]
67                  [update]
68 EOF
69     exit 1
70 }
71
72 # Change to the directory given by $1.
73
74 changedir() {
75     cd $1 || \
76         error "Could not change directory to $1"
77 }
78
79 # Set up CVS environment variables
80
81 cvs_setup() {
82     CVSROOT=":${CVS_PROTOCOL}:${CVS_USERNAME}@"
83     CVSROOT="${CVSROOT}${CVS_SERVER}:${CVS_REPOSITORY}"
84     export CVSROOT
85 }
86
87 # Checkout a fresh copy of the GCC build tree.
88
89 checkout_gcc() {
90     # Tell CVS where to find everything.
91     cvs_setup
92
93     # If the destination already exists, don't risk destroying it.
94     test -e ${DESTINATION} && \
95         error "${DESTINATION} already exists"
96
97     # CVS doesn't allow an absolute path for the destination directory.
98     DESTINATION_PARENT=`dirname ${DESTINATION}`
99     test -d ${DESTINATION_PARENT} || \
100         error "${DESTINATION_PARENT} is not a directory"
101     changedir ${DESTINATION_PARENT}
102
103     # Checkout the tree
104     cvs -z 9 co -d `basename ${DESTINATION}` gcc || \
105         error "Could not check out GCC"
106 }
107
108 # Update GCC.
109
110 update_gcc() {
111     # Tell CVS where to find everything
112     cvs_setup
113
114     # If the destination does not already exist, complain.
115     test -d ${DESTINATION} || \
116         error "{$DESTINATION} does not exist"
117     # Enter the destination directory.
118     changedir ${DESTINATION}
119
120     # Update the tree
121     ./contrib/gcc_update || \
122         error "Could not update GCC"
123 }
124
125 # Build GCC.
126
127 build_gcc() {
128     # Go to the source directory.
129     changedir ${DESTINATION}
130
131     # Remove the object directory.
132     rm -rf ${OBJDIR}
133     # Create it again.
134     mkdir ${OBJDIR} || \
135         error "Could not create ${OBJDIR}"
136     # Enter it.
137     changedir ${OBJDIR}
138
139     # Configure the tree.
140     (eval ${DESTINATION}/configure ${CONFIGURE_OPTIONS} | 
141         tee -a ${LOGFILE}) 2>&1 || \
142         error "Could not configure the compiler"
143
144     # Bootstrap the compiler
145     (eval make ${MAKE_OPTIONS} bootstrap |
146         tee -a ${LOGFILE}) 2>&1 || \
147         error "Could not build the compiler"
148 }
149
150 # Test GCC.
151
152 test_gcc() {
153     # Go to the source directory.
154     changedir ${DESTINATION}
155     # Go to the object directory.
156     changedir ${OBJDIR}
157
158     echo "Running tests...  This will take a while."
159     (make -k check | tee -a ${LOGFILE}) 2>&1
160     (${DESTINATION}/contrib/test_summary | tee -a ${LOGFILE})
161 }
162
163 # Export the GCC source tree.
164
165 export_gcc() {
166     # Go to the source directory.
167     changedir ${DESTINATION}
168     # Go up one level.
169     changedir ..
170     # Build a tarball of the source directory.
171     tar czf ${TARFILE} \
172         --exclude=${OBJDIR} \
173         --exclude=CVS \
174         --exclude='.#*' \
175         --exclude='*~' \
176         `basename ${DESTINATION}`
177 }
178
179 # Install GCC.
180
181 install_gcc() {
182     # Go to the source directory.
183     changedir ${DESTINATION}
184     # Go to the object directory.
185     changedir ${OBJDIR}
186
187     make install > ${LOGFILE} 2>&1 || \
188         error "Installation failed"
189 }
190
191 ########################################################################
192 # Initialization
193 ########################################################################
194
195 # The CVS server containing the GCC repository.
196 CVS_SERVER="gcc.gnu.org"
197 # The path to the repository on that server.
198 CVS_REPOSITORY="/cvs/gcc"
199 # The CVS protocol to use.
200 CVS_PROTOCOL="pserver"
201 # The username to use when connecting to the server.
202 CVS_USERNAME="anoncvs"
203
204 # The directory where the checked out GCC will be placed.
205 DESTINATION="${HOME}/dev/gcc"
206 # The relative path from the top of the source tree to the 
207 # object directory.
208 OBJDIR="objdir"
209
210 # The file where information will be logged.
211 LOGFILE=${HOME}/build-gcc.$$.log
212 # The file where the tarred up sources will be placed.
213 TARFILE="${HOME}/dev/gcc.tgz"
214
215 # Options to pass to configure.
216 CONFIGURE_OPTIONS=
217 # Options to pass to make.
218 MAKE_OPTIONS=
219
220 # Modes of operation
221 BUILD=0
222 CHECKOUT=0
223 EXPORT=0
224 INSTALL=0
225 TEST=0
226 UPDATE=0
227
228 ########################################################################
229 # Main Program
230 ########################################################################
231
232 # Parse the options.
233 while getopts "c:d:m:p:t:u:" ARG; do
234     case $ARG in
235     c)    CONFIGURE_OPTIONS="${OPTARG}";;
236     d)    DESTINATION="${OPTARG}";;
237     m)    MAKE_OPTIONS="${OPTARG}";;
238     p)    CVS_PROTOCOL="${OPTARG}";;
239     t)    CVS_TARGFILE="${OPTARG}";;
240     u)    CVS_USERNAME="${OPTARG}";;
241     \?)   usage;;
242     esac
243 done
244 shift `expr ${OPTIND} - 1`
245
246 # Handle the major modes.
247 while [ $# -ne 0 ]; do
248     case $1 in
249     build)    BUILD=1;;
250     checkout) CHECKOUT=1;;
251     export)   EXPORT=1;;
252     install)  INSTALL=1;;
253     test)     TEST=1;;
254     update)   UPDATE=1;;
255     *)        usage;;
256     esac
257     shift
258 done
259
260 # Check the arguments for sanity.
261 if [ ${CHECKOUT} -ne 0 ] && [ ${UPDATE} -ne 0 ]; then
262     error "Cannot checkout and update simultaneously"
263 fi
264
265 # Remove any old logfiles.
266 rm -f ${LOGFILE}
267 # Tell the user where to find the logfile.
268 echo "gcc_build: The logfile for this run is ${LOGFILE}"
269
270 # Checkout the tree.
271 if [ ${CHECKOUT} -ne 0 ]; then
272     checkout_gcc
273 elif [ ${UPDATE} -ne 0 ]; then
274     update_gcc
275 fi
276
277 # Build the compiler.
278 if [ ${BUILD} -ne 0 ]; then
279     build_gcc
280 fi
281
282 # Test the compiler
283 if [ ${TEST} -ne 0 ]; then
284     test_gcc
285 fi
286
287 # Install the compiler.
288 if [ ${INSTALL} -ne 0 ]; then
289     install_gcc
290 fi
291
292 # Export the sources
293 if [ ${EXPORT} -ne 0 ]; then
294     export_gcc
295 fi