# Build script for binutils.
#
# Copyright (c) 2014-2020 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version=2.35

cd -- "$TMPDIR"
rm -rf binutils-${version}
unpack "${worktree}/sources/binutils-${version}.tar.lz"

# Build instructions
cd binutils-${version}

patch -Np1 -i "${worktree}/patches/binutils/branch-updates.diff"

# Build in a separate directory
rm -rf ../binutils-build
mkdir ../binutils-build
cd ../binutils-build

../binutils-${version}/configure \
AR="ar" AS="as" CC="$BTCC" CXX="$BTCXX" \
CFLAGS="$BTCFLAGS" CXXFLAGS="$BTCXXFLAGS" LDFLAGS="$BTLDFLAGS" \
 --prefix="$crossdir" \
 --host=$host \
 --target=$target \
 --enable-deterministic-archives \
 --disable-separate-code \
 --disable-compressed-debug-sections \
 --disable-werror \
 --disable-nls \
 --disable-ppl-version-check \
 --disable-cloog-version-check \
 --with-sysroot="${crossdir}/$target" \
 $multilib_options

make -j${jobs} MAKEINFO="true"
make -j${jobs} MAKEINFO="true" install

cd -- "$TMPDIR"

cleanup()
{
    rm -rf binutils-${version} binutils-build
}

