#!/bin/bash
#
# Copyright (C) 2018, 2020 Jeffery To
#
# SPDX-License-Identifier: GPL-2.0-only

me=go-gcc-helper
name="${0##*/}"

log() {
	local IFS=" "
	printf '%s\n' "$me: $*"
}

case "$name" in
gcc)
	if [ -z "$GO_GCC_HELPER_CC" ]; then
		log "missing GO_GCC_HELPER_CC"
		exit 1
	fi
	cmd="$GO_GCC_HELPER_CC"
	;;
g++)
	if [ -z "$GO_GCC_HELPER_CXX" ]; then
		log "missing GO_GCC_HELPER_CXX"
		exit 1
	fi
	cmd="$GO_GCC_HELPER_CXX"
	;;
*)
	log "unknown command \"$name\""
	exit 1
	;;
esac

if [ -n "$GO_GCC_HELPER_PATH" ]; then
	export PATH="$GO_GCC_HELPER_PATH"
else
	log "missing GO_GCC_HELPER_PATH"
fi

log "running $cmd $*"

$cmd "$@"
