XCOMM! /bin/csh -f
XCOMM 
XCOMM Generate a Makefile for ibuild
XCOMM 

if ($1 == "-m") then
    set ccsuffix = $2
    set name = $3
    set dest = `basename $3`
    set imakefile = $name-imake
    set makefile = $name-make
    set aout = $name.exe

    shift argv
    shift argv
    shift argv

    if (-f $imakefile) then
	rm -f $imakefile.bak
	mv $imakefile $imakefile.bak
    endif

    echo "XCOMM DO NOT EDIT -- generated by ibmkmf" > $imakefile
    echo " " >> $imakefile

    echo "SPECIAL_IMAKEFLAGS = \" >> $imakefile
    echo "    -f $imakefile -s $makefile -DIVUseInstalled -DTurnOptimizingOn=0" \
	 >> $imakefile
    echo " " >> $imakefile
    echo "CCSUFFIX = $ccsuffix" >> $imakefile
    echo " " >> $imakefile

    echo "SRCS = \" >> $imakefile
    foreach i ($argv)
	echo "    $i."'$(CCSUFFIX) \' >> $imakefile
    end
    echo "    $name-main."'$(CCSUFFIX)' >> $imakefile
    echo "OBJS = \" >> $imakefile
    foreach i ($argv)
	echo "    $i.o \" >> $imakefile
    end
    echo "    $name-main.o" >> $imakefile
    echo "AOUT = $aout" >> $imakefile
    echo " " >> $imakefile

    echo "Use_libUnidraw()" >> $imakefile
    echo "Use_2_6()" >> $imakefile
    echo "ComplexProgramTarget($dest)" >> $imakefile
    echo " " >> $imakefile

    echo "MakeObjectRule($name-main,$name-main,NullParameter)" >> $imakefile
    foreach i ($argv)
	echo "MakeObjectRule($i,$i,NullParameter)" >> $imakefile
    end

else
    set imakefile = $1-imake
    set makefile = $1-make
    imake CONFIGDIRSPEC \
	-f $imakefile -s $makefile -DIVUseInstalled -DTurnOptimizingOn=0
endif
