scripts/addToolsVersion: properly handle .in vs. .in.2
While most components have their version in the .in file, some
have it in the .in.2 (eg. elf2flt).
Currently, to handle this case, we indiscriminately munge both files,
but this is wrong: in the elf2flt case, if we add a binutils version,
we do not want it to be added to elf2flt, and conversely.
So, for each tool, we need to explicitly know what file to munge.
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
1 # This file adds functions to build binutils
2 # Copyright 2007 Yann E. MORIN
3 # Licensed under the GPL v2. See COPYING in the root of this package
7 if [ "${CT_BINUTILS_CUSTOM}" = "y" ]; then
8 CT_GetCustom "binutils" "${CT_BINUTILS_VERSION}" \
9 "${CT_BINUTILS_CUSTOM_LOCATION}"
11 CT_GetFile "binutils-${CT_BINUTILS_VERSION}" \
12 {ftp,http}://{ftp.gnu.org/gnu,ftp.kernel.org/pub/linux/devel}/binutils \
13 ftp://gcc.gnu.org/pub/binutils/{releases,snapshots}
16 if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
17 CT_GetCVS "elf2flt-${CT_ELF2FLT_VERSION}" \
18 ":pserver:anonymous@cvs.uclinux.org:/var/cvs" \
21 "elf2flt-${CT_ELF2FLT_VERSION}"
26 do_binutils_extract() {
27 # If using custom directory location, nothing to do
28 if [ "${CT_BINUTILS_CUSTOM}" = "y" \
29 -a -d "${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}" ]; then
33 CT_Extract "binutils-${CT_BINUTILS_VERSION}"
34 CT_Patch "binutils" "${CT_BINUTILS_VERSION}"
36 if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
37 CT_Extract "elf2flt-${CT_ELF2FLT_VERSION}"
38 CT_Patch "elf2flt" "${CT_ELF2FLT_VERSION}"
42 # Build binutils for build -> target
43 do_binutils_for_build() {
44 local -a binutils_opts
46 case "${CT_TOOLCHAIN_TYPE}" in
47 native|cross) return 0;;
50 CT_DoStep INFO "Installing binutils for build"
51 CT_mkdir_pushd "${CT_BUILD_DIR}/build-binutils-build-${CT_BUILD}"
53 binutils_opts+=( "host=${CT_BUILD}" )
54 binutils_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
55 binutils_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
56 binutils_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
58 do_binutils_backend "${binutils_opts[@]}"
62 if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
63 # We re-use binutils' options, plus our owns
64 binutils_opts+=( "binutils_src=${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}" )
65 binutils_opts+=( "binutils_bld=${CT_BUILD_DIR}/build-binutils-build-${CT_BUILD}" )
67 CT_mkdir_pushd "${CT_BUILD_DIR}/build-elf2flt-build-${CT_BUILD}"
69 do_elf2flt_backend "${binutils_opts[@]}"
77 # Build binutils for host -> target
78 do_binutils_for_host() {
79 local -a binutils_tools
80 local -a binutils_opts
82 CT_DoStep INFO "Installing binutils for host"
83 CT_mkdir_pushd "${CT_BUILD_DIR}/build-binutils-host-${CT_HOST}"
85 binutils_opts+=( "host=${CT_HOST}" )
86 binutils_opts+=( "prefix=${CT_PREFIX_DIR}" )
87 binutils_opts+=( "static_build=${CT_STATIC_TOOLCHAIN}" )
88 binutils_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
89 binutils_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
90 binutils_opts+=( "build_manuals=${CT_BUILD_MANUALS}" )
92 do_binutils_backend "${binutils_opts[@]}"
96 if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
97 # We re-use binutils' options, plus our owns
98 binutils_opts+=( "binutils_src=${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}" )
99 binutils_opts+=( "binutils_bld=${CT_BUILD_DIR}/build-binutils-host-${CT_HOST}" )
101 CT_mkdir_pushd "${CT_BUILD_DIR}/build-elf2flt-host-${CT_HOST}"
103 do_elf2flt_backend "${binutils_opts[@]}"
108 # Make those new tools available to the core C compilers to come.
109 # Note: some components want the ${TARGET}-{ar,as,ld,strip} commands as
111 # Don't do it for canadian or cross-native, because the binutils
112 # are not executable on the build machine.
113 case "${CT_TOOLCHAIN_TYPE}" in
115 binutils_tools=( ar as ld strip )
116 if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
117 binutils_tools+=( elf2flt flthdr )
119 case "${CT_BINUTILS_LINKERS_LIST}" in
120 ld) binutils_tools+=( ld.bfd ) ;;
121 gold) binutils_tools+=( ld.gold ) ;;
122 ld,gold) binutils_tools+=( ld.bfd ld.gold ) ;;
123 gold,ld) binutils_tools+=( ld.bfd ld.gold ) ;;
125 mkdir -p "${CT_BUILDTOOLS_PREFIX_DIR}/${CT_TARGET}/bin"
126 mkdir -p "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
127 for t in "${binutils_tools[@]}"; do
128 CT_DoExecLog ALL ln -sv \
129 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-${t}" \
130 "${CT_BUILDTOOLS_PREFIX_DIR}/${CT_TARGET}/bin/${t}"
131 CT_DoExecLog ALL ln -sv \
132 "${CT_PREFIX_DIR}/bin/${CT_TARGET}-${t}" \
133 "${CT_BUILDTOOLS_PREFIX_DIR}/bin/${CT_TARGET}-${t}"
142 # Build binutils for X -> target
143 # Parameter : description : type : default
144 # host : machine to run on : tuple : (none)
145 # prefix : prefix to install into : dir : (none)
146 # static_build : build statcially : bool : no
147 # cflags : cflags to use : string : (empty)
148 # ldflags : ldflags to use : string : (empty)
149 # build_manuals : whether to build manuals : bool : no
150 do_binutils_backend() {
156 local build_manuals=no
157 local -a extra_config
158 local -a extra_make_flags
160 local -a manuals_install
167 CT_DoLog EXTRA "Configuring binutils"
169 if [ "${CT_BINUTILS_HAS_GOLD}" = "y" ]; then
170 case "${CT_BINUTILS_LINKERS_LIST}" in
172 extra_config+=( --enable-ld=yes --enable-gold=no )
175 extra_config+=( --enable-ld=no --enable-gold=yes )
178 extra_config+=( --enable-ld=default --enable-gold=yes )
181 extra_config+=( --enable-ld=yes --enable-gold=default )
184 if [ "${CT_BINUTILS_GOLD_THREADS}" = "y" ]; then
185 extra_config+=( --enable-threads )
188 if [ "${CT_BINUTILS_PLUGINS}" = "y" ]; then
189 extra_config+=( --enable-plugins )
191 if [ "${CT_BINUTILS_HAS_PKGVERSION_BUGURL}" = "y" ]; then
192 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
193 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
195 if [ "${CT_MULTILIB}" = "y" ]; then
196 extra_config+=("--enable-multilib")
198 extra_config+=("--disable-multilib")
201 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
203 CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
207 CXXFLAGS="${cflags}" \
208 LDFLAGS="${ldflags}" \
209 "${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}/configure" \
210 --build=${CT_BUILD} \
212 --target=${CT_TARGET} \
215 "${extra_config[@]}" \
216 ${CT_ARCH_WITH_FLOAT} \
217 ${BINUTILS_SYSROOT_ARG} \
218 "${CT_BINUTILS_EXTRA_CONFIG_ARRAY[@]}"
220 if [ "${static_build}" = "y" ]; then
221 extra_make_flags+=("LDFLAGS=-static -all-static")
222 CT_DoLog EXTRA "Prepare binutils for static build"
223 CT_DoExecLog ALL make ${JOBSFLAGS} configure-host
226 CT_DoLog EXTRA "Building binutils"
227 CT_DoExecLog ALL make "${extra_make_flags[@]}" ${JOBSFLAGS}
229 CT_DoLog EXTRA "Installing binutils"
230 CT_DoExecLog ALL make install
232 if [ "${build_manuals}" = "y" ]; then
233 CT_DoLog EXTRA "Building and installing the binutils manuals"
234 manuals_for=( gas binutils ld gprof )
235 if [ "${CT_BINUTILS_LINKER_GOLD}" = "y" ]; then
236 manuals_for+=( gold )
238 manuals_install=( "${manuals_for[@]/#/install-pdf-}" )
239 manuals_install+=( "${manuals_for[@]/#/install-html-}" )
240 CT_DoExecLog ALL make ${JOBSFLAGS} pdf html
241 CT_DoExecLog ALL make "${manuals_install[@]}"
244 # Install the wrapper if needed
245 if [ "${CT_BINUTILS_LD_WRAPPER}" = "y" ]; then
246 CT_DoLog EXTRA "Installing ld wrapper"
247 rm -f "${prefix}/bin/${CT_TARGET}-ld"
248 rm -f "${prefix}/${CT_TARGET}/bin/ld"
249 sed -r -e "s/@@DEFAULT_LD@@/${CT_BINUTILS_LINKER_DEFAULT}/" \
250 "${CT_LIB_DIR}/scripts/build/binutils/binutils-ld.in" \
251 >"${prefix}/bin/${CT_TARGET}-ld"
252 chmod +x "${prefix}/bin/${CT_TARGET}-ld"
253 cp -a "${prefix}/bin/${CT_TARGET}-ld" \
254 "${prefix}/${CT_TARGET}/bin/ld"
256 # If needed, force using ld.bfd during the toolchain build
257 if [ "${CT_BINUTILS_FORCE_LD_BFD}" = "y" ]; then
258 export CTNG_LD_IS=bfd
263 # Build elf2flt for X -> target
264 # Parameter : description : type : default
265 # host : machine to run on : tuple : (none)
266 # prefix : prefix to install into : dir : (none)
267 # static_build : build statcially : bool : no
268 # cflags : cflags to use : string : (empty)
269 # ldflags : ldflags to use : string : (empty)
270 # binutils_src : source dir of binutils : dir : (none)
271 # binutils_bld : build dir of binutils : dir : (none)
272 # build_manuals : whether to build manuals : bool : no
273 do_elf2flt_backend() {
288 CT_DoLog EXTRA "Configuring elf2flt"
291 LDFLAGS="${ldflags}" \
292 "${CT_SRC_DIR}/elf2flt-${CT_ELF2FLT_VERSION}/configure" \
293 --build=${CT_BUILD} \
295 --target=${CT_TARGET} \
297 --with-bfd-include-dir=${binutils_bld}/bfd \
298 --with-binutils-include-dir=${binutils_src}/include \
299 --with-libbfd=${binutils_bld}/bfd/libbfd.a \
300 --with-libiberty=${binutils_bld}/libiberty/libiberty.a \
302 "${CT_ELF2FLT_EXTRA_CONFIG_ARRAY[@]}"
304 CT_DoLog EXTRA "Building elf2flt"
305 CT_DoExecLog ALL make ${JOBSFLAGS}
307 CT_DoLog EXTRA "Installing elf2flt"
308 CT_DoExecLog ALL make install
311 # Now on for the target libraries
312 do_binutils_for_target() {
313 local -a extra_config
315 local -a build_targets
316 local -a install_targets
319 [ "${CT_BINUTILS_FOR_TARGET_IBERTY}" = "y" ] && targets+=("libiberty")
320 [ "${CT_BINUTILS_FOR_TARGET_BFD}" = "y" ] && targets+=("bfd")
321 for t in "${targets[@]}"; do
322 build_targets+=("all-${t}")
323 install_targets+=("install-${t}")
326 if [ "${#targets[@]}" -ne 0 ]; then
327 CT_DoStep INFO "Installing binutils for target"
328 mkdir -p "${CT_BUILD_DIR}/build-binutils-for-target"
329 CT_Pushd "${CT_BUILD_DIR}/build-binutils-for-target"
331 CT_DoLog EXTRA "Configuring binutils for target"
333 if [ "${CT_BINUTILS_HAS_PKGVERSION_BUGURL}" = "y" ]; then
334 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
335 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
337 if [ "${CT_MULTILIB}" = "y" ]; then
338 extra_config+=("--enable-multilib")
340 extra_config+=("--disable-multilib")
343 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
346 "${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}/configure" \
347 --build=${CT_BUILD} \
348 --host=${CT_TARGET} \
349 --target=${CT_TARGET} \
354 "${extra_config[@]}" \
355 ${CT_ARCH_WITH_FLOAT} \
356 "${CT_BINUTILS_EXTRA_CONFIG_ARRAY[@]}"
358 CT_DoLog EXTRA "Building binutils' libraries (${targets[*]}) for target"
359 CT_DoExecLog ALL make ${JOBSFLAGS} "${build_targets[@]}"
360 CT_DoLog EXTRA "Installing binutils' libraries (${targets[*]}) for target"
361 CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" "${install_targets[@]}"