#
# Rcsid[] = "$Id: Makefile,v 1.1.1.1 1998/12/17 03:06:05 seth Exp $";
#
#  To run the demo, enter:
#
#      make run_compile
#      make demo
#      make demo_iddq
#
#
#  This makefile is used to run a design through Zycad TDX compile/lsim/fsim/etc.,
#  and will compare the results against results saved in the Test_sav directory.
#
# make test               - runs all of the tests and compares against previous results
# make update             - runs all of the tests and saves the results in Test_sav
# make copy               - saves the latest results in Test_sav
# make test_lsim          - runs only tdx_lsim and compares against previous results
# make test_fsim          - runs only tdx_fsim and compares against previous results
# make test_step          - runs only tdx_step and compares against previous results
# make test_atg           - runs only tdx_atg  and compares against previous results
# make update_lsim        - runs only tdx_lsim and saves the results in Test_sav
# make update_fsim        - runs only tdx_fsim and saves the results in Test_sav
# make update_step        - runs only tdx_step and saves the results in Test_sav
# make update_atg         - runs only tdx_atg  and saves the results in Test_sav
# make copy_lsim          - saves the latest tdx_lsim results in Test_sav
# make copy_fsim          - saves the latest tdx_fsim results in Test_sav
# make copy_step          - saves the latest tdx_step results in Test_sav
# make copy_atg           - saves the latest tdx_atg  results in Test_sav
#
# To use this makefile, you will probably have to add the following to your
# cshrc file: setenv MAKEFLAGS i   . Or use the -i option when running make.
#
# The D macro below sets the circuit design_name. Almost all TDX output uses the
# circuit design_name and an extension.
#
# The results of comparisons are put in $D.diff_log
#
# Messages are printed to standard output when individual tests fail.
#
#
# Individual TDX programs can be changed when running this makefile with:
#
#     make test "LSIM_PROG=~user/work/tdx_lsim"
#     make test "FSIM_PROG=~user/work/tdx_fsim"
#
# Additional unix command-line options can be added when running
# individual TDX programs by setting the related macro:
#
#     make test "LSIM_OPTS=-l -t"
#
# These variables can also be changed with "setenv".
#

RM=@-rm -f
MV=@-mv -f
CP=@-cp
CAT=@-cat
TAIL=@-tail
ECHO=@-echo
MKDIR=@-mkdir
SORT=@-sort
GREP=@-grep

# put the bdiff_filter script into your path if not already there
# (it should be in the TDX_ROOT/bin directory)
#DIFF=@-diff -w
DIFF=@-bdiff_filter

# Null target to force a rule to be executed
FORCE:

ATG_PROG=tdx_atg
ATG_OPTS=
ATG=@-set -x; $(ATG_PROG)

FSIM_PROG=tdx_fsim
FSIM_OPTS=
FSIM=@-set -x; $(FSIM_PROG)

LSIM_PROG=tdx_lsim
LSIM_OPTS=
LSIM=@-set -x; $(LSIM_PROG)

IDDQ_PROG=tdx_iddq
IDDQ_OPTS=
IDDQ=@-set -x; $(IDDQ_PROG)

STEP_PROG=tdx_step
STEP_OPTS=
STEP=@-set -x; $(STEP_PROG)


CHANGEFLT_PROG=changeflt
CHANGEFLT_OPTS=
CHANGEFLT=@-set -x; $(CHANGEFLT_PROG)

COLLAPSE_PROG=collapse
COLLAPSE_OPTS=
COLLAPSE=@-set -x; $(COLLAPSE_PROG)

DCTTOOL_PROG=dcttool
DCTTOOL_OPTS=
DCTTOOL=@-set -x; $(DCTTOOL_PROG)

FCOMP_PROG=fcomp
FCOMP_OPTS=
FCOMP=@-set -x; $(FCOMP_PROG)

FGEN_PROG=fgen
FGEN_OPTS=
FGEN=@-set -x; $(FGEN_PROG)

FLT2FOG_PROG=flt2fog
FLT2FOG_OPTS=
FLT2FOG=@-set -x; $(FLT2FOG_PROG)

FOG2FLT_PROG=fog2flt
FOG2FLT_OPTS=
FOG2FLT=@-set -x; $(FOG2FLT_PROG)

LOADDC_PROG=loaddc
LOADDC_OPTS=
LOADDC=@-set -x; $(LOADDC_PROG)

LOOKVER_PROG=lookver
LOOKVER_OPTS=
LOOKVER=@-set -x; $(LOOKVER_PROG)

LOOKVHDL_PROG=lookvhdl
LOOKVHDL_OPTS=
LOOKVHDL=@-set -x; $(LOOKVHDL_PROG)

LOOKZYC_PROG=lookzyc
LOOKZYC_OPTS=
LOOKZYC=@-set -x; $(LOOKZYC_PROG)

MERGEFLT_PROG=mergeflt
MERGEFLT_OPTS=
MERGEFLT=@-set -x; $(MERGEFLT_PROG)

PARTFLT_PROG=partflt
PARTFLT_OPTS=
PARTFLT=@-set -x; $(PARTFLT_PROG)

REMOVEFLT_PROG=removeflt
REMOVEFLT_OPTS=
REMOVEFLT=@-set -x; $(REMOVEFLT_PROG)

REPORTER_PROG=reporter
REPORTER_OPTS=
REPORTER=@-set -x; $(REPORTER_PROG)

SFSIM_PROG=sfsim
SFSIM_OPTS=
SFSIM_BINS=-bin_path ~/work_o/sim
SFSIM=@-set -x; $(SFSIM_PROG)

TAP_PROG=tap
TAP_OPTS=
TAP=@-set -x; $(TAP_PROG)

VB2VHDL_PROG=vb2vhdl
VB2VHDL_OPTS=
VB2VHDL=@-set -x; $(VB2VHDL_PROG)

VBH2VHDL_PROG=vbh2vhdl
VBH2VHDL_OPTS=
VBH2VHDL=@-set -x; $(VBH2VHDL_PROG)

VEC2JED_PROG=vec2jed
VEC2JED_OPTS=
VEC2JED=@-set -x; $(VEC2JED_PROG)

VEC2ZYC_PROG=vec2zyc
VEC2ZYC_OPTS=
VEC2ZYC=@-set -x; $(VEC2ZYC_PROG)

VERILOGT_PROG=verilogt
VERILOGT_OPTS=
VERILOGT=@-set -x; $(VERILOGT_PROG)

VHDLT_PROG=vhdlt
VHDLT_OPTS=
VHDLT=@-set -x; $(VHDLT_PROG)

XPAND_PROG=xpand
XPAND_OPTS=
XPAND=@-set -x; $(XPAND_PROG)


D=add

SOURCES= 

sources: init

all: init clean test

test tests: init test_compile test_lsim test_fsim test_atg test_step test_iddq

update: init update_compile update_lsim update_fsim update_atg update_step update_iddq

copy: init copy_compile copy_lsim copy_fsim copy_atg copy_step copy_iddq

run_compile: init FORCE $D.fcomp_in
	$(RM) $D.compile_log
	$(RM) $D.flt
	$(RM) *.err
	$(VHDLT) $(VHDLT_OPTS) $D.vhd       >> $D.compile_log 2>&1
	$(FCOMP) -e $(FCOMP_OPTS) $D        >> $D.compile_log 2>&1
	$(RM) *.smo *.sms *.err

test_compile: init run_compile
	$(DIFF) $D.compile_log   Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.flt           Test_sav >> $D.diff_log 2>&1

update_compile: init run_compile copy_compile

copy_compile: init Test_sav FORCE
	$(CP)   $D.compile_log   Test_sav
	$(CP)   $D.flt           Test_sav

run_lsim: init FORCE
	$(RM) $D.lsim_log
	$(RM) $D.lsim.*
	$(LSIM) $D -spt_prtime off -spt      -outmodel $D.lsim $(LSIM_OPTS) >> $D.lsim_log 2>&1
	$(LSIM) $D -spt_prtime off \
               -init_file $D.vec1init -vector_file $D.vec1 $(LSIM_OPTS) >> $D.lsim_log 2>&1
	$(CAT)  $D.log  >> $D.lsim.log

test_lsim: init run_lsim
	$(DIFF) $D.lsim_log             Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.lsim.log             Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.lsim.spt             Test_sav >> $D.diff_log 2>&1

update_lsim: init run_lsim copy_lsim

copy_lsim: init Test_sav FORCE
	$(CP)   $D.lsim_log    Test_sav
	$(CP)   $D.lsim.log    Test_sav
	$(CP)   $D.lsim.spt    Test_sav

run_fsim: init FORCE
	$(RM) $D.fsim_log
	$(RM) $D.fsim.*
	$(FSIM) $D -spt_prtime off           -outmodel $D.fsim $(FSIM_OPTS) >> $D.fsim_log 2>&1

test_fsim: init run_fsim
	$(DIFF) $D.fsim_log             Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.fsim.log             Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.fsim.dct             Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.fsim.stt             Test_sav >> $D.diff_log 2>&1

update_fsim: init run_fsim copy_fsim

copy_fsim: init Test_sav FORCE
	$(CP)   $D.fsim_log      Test_sav
	$(CP)   $D.fsim.log      Test_sav
	$(CP)   $D.fsim.dct      Test_sav
	$(CP)   $D.fsim.stt      Test_sav

run_atg: init FORCE
	$(RM) $D.atg_log
	$(RM) $D.atg.*
	$(ATG) $D            -outmodel $D.atg $(ATG_OPTS) >> $D.atg_log 2>&1

test_atg: init run_atg
	$(DIFF) $D.atg_log              Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.atg.log              Test_sav >> $D.diff_log 2>&1

update_atg: init run_atg copy_atg

copy_atg: init Test_sav FORCE
	$(CP)   $D.atg_log      Test_sav
	$(CP)   $D.atg.log      Test_sav

demo: init FORCE

run_step: init FORCE $D.step_in
	$(RM) $D.step_log
	$(RM) $D.log
	$(RM) $D.step_fsim*
	$(RM) $D.step_atg*
	$(STEP) $D -fault_file $D.fsim.out.flt -vector_file $D.vec \
            $(STEP_OPTS) >> $D.step_log < $D.step_in 2>&1
	$(FSIM) $D -spt_prtime off -spt null -ST -sc $D.1.step -outmodel $D.step_fsim \
                         $(FSIM_OPTS) >> $D.step_fsim_log 2>&1

test_step: init run_step
	$(DIFF) $D.step_log             Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.steplog              Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.1.step               Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.step_fsim_log        Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.step_fsim.log        Test_sav >> $D.diff_log 2>&1

update_step: init run_step copy_step

copy_step: init Test_sav FORCE
	$(CP)   $D.step_log       Test_sav
	$(CP)   $D.steplog        Test_sav
	$(CP)   $D.1.step         Test_sav
	$(CP)   $D.step_fsim_log  Test_sav
	$(CP)   $D.step_fsim.log  Test_sav

run_iddq: init FORCE
	$(RM) $D.iddq_log
	$(RM) $D.iddq.*
	$(IDDQ) $D -spt_prtime off -spt null -init_file $D.id1init \
              -outmodel $D.iddq $(IDDQ_OPTS) >> $D.iddq_log 2>&1

test_iddq: init run_iddq
	$(DIFF) $D.iddq_log             Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.iddq.log             Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.iddq.idq             Test_sav >> $D.diff_log 2>&1

update_iddq: init run_iddq copy_iddq

copy_iddq: init Test_sav FORCE
	$(CP)   $D.iddq_log    Test_sav
	$(CP)   $D.iddq.log    Test_sav
	$(CP)   $D.iddq.idq    Test_sav

# step command input file for all faults
$D.step_in: FORCE
	$(RM)                         $(@F)
	$(ECHO) "advice all"      >> $(@F)
	$(ECHO) "levelize"        >> $(@F)
	$(ECHO) "tap range"       >> $(@F)
	$(ECHO) "quit"            >> $(@F)

# fcomp command input file for all faults
$D.fcomp_in: FORCE
	$(RM)                      $(@F)
	$(ECHO) "~.* SA0"      >> $(@F)
	$(ECHO) "~.* SA1"      >> $(@F)

Test_sav:
	$(MKDIR) Test_sav

clean: FORCE
	$(RM) \
    $D.atg.* \
    $D.atg_clk.* \
    $D.atg_in \
    $D.atg_log \
    $D.atg_clk_log \
    $D.iddq.* \
    $D.iddq_log \
    $D.step.* \
    $D.step_in \
    $D.step_log \
    $D.*.step \
    $D.*.scnviol \
    $D.level.scn \
    $D.step_atg.* \
    $D.step_fsim.* \
    $D.step_fsim_log \
    $D.c \
    $D.ckt \
    $D.cof \
    $D.compile_log \
    $D.dct \
    $D.diag \
    $D.diff_log \
    $D.ech \
    $D.err \
    $D.fcomp_in \
    $D.fff \
    $D.flt \
    $D.fsim.* \
    $D.fsim_log \
    $D.fst \
    $D.grf \
    $D.his \
    $D.ins \
    $D.kbg \
    $D.log \
    $D.luk \
    $D.nam \
    $D.names \
    $D.nnm \
    $D.o \
    $D.out.vec \
    $D.pat \
    $D.plb \
    $D.pnd \
    $D.rsc \
    $D.sfsim.* \
    $D.sfsim_falt* \
    $D.sfsim_good* \
    $D.sfsim_log \
    $D.smo \
    $D.sms \
    $D.step_atg_log \
    $D.steplog \
    $D.stt \
    $D.*.itt \
    $D.tap \
    $D.lsim.* \
    $D.lsim_log \
    $D.tme \
    verilogt.log \
    vhdlt.log \
    xpand.log \
    bxpand.log \
    *.smo *.sms *.err *.ind *.udp \
    *.ckt *.nam *.nnm *.eqv *.fff \
    *.wgl *.tstl


init: $(SOURCES)
	$(RM) $D.diff_log

# get from RCS
CO=co
COFLAGS=
%:: RCS/%,v
	$(CO) $(COFLAGS) $< $@

.DEFAULT:
	@echo "Unknown Makefile target '$@'"
