#
# Rcsid[] = "$Id: Makefile,v 1.1.1.1 1998/12/17 03:06:28 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=bytecomp

SOURCES= \
    $D.tdxinit \
    $D.tdxinit2 \
    $D.timeplate \
    $D.timeplate2 \
    $D.vec \
    $D.vhd \
    and200a0.vhd \
    and500a0.vhd \
    dlo001a0.vhd \
    exn200a0.vhd \
    exo200a0.vhd \
    ffd420a0.vhd \
    inv200a0.vhd \
    mjlat200.vhd \
    nai200a0.vhd \
    nan200a0.vhd \
    noi200a0.vhd \
    nor400a0.vhd


sources: init

all: init clean test

test tests: init test_compile test_lsim test_fsim test_fsim2

update: init update_compile update_lsim update_fsim update_fsim2

copy: init copy_compile copy_lsim copy_fsim copy_fsim2

run_compile: init FORCE
	$(RM) $D.compile_log
	$(RM) $D.flt
	$(RM) *.err
	$(VHDLT)    $(VHDLT_OPTS) \
        nai200a0.vhd \
        exn200a0.vhd \
        and500a0.vhd \
        exo200a0.vhd \
        nor400a0.vhd \
        dlo001a0.vhd \
        nan200a0.vhd \
        ffd420a0.vhd \
        and200a0.vhd \
        inv200a0.vhd \
        mjlat200.vhd \
        noi200a0.vhd \
        $D.vhd                              >> $D.compile_log 2>&1
	$(FCOMP) -e $(FCOMP_OPTS) $D        >> $D.compile_log 2>&1
	$(LOOKVHDL) -v $(LOOKVHDL_OPTS) $D  > $D.luk 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
	$(DIFF) $D.luk                         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
	$(CP)   $D.luk                         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

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 -spt -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.spt                   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.spt      Test_sav
	$(CP)   $D.fsim.dct      Test_sav
	$(CP)   $D.fsim.stt      Test_sav

run_fsim2: init FORCE
	$(RM) $D.fsim2_log
	$(RM) $D.fsim2.*
	$(FSIM) $D -spt_prtime off -spt -init_file $D.tdxinit2 \
         -outmodel $D.fsim2 $(FSIM_OPTS) >> $D.fsim2_log 2>&1

test_fsim2: init run_fsim2
	$(DIFF) $D.fsim2_log                   Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.fsim2.log                   Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.fsim2.spt                   Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.fsim2.dct                   Test_sav >> $D.diff_log 2>&1
	$(DIFF) $D.fsim2.stt                   Test_sav >> $D.diff_log 2>&1

update_fsim2: init run_fsim2 copy_fsim2

copy_fsim2: init Test_sav FORCE
	$(CP)   $D.fsim2_log      Test_sav
	$(CP)   $D.fsim2.log      Test_sav
	$(CP)   $D.fsim2.spt      Test_sav
	$(CP)   $D.fsim2.dct      Test_sav
	$(CP)   $D.fsim2.stt      Test_sav

demo: init FORCE
	$(RM) $D.fsim_log
	$(RM) $D.fsim.*
	$(ECHO) "\
TDX_FSIM supports a wide range of pin timing features because\
TSSI's WGL Timeplate language has been built into the simulator.\
This is a demo of the pin electronics features of TDX_FSIM.\
To get valid fault coverages, the fault simulator MUST match\
drive and strobe timing used on the tester.  The simulator\
must accurately model the circuit AND the tester."
	$(ECHO) "\
These TDX_FSIM features are demonstrated using the 'BYTE COMPARE'\
circuit described in Zycad's Information Packet.  This is an\
8-bit 'compare' circuit that uses bidirectional pins.  Note that\
the output of the bidirectional bus can only be strobed when\
the on-chip driver (RDN) is enabled.  Strobing outside of this\
window will result in invalid fault detections.  Also note that\
the compare output pin (RXDONE) is only valid during the specified\
timing window, and the pin must be stable during the strobe."
	$(ECHO) "\
The pin timing features are demonstrated in two runs of TDX_FSIM.\
The first run uses the correct pin timing (see the Information Packet),\
and the second run extends the strobe windows on RXDONE and the\
bidirectional bus.  Since TDX_FSIM will not perform a fault detection\
strobe when a pin is unstable, the coverage drops from 74% to 58% in\
the second run.  In the DCTTOOL display, the green curve (top) is the\
first run, and the yellow curve (bottom) is the coverage from the\
incorrect timing of the second run."
	$(ECHO) ""
	$(FSIM) $D -spt_prtime off -spt      -outmodel $D.fsim >> $D.fsim_log 2>&1
	$(RM) $D.fsim2_log
	$(RM) $D.fsim2.*
	$(DCTTOOL) -n 2 -f $D.fsim.stt -f $D.fsim2.stt &
	$(ECHO) "\
The following is the run with wider strobe windows."
	$(FSIM) $D -spt_prtime off -spt -init_file $D.tdxinit2 -outmodel $D.fsim2 >> $D.fsim2_log 2>&1

Test_sav:
	$(MKDIR) Test_sav

clean: FORCE
	$(RM) \
    $D.atg.* \
    $D.atg_in \
    $D.atg_log \
    $D.step.* \
    $D.step_in \
    $D.step_log \
    $D.*.step \
    $D.*.scnviol \
    $D.level.scn \
    $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.fsim.* \
    $D.fsim_log \
    $D.fsim2.* \
    $D.fsim2_log \
    $D.fst \
    $D.grf \
    $D.his \
    $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.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

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

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