#!/bin/sh
# $Id: openbsd-egcc,v 1.4 2025/07/13 17:33:26 tom Exp $
# vile:ts=4 sw=4
# source this to use a workaround for gcc with 32-bit OpenBSD.
# 32-bit OpenBSD has egcc but not gcc, since they prefer clang.
# 64-bit OpenBSD has gcc, but partially-broken g++.
use_EGCC=no
if test -z "$CC" ; then
	case `partition` in
	*openbsd*)
		if test ! -f /usr/bin/gcc && \
		   test   -f /usr/local/bin/egcc
		then
			if test ! -h /usr/local/bin/gcc && \
			   test ! -f /usr/local/bin/gcc
			then
				echo "WARNING: using egcc to work around OpenBSD ports"
				use_EGCC=yes
				export CC=egcc
				ACTUAL_GCC=egcc
			fi
		fi
		;;
	esac
else
	case "$CC" in
	egcc*|gcc*)
		ACTUAL_GCC=$CC
		;;
	esac
fi

: ${ACTUAL_GCC:=gcc}
export ACTUAL_GCC

case `partition` in
*openbsd*)
	q=
	for p in /usr/local/lib /usr/X11R6/lib
	do
		[ -d "$p" ] || continue
		[ -n "$q" ] && q="$q":
		q="$q:$p"
	done
	if [ -n "$q" ]
	then
		echo "WARNING: setting LD_LIBRARY_PATH to work with buggy OpenBSD ports"
		export LD_LIBRARY_PATH="$q"
	fi
	;;
esac
