############################
#
# makefile parameters
#
############################

SHELL      = /bin/sh

############################
#
# Executable files ( Alliance Tools )
#
############################

ASM        = $(TOP)/bin/dlx_asm 
ASIMUT     = $(TOP)/bin/asimut
SYF        = $(TOP)/bin/syf
LOGIC      = $(TOP)/bin/logic
NETOPTIM   = $(TOP)/bin/netoptim
FPGEN      = $(TOP)/bin/fpgen
GENLIB     = $(TOP)/bin/genlib
GENPAT     = $(TOP)/bin/genpat
SCR_EXE    = $(TOP)/bin/scr
LYNX       = $(TOP)/bin/lynx
DRUC       = $(TOP)/bin/druc
LVX        = $(TOP)/bin/lvx
DPR        = $(TOP)/bin/dpr
BBR        = $(TOP)/bin/bbr
RING_EXE   = $(TOP)/bin/ring
S2R        = $(TOP)/bin/s2r

############################
#
# Cells directories
#
#       scr  : Standard cells
#      ring  : Pads cells
#   fitpath  : Datapath cells
#       rsa  : Recurence Solver Adder cells
#       rfg  : Register File Generator cells
#       bsg  : Barrel Shifter Generator cells
#
############################

CELLS      = $(TOP)/cells

SCR        = $(CELLS)/scr
RING       = $(CELLS)/ring/pad12
FPLIB      = $(CELLS)/fitpath/fplib
DPLIB      = $(CELLS)/fitpath/dplib
RSA        = $(CELLS)/rsa
RFG        = $(CELLS)/rfg
BSG        = $(CELLS)/bsg

ALL        = $(SCR):$(RING):$(FPLIB):$(DPLIB):$(RSA):$(RFG):$(BSG)

############################
#
# Environments Variables
#
############################

# Set the logical environment to VST
ENV_VST      = MBK_IN_LO=vst;              export MBK_IN_LO;             \
               MBK_OUT_LO=vst;             export MBK_OUT_LO;            \
               MBK_WORK_LIB=.;             export MBK_WORK_LIB

# Set the logical environment to AL
ENV_AL       = MBK_IN_LO=al;               export MBK_IN_LO;             \
               MBK_OUT_LO=al;              export MBK_OUT_LO;            \
               MBK_WORK_LIB=.;             export MBK_WORK_LIB

# Set the physical environment to AP
ENV_AP       = MBK_IN_PH=ap;               export MBK_IN_PH;             \
               MBK_OUT_PH=ap;              export MBK_OUT_PH;            \
               MBK_WORK_LIB=.;             export MBK_WORK_LIB

# Set the asimut environment
ENV_VH       = VH_BEHSFX=vbe;              export VH_BEHSFX;             \
               VH_MAXERR="10";             export VH_MAXERR;             \
               VH_PATSFX=pat;              export VH_PATSFX

# Set the Synthese Logique environment
ENV_SL       = MBK_TARGET_LIB=$(SCR);       export MBK_TARGET_LIB;       \
               MBK_VDD=vdd;                 export MBK_VDD;              \
               MBK_VSS=vss;                 export MBK_VSS

# Set the Rectangle Data Structure environment
ENV_RDS      = RDS_TECHNO_NAME=$(TOP)/etc/prol12.rds;                    \
                                           export RDS_TECHNO_NAME;       \
               RDS_IN=cif;                 export RDS_IN;                \
               RDS_OUT=cif;                export RDS_OUT;               \
               MBK_WORK_LIB=.;             export MBK_WORK_LIB

############################
#
# Input of Makefile
#
# When you just call "make", display the availables Makefile entries
#
############################

############################
#
# When you call "make help", display the availables Makefile entries
#
############################

help         :
	@echo " "
	@echo "          Alliance CAD System 2.0,        dlxm_make"
	@echo "          Copyright (c) 94, MASI, CAO-VLSI Team"
	@echo "          E-mail support:      cao-vlsi@masi.ibp.fr"

	@echo " "
	@echo " How to make all the dlxm with a minimal simulation subset:"
	@echo " "
	@echo "                   all     : Make all the dlxm"
	@echo " "
	@echo " this step can be done in 4 separate steps :"
	@echo " "
	@echo "       1    functional     : Dlxm behavioral model validation"
	@echo "       2    structural     : Logical synthesis and validation"
	@echo "       3      physical     : Layout generation and validation"
	@echo " "
	@echo " this step can be done in 4 separate steps :"
	@echo " "
	@echo "         3.1   ctl_routing : Routing the control"
	@echo "         3.2   dpt_routing : Routing the data-path"
	@echo "         3.3  core_routing : Routing the core"
	@echo "         3.4  dlxm_routing : Routing the dlxm"
	@echo " "
	@echo "       4          real     : real layout file generation"
	@echo " "
	@echo "                 clean     : Clean the directory"
	@echo " "

############################
#
# When you call "make clean", the directory is cleanup
#
############################

clean        : clean_sim      \
               clean_struct   \
               clean_layout   \
               clean_real

clean_sim       :
	-@rm -f romu.vbe 
	-@rm -f roms.vbe
	-@rm -f and001_chip.pat
	-@rm -f and001_blocks.pat
	-@rm -f and001_gates.pat
	-@rm -f dlxm_scan.pat
	-@rm -f dlxm_scan_res.pat

clean_struct     :
	-@rm -f dlxm_seq.vbe
	-@rm -f dlxm_seqo.vbe
	-@rm -f dlxm_seq.cod
	-@rm -f dlxm_seq.vst
	-@rm -f dlxm_stso.vbe 
	-@rm -f dlxm_sts.vst 
	-@rm -f dlxm_dpt.vst
	-@rm -f core.vst
	-@rm -f dlxm_dpt.dpr
	-@rm -f *_32x*.vst
	-@rm -f *_32x*.vbe

clean_layout  :
	-@rm -f *.ap
	-@rm -f *.al
	-@rm -f dlxm_ctl.stat
	-@rm -f lvx_result_*
	-@rm -f core.vst 
	-@rm -f dlxm_ctl.vst

clean_real      :
	-@rm -f dlxm.cif

############################
#
# the option to make all the dlxm
#
############################

all          : functional    \
               structural    \
               physical      \
               real

############################
#
# the option to validate the dlxm functional description
#
############################

functional     : dlxm_chip_sim

############################
#
# the option to validate the dlxm structural description
#
############################

structural   : dlxm_blocks_sim   \
               dlxm_gates_sim    \
               dlxm_scan_sim

############################
#
# the option to validate the dlxm physical description
#
############################

physical     : dlxm_routing

############################
#
# the option to make the ready to foundry dlxm file
#
############################

real         : dlxm_real

##########################################################################
#
#
# Functional part :
#
#   - Simulate with dlxm.vbe =>
#
#      1) Validation of dlxm.vbe
#
#      2) Validation of asm files
#
##########################################################################

dlxm_chip_sim     : and001_chip.pat 

#####################################
#
# Simulation using user rom and default supervisor rom
#
#    - Assign the environments variables
#    - Generate romu.vbe
#    - Generate roms.vbe
#    - Simulate
#
# Don't forget to see if the last pc is
# on the GOOD adress ( 7ffffff0 )
#
#####################################

and001_chip.pat    : and001.u def001.s dlxm.vbe
	MBK_CATA_LIB=.;                 export MBK_CATA_LIB;                 \
	MBK_CATAL_NAME=CATAL_CPU_CHIP;  export MBK_CATAL_NAME;               \
	$(ENV_VST);                                                          \
	$(ENV_VH);                                                           \
	$(ASM) and001.u romu;                                                \
	$(ASM) def001.s roms;                                                \
	$(ASIMUT) dlxm_cpu dlxm_cpu_chip and001_chip

##########################################################################
#
#
# structural part :
#
#    - Generation of the core structural description
#
#    - Generation of the sequencer behavioral description
#
#    - Simulation of the dlxm with 3 blocks
#
#    - Generation of the corresponding 3 netlists
#
#    - Simulation of the dlxm with gates leaf cells
#
#    - Simulation of the dlxm with scan-path 
#
##########################################################################

####################################
#
# Creating core.vst from core.3blocks.vst
#
####################################

core.vst : core.3blocks.vst
	@ cp core.3blocks.vst core.vst;                        \
	chmod 644 core.vst 

####################################
#
# Creating dlxm_seq.vbe from dlxm_seq.fsm ( with syf )
#
#   - Generation of dlxm_seq.vbe
#
####################################

dlxm_seq.vbe : dlxm_seq.fsm
	@ $(ENV_SL);                                                        \
	$(SYF) -s dlxm_seq -of dlxm_seq -scan -save;

####################################
# Simulation of the dlxm described with pads and core in 3 blocks
# dlxm_sts.vbe dlxm_seq.vbe dlxm_dpt.vbe
####################################

dlxm_blocks_sim      : and001_blocks.pat 

#####################################
#
#    - Assign the environments variables
#    - Generate romu.vbe
#    - Generate roms.vbe
#    - Simulate
#
# Don't forget to see if the last pc is
# on the GOOD adress ( 7ffffff0 )
#
#####################################

and001_blocks.pat    : and001.u def001.s                    \
                       dlxm_sts.vbe                         \
                       dlxm_seq.vbe                         \
                       dlxm_dpt.vbe                         \
                       core.vst                             \
                       dlxm.vst
	@ MBK_CATA_LIB=.:$(RING);                      export MBK_CATA_LIB;  \
	MBK_CATAL_NAME=CATAL_CPU_BLOCKS;             export MBK_CATAL_NAME;  \
	$(ENV_VST);                                                          \
	$(ENV_VH);                                                           \
	$(ASM) and001.u romu;                                                \
	$(ASM) def001.s roms;                                                \
	$(ASIMUT) dlxm_cpu dlxm_cpu_blocks and001_blocks

####################################
#
# Creating dlxm_sts.vst from dlxm_sts.vbe ( with logic )
#
#    - Generation of dlxm_stso.vbe
#
#    - Generation of dlxm_sts.vst
#
####################################

dlxm_sts.vst : dlxm_sts.vbe
	@ $(ENV_VST);                                                        \
	$(ENV_SL);                                                           \
	MBK_CATA_LIB=$(SCR);    export MBK_CATA_LIB;                         \
	$(LOGIC) -o dlxm_sts dlxm_stso;                                      \
	$(LOGIC) -s dlxm_stso dlxm_sts

####################################
#
# Creating dlxm_seq.vst from dlxm_seq.vbe ( with logic )
#
#    - Generation of dlxm_seqo.vbe
#
#    - Generation of dlxm_seq.vst
#
####################################

dlxm_seq.vst : dlxm_seq.vbe
	@ $(ENV_VST);                                                        \
	$(ENV_SL);                                                           \
	MBK_CATA_LIB=$(SCR);    export MBK_CATA_LIB;                         \
	$(LOGIC) -o dlxm_seq dlxm_seqo;                                      \
	$(LOGIC) -s dlxm_seqo dlxm_seq

####################################
#
# Creating dlxm_dpt.vst from dlxm_dpt.c ( with fpgen )
#
#    - Generation of dlxm_dpt.vst
#
#    - Generation of dlxm_dpt.dpr
#
####################################

dlxm_dpt.vst : dlxm_dpt.c
	@ MBK_CATA_LIB=.:$(ALL);             export MBK_CATA_LIB;            \
	MBK_CATAL_NAME=CATAL_CPU_GATES;    export MBK_CATAL_NAME;            \
	$(ENV_VST);                                                          \
	$(ENV_AP);                                                           \
	$(FPGEN) -v dlxm_dpt

####################################
# Simulation of dlxm_sts.vst dlxm_seq.vst dlxm_dpt.vst
####################################

dlxm_gates_sim      : and001_gates.pat 

#####################################
#
# Always the same method :
#
#    - Assign the environments variables
#    - Generate romu.vbe
#    - Generate roms.vbe
#    - Simulate
#
# Don't forget to see if the last pc is
# on the GOOD adress ( 7ffffff0 )
#
#####################################

and001_gates.pat    : and001.u  def001.s                \
                      core.vst                          \
                      dlxm.vst                          \
                      dlxm_seq.vst                      \
                      dlxm_sts.vst                      \
                      dlxm_dpt.vst
	@ MBK_CATA_LIB=.:$(ALL);             export MBK_CATA_LIB;   \
	MBK_CATAL_NAME=CATAL_CPU_GATES;    export MBK_CATAL_NAME;   \
	$(ENV_VST);                                                 \
	$(ENV_VH);                                                  \
	$(ASM) and001.u romu;                                       \
	$(ASM) def001.s roms;                                       \
	$(ASIMUT) dlxm_cpu dlxm_cpu_gates and001_gates

##########################################################################
#
# Validation of the scan-path
#
#         1) Generate pattern file ( GENPAT )
#
#         2) Simulate ( ASIMUT )
#
##########################################################################

dlxm_scan_sim : dlxm_scan_res.pat

####################################
#
# Generating patterns files
#
#    - Call GENPAT
#
####################################

dlxm_scan.pat : dlxm_scan.c
	@ MBK_CATA_LIB=.:$(ALL);              export MBK_CATA_LIB;           \
	$(ENV_VH);                                                           \
	$(GENPAT) dlxm_scan

####################################
#
# Simulate for testing scan-path
#
#    - Call ASIMUT
#
####################################

dlxm_scan_res.pat : dlxm_scan.pat                     \
                    and001.u def001.s                 \
                    core.vst                          \
                    dlxm.vst                          \
                    dlxm_sts.vst                      \
                    dlxm_seq.vst                      \
                    dlxm_dpt.vst
	@ MBK_CATA_LIB=.:$(ALL);             export MBK_CATA_LIB;   \
	MBK_CATAL_NAME=CATAL_CPU_GATES;    export MBK_CATAL_NAME;   \
	$(ENV_VST);                                                 \
	$(ENV_VH);                                                  \
	$(ASM) and001.u romu;                                       \
	$(ASM) def001.s roms;                                       \
	$(ASIMUT) dlxm_cpu dlxm_scan dlxm_scan_res

##########################################################################
#
# Physical part :
#
#    - Merge sequencer and status
#
#    - Route control
#
#    - Route datapath
#
#    - Route core
#
#    - Route chip
#
##########################################################################

#####################################
#
# How to make control
#
#   - Restructurate control
#
#   - Call the router SCR
#
#   - Extract the netlist from layout ( LYNX )
#
#   - Compare the netlist ( LVX )
#
#####################################

ctl_routing : lvx_result_ctl

#####################################
#
# Restructurate control
#
#   - Call GENLIB with the unflat_flat.c file
#
#   - Call netoptim on control
#
#####################################

dlxm_ctl.vst : dlxm_seq.vst             \
               dlxm_sts.vst             \
               core.vst                 \
               unflat_flat.c
	@ MBK_CATA_LIB=.;        export MBK_CATA_LIB;                    \
	$(ENV_VST);                                                      \
	$(GENLIB) -v unflat_flat
	@ $(ENV_VST);                                                    \
	$(ENV_SL);                                                       \
	MBK_CATA_LIB=$(SCR);   export MBK_CATA_LIB;                      \
	$(NETOPTIM) -f dlxm_ctl dlxm_ctl dlxm_ctl

#####################################
#
# Routing control
#
#    - Call SCR
#
#####################################

dlxm_ctl.ap : dlxm_ctl.vst dlxm_ctl.scr
	@ MBK_CATA_LIB=$(SCR);   export MBK_CATA_LIB;                        \
	MBK_VDD=vdd;           export MBK_VDD;                               \
	MBK_VSS=vss;           export MBK_VSS;                               \
	$(ENV_VST);                                                          \
	$(ENV_AP);                                                           \
	$(SCR_EXE) -p -r -i 5000 -l 5 dlxm_ctl

#####################################
#
# Extracting control
#
#    - Call LYNX
#
#####################################

dlxm_ctl.al : dlxm_ctl.ap
	@ MBK_CATA_LIB=$(SCR);   export MBK_CATA_LIB;                        \
	$(ENV_AL);                                                           \
	$(ENV_AP);                                                           \
	$(LYNX) -v dlxm_ctl dlxm_ctl

#####################################
#
# Netlist comparaison
#
#    - Call LVX
#
#   - Create a file for makefile dependances
#
#####################################

lvx_result_ctl : dlxm_ctl.al
	@ MBK_CATA_LIB=$(SCR);   export MBK_CATA_LIB;                          \
	$(LVX) vst al dlxm_ctl dlxm_ctl
	touch lvx_result_ctl

#####################################
#
# How to make data-path
#
#   - Call DPR
#
#   - Extract the netlist from layout ( LYNX )
#
#   - Compare the netlist ( LVX )
#
#####################################

dpt_routing : lvx_result_dpt

#####################################
#
# Routing data-path
#
#   - Call DPR
#
#####################################

dlxm_dpt.ap : dlxm_dpt.vst
	@ MBK_CATA_LIB=.:$(ALL);     export MBK_CATA_LIB;                    \
	MBK_CATAL_NAME=CATAL_CPU_GATES;      export MBK_CATAL_NAME;          \
	$(ENV_VST);                                                          \
	$(ENV_AP);                                                           \
	$(DPR) dlxm_dpt -p -r dlxm_dpt

#####################################
#
# Extracting data-path
#
#   - Call LYNX
#
#####################################

dlxm_dpt.al : dlxm_dpt.ap
	@ MBK_CATA_LIB=.:$(ALL);               export MBK_CATA_LIB;          \
	MBK_CATAL_NAME=CATAL_CPU_GATES;      export MBK_CATAL_NAME;          \
	$(ENV_AL);                                                           \
	$(ENV_AP);                                                           \
	$(LYNX) -v dlxm_dpt dlxm_dpt

#####################################
#
# Netlist comparaison
#
#   - Call LVX
#
#   - Create a file for makefile dependances
#
#####################################

lvx_result_dpt : dlxm_dpt.al
	@ MBK_CATA_LIB=.:$(ALL);               export MBK_CATA_LIB;          \
	MBK_CATAL_NAME=CATAL_CPU_GATES;      export MBK_CATAL_NAME;          \
	$(LVX) vst al dlxm_dpt dlxm_dpt -f
	touch lvx_result_dpt

#####################################
#
# How to make core
#
#   - Call BBR
#
#   - Extract the netlist from layout ( LYNX )
#
#   - Compare the netlist ( LVX )
#
#####################################

core_routing : dpt_routing ctl_routing lvx_result_core

#####################################
#
# Routing core
#
#   - Create the placement ( GENLIB )
#
#   - Call BBR
#
#   - Rename the output file 
#
#####################################

core.ap : core.c dlxm_dpt.ap dlxm_ctl.ap
	@ MBK_CATA_LIB=$(ALL);   export MBK_CATA_LIB;                        \
	$(ENV_VST);                                                          \
	$(ENV_AP);                                                           \
	$(GENLIB) -v core;                                                   \
	$(BBR) core -v -o core vdd 10 vss 10;

#####################################
#
# Extracting core
#
#   - Call LYNX
#
#####################################

core.al : core.ap
	@ MBK_CATA_LIB=$(ALL);   export MBK_CATA_LIB;                        \
	$(ENV_AL);                                                           \
	$(ENV_AP);                                                           \
	$(LYNX) -v core core

#####################################
#
# Netlist comparaison
#
#   - Call LVX
#
#   - Create a file for makefile dependances
#
#####################################

lvx_result_core : core.al
	@ MBK_CATA_LIB=$(ALL);   export MBK_CATA_LIB;                          \
	$(LVX) vst al core core
	touch lvx_result_core

#####################################
#
# How to make dlxm
#
#   - Call RING
#
#   - Extract the netlist from layout ( LYNX )
#
#   - Compare the netlist ( LVX )
#
#####################################

dlxm_routing : core_routing lvx_result_dlxm

#####################################
#
# Routing dlxm
#
#   - Call RING
#
#####################################

dlxm.ap : core.ap dlxm.rin
	@ MBK_CATA_LIB=.:$(ALL);     export MBK_CATA_LIB;                    \
	$(ENV_VST);                                                          \
	$(ENV_AP);                                                           \
	$(RING_EXE) dlxm dlxm

#####################################
#
# Extracting dlxm
#
#   - Call LYNX
#
#####################################

dlxm.al : dlxm.ap
	@ MBK_CATA_LIB=$(ALL);   export MBK_CATA_LIB;                        \
	$(ENV_AL);                                                           \
	$(ENV_AP);                                                           \
	$(LYNX) -v dlxm dlxm

#####################################
#
# Netlist comparaison
#
#   - Call LVX
#
#   - Create a file for makefile dependances
#
#####################################

lvx_result_dlxm : dlxm.al
	@ MBK_CATA_LIB=.:$(ALL); export MBK_CATA_LIB;                      \
	$(LVX) vst al dlxm dlxm
	touch lvx_result_dlxm

#####################################
#
# How to make real view of dlxm
#
#    - Call S2R : Generate the real view ( cif )
#
#####################################

dlxm_real : physical dlxm.cif

#####################################
#
# Creation of real view of dlxm
#
#   - Call S2R
#
#####################################

dlxm.cif : dlxm.ap
	@ MBK_CATA_LIB=.:$(ALL);              export MBK_CATA_LIB;           \
	$(ENV_RDS);                                                          \
	$(ENV_AP);                                                           \
	$(S2R) dlxm

#####################################
#
#       ... The End ...
#
#   - Pirouz . Julien . Mariem - 
#
#####################################

