#! /bin/csh
# ----------------------------------------------------------------
#   (C) 1994 Institute for New Generation Computer Technology
#       (Read COPYRIGHT for detailed information.)
# ----------------------------------------------------------------   

if (! -f klic.db ) then
	cp ${GDCCPATH}/Parser/DB/* ./
endif

set LIBP      = ~/lib  

set EXECFILE  = a.out
set GDCCFILEs =
set KL1FILEs  =
set DOM       = unknown
set COMP      = yes
set INCP      =
set LIBs      =
set DP        =
set f_o       = 0
set f_dom     = 0
set f_dp      = 0

set AlgObjs = (${GDCCPATH}/Alg/alg_if.o ${GDCCPATH}/Alg/find.o ${GDCCPATH}/Alg/platypus.o ${GDCCPATH}/Alg/ask_daemon.o ${GDCCPATH}/Alg/poly.o ${GDCCPATH}/Alg/solver.o ${GDCCPATH}/Alg/poly_filter.o ${GDCCPATH}/Alg/rule_project.o ${GDCCPATH}/Alg/criteria.o ${GDCCPATH}/Alg/mole.o ${GDCCPATH}/Alg/otter.o ${GDCCPATH}/Alg/std_con.o ${GDCCPATH}/Alg/rewrite.o ${GDCCPATH}/Alg/pe_spec.o ${GDCCPATH}/Alg/rule_db.o ${GDCCPATH}/Alg/wombat.o ${GDCCPATH}/Alg/rational.o ${GDCCPATH}/Alg/bignum.o ${GDCCPATH}/Parser/diff.o ${GDCCPATH}/Parser/gdcc.o ${GDCCPATH}/Parser/ground.o ${GDCCPATH}/Parser/var.o ${GDCCPATH}/Parser/std_block.o)

set BoolObjs = (${GDCCPATH}/Bool/bool_if.o ${GDCCPATH}/Bool/bool_solver.o ${GDCCPATH}/Bool/bool.o ${GDCCPATH}/Parser/std_block.o ${GDCCPATH}/Parser/gdcc.o ${GDCCPATH}/Parser/var.o ${GDCCPATH}/Parser/diff.o ${GDCCPATH}/Parser/ground.o)

set LIBP = -L${LIBP}


foreach Op ( $argv[*] )

        if ( $f_o == 1 ) then 
		set EXECFILE = $Op
		set f_o = 0
                continue
	endif

        if ( $f_dom == 1) then 
		set DOM = $Op 
		set f_dom = 0
		continue
	endif

        if ( $f_dp == 1) then 
		set DP = $Op 
		set f_dp = 0
		continue
	endif

	if ("${Op}" == '-o') then 
		set f_o = 1 
		continue
	endif

	if ("${Op}" == '-k') then 
		set COMP = no
		continue
	endif

        if ("${Op}" == '-dom') then 
		set f_dom = 1 
		continue
	endif

        if ("${Op}" == '-dp') then 
		set f_dp = 1 
		continue
	endif

        if ("${Op}" =~ -I*) then
                set INCP = ${INCP}' '${Op}
                continue
        endif

        if ("${Op}" =~ -L*) then
                set LIBP = ${LIBP}' '${Op}
                continue
        endif                 

        if ("${Op}" =~ -\l*) then
                set LIBs = ${LIBs}' '${Op}
                continue
        endif    

	set tmp = `expr ${Op} : '\(.*\).gdcc'`

        if (tmp == 1) then
		echo Illegal GDCC file name ${Op}
                exit -2
	else
	        set GDCCFILEs = ${GDCCFILEs}' '${Op}
	endif

end

#echo gdcc files   : ${GDCCFILEs} 
#echo domain       : ${DOM} 
#echo exec file    : ${EXECFILE} 
#echo include path : ${INCP} 
#echo lib path     : ${LIBP} 
#echo libraries    : ${LIBs} 
#echo comp flag    : ${COMP} 
#echo distribution : ${DP}


if ($COMP == yes) then
    foreach file (${GDCCFILEs})

	set NFILE    = `expr ${file} : '\(.*\).gdcc'`  
	set KL1FILE  = ${NFILE}.kl1
        set KL1FILEs = ${KL1FILEs}' '${KL1FILE}

	if (${DOM} == 'alg') then
                echo Translating $file ........
        	gdcc_alg ${file}
	else if (${DOM} == 'bool') then
                echo Translating $file ........
	        gdcc_bool ${file}
	else
        	echo "Illegal domain name" ${DOM}
                exit -2
	endif                                   
    end


    echo Compiling ${KL1FILEs} ........

    if (${DOM} == 'alg') then
	klic  ${DP} ${INCP} ${LIBP} -lgmp -lmp ${LIBs} -o ${EXECFILE} ${AlgObjs} ${KL1FILEs}
    else if (${DOM} == 'bool') then
	klic  ${DP} ${INCP} ${LIBP} ${LIBs} -o ${EXECFILE} ${BoolObjs} ${KL1FILEs}
    endif

endif













