forked from foss-for-synopsys-dwc-arc-processors/toolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-elf32.sh
executable file
·299 lines (238 loc) · 10.5 KB
/
build-elf32.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/bin/sh
# Copyright (C) 2009, 2011, 2012, 2013 Embecosm Limited
# Copyright (C) 2012-2015 Synopsys Inc.
# Contributor Joern Rennecke <[email protected]>
# Contributor Jeremy Bennett <[email protected]>
# Contributor Anton Kolesov <[email protected]>
# This script builds the ARC 32-bit ELF tool chain.
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
# Usage:
# ${ARC_GNU}/toolchain/build-elf32.sh
# The directory in which we are invoked is the build directory, in which we
# find the components source trees and in which all build directories are created.
# All other parameters are set by environment variables
# LOGDIR
# Directory for all log files.
# ARC_GNU
# The directory containing all the sources. If not set, this will default
# to the directory containing this script.
# INSTALLDIR
# The directory where the tool chain should be installed
# ARC_ENDIAN
# "little" or "big"
# ELF32_DISABLE_MULTILIB
# Either --enable-multilib or --disable-multilib to control the building
# of multilibs.
# ISA_CPU
# For use with the --with-cpu flag to specify the ISA. Can be arc700 or
# arcem.
# DO_SIM
# Either --sim or --no-sim to control whether we build and install the
# CGEN simulator.
# CONFIG_EXTRA
# Additional flags for use with configuration.
# CFLAGS_FOR_TARGET
# Additional flags used when building the target libraries (e.g. for
# compact libraries) picked up automatically by make. This variable is used
# by configure scripts and make, and build-elf.sh doesn't do anything about
# it explicitly.
# DO_PDF
# Either --pdf or --no-pdf to control whether we build and install PDFs of
# the user guides.
# PARALLEL
# string "-j <jobs> -l <load>" to control parallel make.
# HOST_INSTALL
# Make target prefix to install host application. Should be either
# "install" or "install-strip".
# We source the script arc-init.sh to set up variables needed by the script
# and define a function to get to the configuration directory (which can be
# tricky under MinGW/MSYS environments).
# The script uses a build directory (bd-elf32[eb]) local to the directory in
# which it is executed.
# The script generates a date and time stamped log file in the logs directory.
# This version is modified to work with the source tree as organized in
# GitHub.
# ------------------------------------------------------------------------------
# Local variables.
if [ "${ARC_ENDIAN}" = "big" ]
then
arch=arceb
build_dir="$(echo "${PWD}")/bd-elf32eb"
else
arch=arc
build_dir="$(echo "${PWD}")/bd-elf32"
fi
# Set up a logfile
logfile="${LOGDIR}/elf32-build-$(date -u +%F-%H%M).log"
rm -f "${logfile}"
echo "START ELF32: $(date)" | tee -a "$logfile"
# Initialize common variables and functions.
. "${ARC_GNU}"/toolchain/arc-init.sh
toolchain_build_dir=$PWD/toolchain
# variables to control whether the simulator is build. Note that we actively
# edit in the requirement for a simulator library in case it has been left
# commented out from a previous part-completed run of this script.
if [ "x${DO_SIM}" = "x--sim" ]
then
sim_config="--enable-sim --enable-sim-endian=no"
sim_build=all-sim
# NB: CGEN doesn't have install-strip target.
sim_install=install-sim
${SED} -i "${ARC_GNU}"/gdb/gdb/configure.tgt \
-e 's!# gdb_sim=../sim/arc/libsim.a!gdb_sim=../sim/arc/libsim.a!'
else
sim_config=--disable-sim
sim_build=
sim_install=
${SED} -i "${ARC_GNU}"/gdb/gdb/configure.tgt \
-e 's!gdb_sim=../sim/arc/libsim.a!# gdb_sim=../sim/arc/libsim.a!'
fi
# If PDF docs are enabled, then check if prerequisites are satisfied.
if [ "x${DO_PDF}" = "x--pdf" ]
then
if ! which texi2pdf >/dev/null 2>/dev/null
then
echo "TeX is not installed. See README.md for a list of required"
echo "system packages. Option --no-pdf can be used to disable build"
echo "of PDF documentation."
exit 1
fi
# There are issues with Texinfo v4 and non-C locales.
# See http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
if [ 4 = `texi2dvi --version | grep -Po '(?<=Texinfo )[0-9]+'` ]
then
export LC_ALL=C
fi
fi
echo "Installing in ${INSTALLDIR}" | tee -a "$logfile"
# Purge old build dir if there is any and create a new one.
rm -rf "$build_dir"
mkdir -p "$build_dir"
# Binutils
build_dir_init binutils
configure_elf32 binutils
make_target building all-binutils all-gas all-ld
# Gas requires opcodes to be installed, LD requires BFD to be installed.
# However those dependencies are not described in the Makefiles, instead if
# required components is not yet installed, then dummy as-new and ld-new will
# be installed. Both libraries are installed by install-binutils. Therefore it
# is required that binutils is installed before ld and gas. That order
# denedency showed up only with Linux toolchain so far, but for safety same
# patch is applied to baremetal toolchain.
make_target_ordered installing ${HOST_INSTALL}-binutils ${HOST_INSTALL}-ld \
${HOST_INSTALL}-gas
if [ "$DO_PDF" = "--pdf" ]
then
make_target "generating PDF documentation" install-pdf-binutils \
install-pdf-ld install-pdf-gas
fi
# Sometimes there are problems with libstdc++ precompiled headers and canadian
# cross toolchain - this happens because libstdc++ configure scripts checks
# feature availability using the host compiler with host headers, but when
# doing header precompilation it uses host compiler with headers of new
# toolchain. Those headers should be the same in general, but there is a nasty
# cyclic dependency with fenv.h. If compiler which is being used for configure
# has this header - then this "host header" will be used. If it doesn't have
# fenv.h - then file from libstdc++ distribution is used. In normal case of a
# bare toolchain there is no such header, so final toolchain includes file from
# libstdc++. But with windows cross compilation, during configure stage this
# header exists in toolchain - version that was installed from libstdc++. Thus
# configure got confused, because that is not a real file in the sense
# libstdc++ expects it to be. As a results "new" libstdc++ is configured like
# fenv.h exists, but it is not.
# Ultimately that seems to happen because libstdc++ configure script uses host
# compiler as-is, with it's own headers, but instead it should use it only as
# code-compiler, with -nostdinc and headers of toolchain being built. What is
# more, that is exactly how things happen, when toolchain is built from unified
# source tree, when newlib is in the tree. But when they are build separately -
# things get awry, and improper process is used. That happens squarely because
# top level `configure` script will modify FLAGS_FOR_TARGET variable the way we
# need it _only_ when newlib is part of the whole build. For us workaround is
# simple - build of libstdc++ precompiled headers should be disabled (it
# doesn't seem they are installed anywhere), which removes problematic build
# step. Perhaps, more sustainable solution would be to make a step back with
# regards of unified tree usage and make newlib part of the unified source tree
# for baremetal builds.
if [ "$TOOLCHAIN_HOST" ]; then
pch_opt=--disable-libstdcxx-pch
else
pch_opt=
fi
# GCC + configure of libstdc++
build_dir_init gcc
configure_elf32 gcc gcc --with-newlib $pch_opt
make_target building all-gcc all-target-libgcc
make_target installing ${HOST_INSTALL}-gcc install-target-libgcc
if [ "$DO_PDF" = "--pdf" ]
then
make_target "generating PDF documentation" install-pdf-gcc
fi
# Newlib (build in sub-shell with new tools added to the PATH)
build_dir_init newlib
(
PATH=$INSTALLDIR/bin:$PATH
configure_elf32 newlib
make_target building all-target-newlib
make_target installing install-target-newlib
if [ "$DO_PDF" = "--pdf" ]
then
make_target "generating PDF documentation" install-pdf-target-newlib
fi
)
# libstdc++
# It is built in the build tree of GCC to avoid nasty problems which might
# happen when libstdc++ is being built in the separate directory while new
# compiler is in the PATH. Notably a known broken situation is when new
# toolchain is being installed on top of the previous installation and
# libstdc++ configure script will find some header files left from previous
# installation and will decide that some features are present, while they are
# not. That problem doesn't occur when libstdc++ is built in same build tree as
# GCC before that.
echo "Building libstdc++ ..." | tee -a "$logfile"
cd $build_dir/gcc
make_target building all-target-libstdc++-v3
make_target installing install-target-libstdc++-v3
# Don't build libstdc++ documentation because it requires additional software
# on build host.
# Expat if requested
if [ "$SYSTEM_EXPAT" = no ]
then
mkdir -p $toolchain_build_dir/_download_tmp
expat_version=2.1.0
expat_tar=expat-${expat_version}.tar.gz
if [ ! -s $toolchain_build_dir/_download_tmp/$expat_tar ]; then
wget -nv -O $toolchain_build_dir/_download_tmp/$expat_tar \
http://sourceforge.net/projects/expat/files/expat/$expat_version/$expat_tar/download
fi
build_dir_init expat
tar xzf $toolchain_build_dir/_download_tmp/$expat_tar --strip-components=1
configure_elf32 expat $PWD
make_target building all
make_target installing install
fi
# GDB and CGEN simulator (maybe)
build_dir_init gdb
configure_elf32 gdb
make_target building all-gdb ${sim_build}
make_target installing ${sim_install} ${HOST_INSTALL}-gdb
if [ "$DO_PDF" = "--pdf" ]
then
make_target "generating PDF documentation" install-pdf-gdb
fi
# Restore GDB config for simulator (does nothing if the change was not made).
${SED} -i "${ARC_GNU}"/gdb/gdb/configure.tgt \
-e 's!# gdb_sim=../sim/arc/libsim.a!gdb_sim=../sim/arc/libsim.a!'
# Copy TCF handler.
cp "$ARC_GNU/toolchain/extras/arc-tcf-gcc" "$INSTALLDIR/bin/${arch}-elf32-tcf-gcc"
echo "DONE ELF32: $(date)" | tee -a "$logfile"
# vim: noexpandtab sts=4 ts=8: