#!/bin/sh

set -eu

. /usr/share/geordi/_functions

info "Copying compiler into chroot"

info "Using g++ from $(gcc_binary)"
info "Detected g++ version: $(gcc_version)"

# Ensure we can detect GCC version and location
gcc_binary >/dev/null && gcc_version >/dev/null

case "$(gcc_version)" in
	3*)
		error "GCC 3.x is not supported"
		;;
esac

info "Detected target architecture: $(gcc_target)"

for BINARY in $(gcc_binary) $(which as) $(which ld) $($(gcc_binary) -print-prog-name=cc1plus);
do
	debug "Copying ${BINARY} and its dependencies"

	copy_file "${BINARY}"
	copy_libs_for_binary "${BINARY}"
done
