OSDN Git Service

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