#--------------------------------------------------------
# Makefile
#--------------------------------------------------------
# C'est sous RCS. Pour creer un document RCS :
#
#        _ tu cree un repertoire RCS s'il n'existe pas deja.
#
#        _ tu cree le master -> C-x v i
#
#        _ pour editer (prendre ou rendre)
#          tu utilise C-x C-q qui change le chmod du fichier
#          et appelle automatiquement RCS si le directory
#          RCS exite...
#


# Les flags de compilation. Note: on ne peut pas avoir DEBUG et PROFILE vrais en meme temps. Ils sont
# exclusifs.

DEBUG    = yes
PROFILE  = no


ifeq ($(DEBUG), yes)
	CAMLFLAGS=-g
else
	CAMLFLAGS=-pflm
endif

# Parametrage suivant l'archi par un nom 
# de repertoire fournit par archi_mach
#
LOCAL_ARCH= $(shell /local/Archi/COMMON/archi_mach)

# Ou chercher CAMLLIGHT ?
#

ifeq ($(LOCAL_ARCH), SGI)
	ARCHI=Archi2			# En effet, pour SGI, plus de place en Archi !...
else
	ARCHI=Archi
endif

CAMLC   = /local/$(ARCHI)/$(LOCAL_ARCH)/camlc $(CAMLFLAGS)
CAMLYACC= /local/$(ARCHI)/$(LOCAL_ARCH)/camlyacc 
CAMLLEX = /local/$(ARCHI)/$(LOCAL_ARCH)/camllex


# Parametrage SYSV et BSD: 
# nos paths sont pas completement transparent, alors on fait a la main
#
ifeq  ($(LOCAL_ARCH),SOLARIS2.1)
	CC = /opt/SUNWspro/bin/cc 
	LINT = /opt/SUNWspro/bin/lint
	RANLIB = echo                 # plus besoin de ranlib en SYSV
else
	CC = cc
	RANLIB = ranlib   
endif


# Les includes changent en fonction de la presence de readline.
#


#-------------------------------------------------------
# New Universe

SRC_INTERFACES=\
	complex-lib.mli\
	esq-kernel.mli

# Mettre dans cette liste tous les .ml, meme ceux qui sont produit
# automatiquement. Les mettre au bon endroit, c'est a dire la ou il
# a la place que le .zo doit avoir lors de la compilation. S'il y a
# un .mli associe, le mettre a une position en accord.


SRC_ML=\
	complex-lib.ml\
	esq-kernel.ml\
	univers-geo.ml

# -------------------------------------------------------

SRC_LEX=

SRC_YACC=

OTHERS=

# -------------------------------------------------------

SOURCES  = $(SRC_INTERFACES) $(SRC_LEX) $(SRC_YACC) $(SRC_ML)
CODES_ML = $(SRC_INTERFACES) $(SRC_ML) $(OBJ1)

OBJ1 = $(SRC_YACC:.mly=.ml) $(SRC_LEX:.mll=.ml) 
OBJ2 = $(SRC_INTERFACES:.mli=.zi) $(SRC_YACC:.mly=.zi)

OBJETS   = $(SRC_ML:.ml=.zo) $(OBJ1:.ml=.zo)


esqimo:	$(OBJETS)
	camlmktop -o esqimo  $(OBJETS)
	camllight esqimo


all:	$(SOURCES) $(OBJETS)
	@echo  $(SOURCES)
	@echo  $(OBJETS)
	make tags
	make esqimo


tags:
	make TAGS

TAGS:	$(SOURCES)
	mletags  $(SRC_ML) $(SRC_INTERFACES) > TAGS
	etags -o .tmp $(SRC_C)
	cat .tmp >> TAGS
	\rm .tmp


param:
	@echo LOCAL_ARCH    = $(LOCAL_ARCH)
	@echo CAMLC         = $(CAMLC)
	@echo CC            = $(CC)
	@echo RANLIB        = $(RANLIB)
	@echo LD            = $(LD)
	@echo C_INCLUDE_DIR = $(C_INCLUDE_DIR)


clean scratch:
	rm -f	*.z[io] *.o  *.a 

# ----------------------------------------------------------------------------
# Regles implicites

%.zi:	%.mli
	$(CAMLC) -c $<

%.zo:	%.ml
	$(CAMLC) -c $<

%.zi:	%.ml			# Creation du .zi a partir du .ml si le .mli
	$(CAMLC) -c $<		# n'existe pas (regle apparait apres l'autre)

%.mli %.ml:	%.mly
		$(CAMLYACC) $<

%.ml:	%.mll
	$(CAMLLEX) $<

%.type:	%.ml %.zi         # dans cet ordre, pour que $< refere a %.ml
	$(CAMLC) -i $<


# -------------------------------------------------------
# Generation automatique de fichiers sources

# -------------------------------------------------------
# DEPENDANCES


DOLLAR=$$

depend:	$(SRC_ML) $(SRC_INTERFACES)
	perl /local/$(ARCHI)/$(LOCAL_ARCH)/camldep $(SRC_ML) $(SRC_INTERFACES) > .Makefile.Dep
	@ echo  
	@ echo "===> Dependances dans .Makefile.Dep
	@ echo 


.dependances:	$(SOURCES)
	$(MAKE) dependances



## ===========================================================


include .Makefile.Dep

