# SXC: Compiler for a C-like language for the SX (Ubicom) microcontroller.
# Copyright (C) 1999 Blaise Gassend <blaise at gassend dot com> 
# and Franois-Marie Lefevere <francois-marie dot lefevere at m4x dot org>
#
# This code was almost entirely rewritten form an initial skeleton by Didier 
# Rmi, some of the original code probably remains.
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

default: all

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

SOURCES = \
	args.ml error.ml gen.ml  pp.ml code.ml ass.ml fasm.ml tracetype.ml \
	traceprep.ml bank.ml codegen.ml extractcalls.ml \
	smallset.ml liveness.ml partition.ml alloc.ml backend.ml \
	parser.mly lexer.mll ast.ml heap.ml page.ml trans.ml main3.ml heap.ml


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

EXEC = sxc
INTERP = nocaml

########################## 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)
LIBS= $(NUMS) 
# $(STR)

# 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) $(INTERP)

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 = $(SOURCES2:.ml=.cmx)

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

$(INTERP): $(OBJS)
	$(CAMLMKTOP) $(CUSTOM) -o $(INTERP) $(LIBS) $(OBJS)

$(EXEC).opt: $(OPTOBJS)
	$(CAMLOPT) -o $(EXEC) $(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 = ocamlc -g -w A
CAMLMKTOP = ocamlmktop -g -w A

CAMLOPT = ocamlopt -p 
# CAMLDEP = ocamldep
# CAMLLEX = ocamllex
# CAMLYACC = ocamlyacc
