@echo off
echo Configuring ld for go32
echo This makefile will be built for GNUISH make
rem This batch file assumes a unix-type "sed" program

update ..\bfd\hosts\go32.h sysdep.h

echo # Makefile generated by "configure.bat"> Makefile
echo LONGARGS = gcc:ar >> Makefile
echo CC=gcc >> Makefile
echo host_alias=go32 >> Makefile
echo target_alias=go32 >> Makefile

update ../bfd/hosts/go32.h sysdep.h

if exist config.sed del config.sed

echo "s/^	\$(srcdir)\/move-if-change/	update/	">> config.sed
echo "s/CC = cc/CC = gcc/				">> config.sed
echo "s/:\([^ 	]\)/: \1/g				">> config.sed
echo "s/^	\ *\.\//	go32 /			">> config.sed
echo "s/`echo \$(srcdir)\///g				">> config.sed
echo "s/ | sed 's,\^\\\.\/,,'`//g			">> config.sed
echo "s/^	cd \$(srcdir)[ 	]*;//			">> config.sed

echo "/^SHELL/ d					">> config.sed

echo "/^GENS/ s/=sh/=sh.exe/				">> config.sed
echo "/mkscript:/,/-o/ {				">> config.sed
echo "  /-o/ a\						">> config.sed
echo "	coff2exe mkscript				">> config.sed
echo "}							">> config.sed

echo "/^EMULATION/ {					">> config.sed
echo "  s/^EMUL/#EMUL/					">> config.sed
echo "  a\						">> config.sed
echo "EMULATION_OFILES=e_go32.o e_i386coff.o		">> config.sed
echo "}							">> config.sed

echo "/^DEF_EMUL/ {					">> config.sed
echo "  s/^DEF_EMUL/OLD_DEF_EMUL/			">> config.sed
echo "  i\						">> config.sed
echo "DEF_EMUL=-DDEFAULT_EMULATION=\\\"go32\\\"		">> config.sed
echo "}							">> config.sed

echo "s/em_/e_/g					">> config.sed

echo "s/'"/\\"/g					">> config.sed
echo "s/"'/\\"/g					">> config.sed

sed -e "s/^\"//" -e "s/\"$//" -e "s/[ 	]*$//" config.sed > config2.sed
sed -f config2.sed Makefile.in >> Makefile
del config.sed
del config2.sed

echo "/^em_.*\.c.*:/ {					">> config.sed
echo "  s/^em_\(.*\)\.c.*$/\1/				">> config.sed
echo "  p						">> config.sed
echo "}							">> config.sed

sed -e "s/^\"//" -e "s/\"$//" -e "s/[ 	]*$//" config.sed > config2.sed
sed -n -f config2.sed Makefile.in > ldemul-list.dj
rem sed -e "s/^/extern ld_emulation_xfer_type ld_/" -e "s/$/_emulation;/" ldemul-list.dj > ldemul-list.h2
rem echo #define EMULATION_LIST \>>ldemul-list.h2
rem sed -e "s/^/ \&ld_/" -e "s/$/_emulation,\\/" ldemul-list.dj >> ldemul-list.h2
rem echo 0 >>ldemul-list.h2

echo extern ld_emulation_xfer_type ld_go32_emulation; > ldemul-list.h2
echo extern ld_emulation_xfer_type ld_i386coff_emulation; >> ldemul-list.h2
echo #define EMULATION_LIST \>>ldemul-list.h2
echo   &ld_go32_emulation,\>>ldemul-list.h2
echo   &ld_i386coff_emulation,\>>ldemul-list.h2
echo 0>>ldemul-list.h2

update ldemul-list.h2 ldemul-list.h
del config.sed
del config2.sed

call fix-em genscript.sh
for %%i in (*.em) do call fix-em %%i
