#!/bin/sh

#
# usage: mkdef dll
#
# build dll.def, and dll.c file
#

base=$1

def1=${base}.def

#
# start writing to .def file...
exec >$def1

#
# standard header
echo  -e "Library\t$base"
echo 		
echo "EXPORTS"

def2=${base}.c

exec >$def2

echo 
echo "#include \"if32.h\""
echo "#include \"${base}.h\""
echo

def3=${base}.h

exec >$def3
echo 
echo "#include \"bin32.h\""
echo
echo "extern MAPTABLE ModuleMapper_${base}[];"
echo

while read type args function index ext
do
	if [ "$type" != "stdcall" ]
	then
		continue;
	fi

	#
	# append this new entry to .def file
	echo -e "\t$function\t@$index" >>$def1
	
	#
	# append to .c file...
	exec >>$def2
		
	echo "void"
	echo "IT32_$function()"
	echo "{"
#	echo "    calltrap(\"$function\");"
#	echo "    if32_stdcall_$args($function$ext);"
	echo "    if32_stdcall_$args(ModuleMapper_${base}[$index].maddr);"
	echo "}"
	echo 

	exec >>$def3
	echo "void $function$ext();"
	
done <${base}.d

