#!/bin/sh
# $Id: cfg-mingw32,v 1.13 2023/01/24 23:19:08 tom Exp $
# configure to cross-compile using mingw32 using 32-bits

unset CC
unset CXX

TARGET=`choose-mingw32 gcc pkg-config`

# Fedora 33 or 34 turned on hardening flags in the packaged libraries, making
# them unusable if we do not do the same.
case `partition` in
*fedora3[3-9]|*fedora[4-9][0-9]|*fedoracur)
	export CFLAGS='-O2 -Wall -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS'
	export LIBS="-lssp"
	;;
esac

if test -n "$TARGET"
then
	PREFIX=
	test -d /usr/$TARGET && PREFIX="--prefix=/usr/$TARGET"

	# some older configuration does this
	if test -z "$PREFIX"
	then
	SYS=/usr/$TARGET/sys-root/mingw
	if test -d $SYS/include
	then
		echo "...adding $SYS/include to CFLAGS"
		CFLAGS="$CFLAGS -I$SYS/include"
		export CFLAGS
	fi
	if test -d $SYS/lib
	then
		echo "...adding $SYS/lib to LDFLAGS"
		LDFLAGS="$LDFLAGS -L$SYS/lib"
		export LDFLAGS
	fi
	fi

	cfg-normal \
		--host=$TARGET \
		--target=$TARGET \
		$PREFIX "$@" || exit 1
else
	echo "? cannot find MinGW-32 compiler in path"
	exit 1
fi
