default: ppc

test: test/ok

test/ok: ppc
	cd test; make

help: 
	echo 'Lire le fichier README donc voici le contenu:'
	@cat README

#######################  Mandatory User's variables  #####################
#
# The Caml sources (including camlyacc and camllex source files)

SOURCES = misc.ml pp.mli print.ml env.ml \
   gen.ml frame.ml code.mli ast.ml trans.ml canon.ml \
   ass.ml spim.ml smallset.ml \
   liveness.ml partition.ml talloc.ml \
   memograph.ml draw.ml alloc.ml lexer.mll parser.mly \
   interpret.ml simul.ml \
   main.ml

clean::
	rm -f lexer.ml parser.ml parser.mli *.out

EXEC = ppc

########################## Optional user's variables #####################
#
# The list of Caml libraries needed by the program
# For instance:
# LIBS=$(GRAPHICS) $(UNIX) $(STR) $(NUMS) $(THREADS) $(DBM)
LIBS=$(GRAPHICS)  $(UNIX)

# Should be set to -custom if you use any of the libraries above
# or if any C code have to be linked with your program
# (irrelevant for ocamlopt)
CUSTOM=-custom

# You may fix here the path to access the Caml compiler on your machine
# You may also have to add various -I options.
CAMLC = ocamlc
CAMLOPT = ocamlopt
CAMLDEP = ocamldep
CAMLLEX = ocamllex
CAMLYACC = ocamlyacc

# The list of Caml libraries needed by the program
# For instance:
# LIBS=$(GRAPHICS) $(UNIX) $(STR) $(NUMS) $(THREADS) $(DBM)


# Should be set to -custom if you use any of the libraries above
# or if any C code have to be linked with your program
# (irrelevant for ocamlopt)
# CUSTOM=-custom

# Default setting of the * variables. Should be changed if your
# local libraries are not found by the compiler.

GRAPHICS =graphics.cma -cclib -lgraphics -cclib -L/usr/X11R6/lib -cclib -lX11

UNIX =unix.cma -cclib -lunix

STR =str.cma -cclib -lstr

NUMS =nums.cma -cclib -lnums

THREADS =threads.cma -cclib -lthreads

DBM =dbm.cma -cclib -lmldbm -cclib -lndbm

################ End of user's variables #####################


##############################################################
################ This part should be generic
################ Nothing to set up or fix here
##############################################################

all: .depend $(EXEC)

opt : $(EXEC).opt

#ocamlc -custom other options graphics.cma other files -cclib -lgraphics -cclib -lX11
#ocamlc -thread -custom other options threads.cma other files -cclib -lthreads
#ocamlc -custom other options str.cma other files -cclib -lstr
#ocamlc -custom other options nums.cma other files -cclib -lnums
#ocamlc -custom other options unix.cma other files -cclib -lunix
#ocamlc -custom other options dbm.cma other files -cclib -lmldbm -cclib -lndbm

SOURCES1 = $(SOURCES:.mly=.ml)
SOURCES2 = $(SOURCES1:.mll=.ml)
OBJS = $(filter %.cmo,$(SOURCES2:.ml=.cmo))
OPTOBJS = $(filter %.cmx,$(SOURCES2:.ml=.cmx)) 

$(EXEC): $(OBJS)
	$(CAMLC) $(CUSTOM) -o $(EXEC) $(LIBS) $(OBJS)

$(EXEC).opt: $(OPTOBJS)
	$(CAMLOPT) -o $(EXEC).opt $(LIBS:.cma=.cmxa) $(OPTOBJS)

.SUFFIXES: .ml .mli .cmo .cmi .cmx .mll .mly

.ml.cmo:
	$(CAMLC) -c $<

.mli.cmi:
	$(CAMLC) -c $<

.ml.cmx:
	$(CAMLOPT) -c $<

.mll.cmo:
	$(CAMLLEX) $<
	$(CAMLC) -c $*.ml

.mll.cmx:
	$(CAMLLEX) $<
	$(CAMLOPT) -c $*.ml

.mly.cmo:
	$(CAMLYACC) $<
	$(CAMLC) -c $*.mli
	$(CAMLC) -c $*.ml

.mly.cmx:
	$(CAMLYACC) $<
	$(CAMLOPT) -c $*.mli
	$(CAMLOPT) -c $*.ml

.mly.cmi:
	$(CAMLYACC) $<
	$(CAMLC) -c $*.mli

.mll.ml:
	$(CAMLLEX) $<

.mly.ml:
	$(CAMLYACC) $<

clean::
	rm -f *.cm[iox] *~ .*~ #*#
	rm -f $(EXEC)
	rm -f $(EXEC).opt

.depend.input: Makefile
	@echo -n '--Checking Ocaml input files: '
	@(ls $(SOURCES2) $(SOURCES2:.ml=.mli) 2>/dev/null || true) \
	     >  .depend.new
	@diff .depend.new .depend.input 2>/dev/null 1>/dev/null && \
	  (echo 'unchanged'; touch .depend.input; rm -f .depend.new) || \
	  (echo 'changed'; touch .depend.needed; mv .depend.new .depend.input)

depend: $(SOURCES2) .depend.input
	@touch .depend.needed
	@make .depend

.depend.needed:
	@touch .depend.needed

.depend:: .depend.needed
	@echo -n '--Re-building dependencies: '
	@$(CAMLDEP) $(SOURCES2) $(SOURCES2:.ml=.mli) > .depend
	@echo  'done'

include .depend


##########################  Continue  customization  #####################
# The Caml compilers.
# You may fix here the path to access the Caml compiler on your machine
# You may also have to add various -I options.

CAMLC = ocamlcp -p f
CAMLC = ocamlc.opt -g -w p

CAMLOPT = ocamlopt.opt
 
# CAMLDEP = ocamldep
# CAMLLEX = ocamllex
# CAMLYACC = ocamlyacc
