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