# Require $prefix, $workdir, $binutils_src
install_binutils()
(
  set -e
  [[ -e $prefix/bin/as ]] && exit 0

  [[ "$workdir" = */hscpipe_build_dir ]] || exit 1
  rm -rf "$workdir"; mkdir -p "$workdir"; pushd "$workdir"

  curl -L "$binutils_src" | tar -xJf -

  local pseudo_makeinfo=false
  if ! command -v makeinfo &> /dev/null
  then
    echo "#!/bin/bash" > "$prefix/bin/makeinfo"
    chmod a+x "$prefix/bin/makeinfo"
    pseudo_makeinfo=true
  fi

  cd *
  ./configure --prefix="$prefix"
  make
  make install

  if [[ $pseudo_makeinfo != false ]]
  then
    rm -f "$prefix/bin/makeinfo"
  fi
)
