# La variable suivante est la SEULE chose  changer dans ce
# Makefile. Elle permet d'informer le Makefile sur le nom du fichier
# de description VHDL

CIBLE=diviseur

# Makefile pour la compilation d'un ASIC sur une technologie
# 1.0m. Les besoins sont:
#
#   - un fichier de description VHDL au format "vbe" (voir la page man)
#             nom : CIBLE.vbe
#   - un fichier de disposition des broches au format "rin"
#             nom : CIBLE.rin
#   - ventuellement un programme C de cration du fichier de simulation
#             nom : test_CIBLE.c

# Les divers tapes de la gnration de l'ASIC sont :
#   1) criture du fichier vhdl
#   2) lancement du test initial par : make testinitial
#   3) revenir en phase 1 si les rsultats ne sont pas bons
#         4) lancer make pour la compilation entire de l'ASIC
#   ou 4bis) lancer la compilation sans aucun test par : make TEST=non
#
#
# La compilation sans test se passe du fichier C de
# simulation. Nanmoins, cette possibilit n'a t implmente que
# dans le but d'acclrer la compilation d'un ASIC qui a dj t
# compil et test avec succs avant. Sinon, c'est une trs mauvaise
# ide.
#
# Toute erreur arrte le droulement du Makefile. Il faut alors
# corriger l'erreur et reprendre la compilation.


# A partir de maintenant, il n'y a plus besoin de toucher quoi que ce
# soit dans le Makefile. Tout se fait automatiquement.



ASIMUT=asimut -i 0
TEST=oui

all: $(CIBLE).cif

.PHONY: all testinitial clean tgz\
        testbop testscr testgenlib testring testretour testproof

core.vbe: $(CIBLE).vbe
	bop -o $(CIBLE) core ;\
	if test x$(TEST) = xoui; then make testbop; fi

core.vst: core.vbe
	scmap core core

core.ap: core.vst
	scr -p -r core core
	if test x$(TEST) = xoui; then make testscr; fi

$(CIBLE).c: $(CIBLE).vbe
	perl perl/creerring $(CIBLE)

$(CIBLE).vst: $(CIBLE).c core.vst
	genlib -v $(CIBLE)
	if test x$(TEST) = xoui; then make testgenlib; fi

$(CIBLE).ap: core.ap $(CIBLE).vst  $(CIBLE).rin
	ring $(CIBLE) $(CIBLE)
	if test x$(TEST) = xoui; then \
		make testring; \
		make testretour; \
		make testproof; \
	fi

# On effectue dans tous les cas un appel au design rule checker mais
# c'est par ignorance de l'utilit du fichier qu'il produit au
# programme s2r.
$(CIBLE).cif: $(CIBLE).ap $(CIBLE).drc
	RDS_TECHNO_NAME=$(TOP)/etc/prol10_7.rds ;\
	export RDS_TECHNO_NAME ;\
	s2r -v $(CIBLE)

## fichier de simulation comportementale sans les lignes d'alimentation #######
test.pat: test_$(CIBLE).c
	genpat test_$(CIBLE)

#### le mme simul et avec toutes les lignes d'alimentation ##################

# Notons : 
# les sorties ne sont connues qu'aprs simulation du fichier
# VHDL initial. C'est pour cela que la dpendance de
# "test_avec_alim.pat" est "testinitial.pat" et non "test.pat". Le
# script Perl demande comme argument "test" car il a besoin d'une base
# de nom et complte cette base par "initial.pat" pour le fichier
# d'entre et "_sans_alim.pat" pour le fichier de sortie.
test_avec_alim.pat: testinitial.pat
	perl perl/ajout_alim test

########### simulation comportementale initiale ##########################

testinitial.pat: test.pat $(CIBLE).vbe
	$(ASIMUT) -b $(CIBLE) test testinitial

testinitial: testinitial.pat
	waview testinitial.pat&

########## simulation comportementale aprs bop ##########################

testbop: testinitial.pat core.vbe
	$(ASIMUT) -b core testinitial testbop

################# vrification du travail de scmap ############################
# d'aprs certaines expriences que l'on a eu avec le tutorial
# addaccu, il se trouve que des fois une simulation sur le rsultat de
# scmap peut chouer lamentablement, alors qu'une simulation sur le
# rsultat de genlib va fonctionner sans aucun problme(et le
# reste). On delaye donc cette simulation aprs l'excution de genlib.

################# vrification du travail de genlib ###########################
testgenlib: test_avec_alim.pat $(CIBLE).vst
	$(ASIMUT) $(CIBLE) test_avec_alim testgenlib

######### vrification du routage du noyau (travail de scr) ###################

core.al : core.ap
	MBK_IN_PH=ap ;\
	MBK_OUT_LO=al ;\
	RDS_TECHNO_NAME=$(TOP)/etc/cmos_7.rds ;\
	MBK_CATA_LIB=$(TOP)/cells/sclib:$(TOP)/cells/padlib ;\
	export MBK_IN_PH MBK_OUT_LO RDS_TECHNO_NAME MBK_CATA_LIB ;\
	lynx -v core core

testscr : core.al core.vst
	MBK_CATA_LIB=$(TOP)/cells/sclib:$(TOP)/cells/padlib ;\
	export MBK_CATA_LIB ;\
	lvx vst al core core -f

########### vrification du routage noyau-pads (travail de ring) ##############

$(CIBLE).al : $(CIBLE).ap
	MBK_IN_PH=ap ;\
	MBK_OUT_LO=al ;\
	RDS_TECHNO_NAME=$(TOP)/etc/cmos_7.rds ;\
	MBK_CATA_LIB=$(TOP)/cells/sclib:$(TOP)/cells/padlib ;\
	export MBK_IN_PH MBK_OUT_LO RDS_TECHNO_NAME MBK_CATA_LIB ;\
	lynx -v $(CIBLE) $(CIBLE)

testring : $(CIBLE).al $(CIBLE).ap
	MBK_CATA_LIB=$(TOP)/cells/sclib:$(TOP)/cells/padlib ;\
	export MBK_CATA_LIB ;\
	lvx vst al $(CIBLE) $(CIBLE)


########### vrification par le design rule checker (druc) ####################

$(CIBLE).drc : $(CIBLE).ap
	MBK_IN_PH=ap ;\
	RDS_OUT=cif ;\
	RDS_TECHNO_NAME=$(TOP)/etc/cmos_7.rds ;\
	MBK_CATA_LIB=$(TOP)/cells/sclib:$(TOP)/cells/padlib ;\
	export MBK_IN_PH RDS_OUT RDS_TECHNO_NAME MBK_CATA_LIB ;\
	druc $(CIBLE)


########### simulation comportementale finale ###########################

$(CIBLE)e.al: $(CIBLE).ap
	MBK_IN_PH=ap ;\
	MBK_OUT_LO=al ;\
	RDS_TECHNO_NAME=$(TOP)/etc/cmos_7.rds ;\
	MBK_CATA_LIB=$(TOP)/cells/sclib:$(TOP)/cells/padlib ;\
	export MBK_IN_PH MBK_IN_LO MBK_OUT_LO RDS_TECHNO_NAME MBK_CATA_LIB ;\
	lynx -v -t $(CIBLE) $(CIBLE)e ;\

$(CIBLE)e.vbe: $(CIBLE)e.al $(CIBLE)e.inf
	MBK_IN_LO=al ;\
	RDS_TECHNO_NAME=$(TOP)/etc/cmos_7.rds ;\
	MBK_CATA_LIB=$(TOP)/cells/sclib:$(TOP)/cells/padlib ;\
	export MBK_IN_PH MBK_IN_LO MBK_OUT_LO RDS_TECHNO_NAME MBK_CATA_LIB ;\
	yagle $(CIBLE)e -v -i

testretour: test_avec_alim2.pat $(CIBLE)e.vbe
	$(ASIMUT) -b $(CIBLE)e test_avec_alim2 testretour

############ passage au prouveur formel #################################

$(CIBLE)e.inf $(CIBLE)v.vbe: $(CIBLE)e.al $(CIBLE).vbe
	perl perl/prepareproof $(CIBLE);

testproof: $(CIBLE)e.vbe $(CIBLE)v.vbe
	proof -p -d $(CIBLE)e $(CIBLE)v


###############################################################################
clean:
	rm -f typetest.h *.pat core* *.vst *.ap *.al *.lvx $(CIBLE)[a-z]* *~ *drc *cif $(CIBLE).c *.travail.* noclk

tgz: clean
	cd .. ;\
	tar cf - $(CIBLE) |gzip -9 >$(CIBLE).tgz
