#############################################################################
# Configuration section
#############################################################################

# Where to install the binary
BINDIR=/usr/local/bin

# Where to install the man pages
MANDIR=/usr/local/man

#############################################################################

#CONFIG
VERSION = 0.1
OPTS = -debug -assert -raise #  -typecheck -contract -profile -readable
PP = -pp cpp -pp "./fix_caml.pl -version=$(VERSION) $(OPTS) aspect.pl" 

#VERSION := $(shell cat VERSION)
#-pp "sed -e 's/__VERSION__/$(VERSION)/'" 
#-inline 0 # better when want debug, when want good backtrace of a coredump, ...
#PP = -pp "camlp4o ./pa_tywith.cmo"  -pp "camlp4o ./macro.cmo"   #  -dtypes
#could use -pp cpp and -Draise ..., cpp define too the __FILE and __LINE i think


ADDONSPATH = -I commons  

OCAMLRUNPARAM = 'b'
export OCAMLRUNPARAM

OCAMLC=ocamlc -g   $(PP) $(ADDONSPATH) -thread
OCAMLOPT=ocamlopt  $(PP) $(ADDONSPATH) -thread
OCAMLLEX=ocamllex
OCAMLYACC=ocamlyacc
OCAMLDEP=ocamldep $(PP) $(ADDONSPATH)
OCAMLMKTOP=ocamlmktop -g -custom $(PP) -thread $(ADDONSPATH)

LIBSMAIN = str unix threads

#agrep

SOURCECOMMON = 	commons/dumper.ml commons/suffix_tree.ml \
	commons/common.ml \
	commons/setb.ml commons/mapb.ml  commons/setPt.ml commons/seti.ml \
	commons/ocollection.ml \
	commons/oset.ml commons/oassoc.ml commons/osequence.ml commons/oarray.ml commons/ograph.ml \
	commons/oseti.ml commons/oseth.ml commons/osetb.ml commons/osetpt.ml \
	commons/oassocb.ml commons/oassoch.ml commons/oassoc_buffer.ml commons/oassocid.ml \
	commons/ograph2way.ml \
	commons/fullcommon.ml 

SOURCESPECIAL = $(SOURCECOMMON)  graph.ml flag.ml lib.ml message_lexer.ml message_parser.ml comm.ml bot.ml botrobber.ml botcop.ml  

SOURCEMAIN = $(SOURCECOMMON)  graph.ml flag.ml lib.ml message_lexer.ml message_parser.ml comm.ml bot.ml botrobber.ml botcop.ml main.ml 
SOURCEMYMAIN = $(SOURCECOMMON) graph.ml flag.ml lib.ml message_lexer.ml message_parser.ml comm.ml bot.ml botrobber.ml botcop.ml  mymain.ml




all: main.byte main.nc robber cop robber2 cop2

robber: $(SOURCESPECIAL:.ml=.cmx) robber.cmx
	$(OCAMLOPT) -o $@ $(LIBSMAIN:=.cmxa) $(SOURCESPECIAL:.ml=.cmx) robber.cmx

robber2: $(SOURCESPECIAL:.ml=.cmx) robber2.cmx
	$(OCAMLOPT) -o $@ $(LIBSMAIN:=.cmxa) $(SOURCESPECIAL:.ml=.cmx) robber2.cmx

cop: $(SOURCESPECIAL:.ml=.cmx) cop.cmx
	$(OCAMLOPT) -o $@ $(LIBSMAIN:=.cmxa) $(SOURCESPECIAL:.ml=.cmx) cop.cmx

cop2: $(SOURCESPECIAL:.ml=.cmx) cop2.cmx
	$(OCAMLOPT) -o $@ $(LIBSMAIN:=.cmxa) $(SOURCESPECIAL:.ml=.cmx) cop2.cmx


.PHONY: test
test:
	echo "" | ./robber || echo "" | ./robber2 || echo "" | ./cop || echo "" | ./cop2

#robber: main.nc
#	cp main.nc robber
#
#cop: main.nc
#	cp main.nc cop


main.nc: $(SOURCEMAIN:.ml=.cmx)
	$(OCAMLOPT) -o $@ $(LIBSMAIN:=.cmxa) $(SOURCEMAIN:.ml=.cmx)
clean:: 
#	rm -f main.nc

main.byte: $(SOURCEMAIN:.ml=.cmo)
	$(OCAMLC) -o $@ $(LIBSMAIN:=.cma) $(SOURCEMAIN:.ml=.cmo) 
clean:: 
	rm -f main.byte

main.top: $(SOURCEMAIN:.ml=.cmo)
	$(OCAMLMKTOP) -o $@ $(LIBSMAIN:=.cma) $(SOURCEMAIN:.ml=.cmo) 
clean:: 
	rm -f main.top


mymain.nc: $(SOURCEMYMAIN:.ml=.cmx)
	$(OCAMLOPT) -o $@ $(LIBSMAIN:=.cmxa) $(SOURCEMYMAIN:.ml=.cmx)
clean:: 
	rm -f mymain.nc

mymain.byte: $(SOURCEMYMAIN:.ml=.cmo)
	$(OCAMLC) -o $@ $(LIBSMAIN:=.cma) $(SOURCEMYMAIN:.ml=.cmo) 
clean:: 
	rm -f mymain.byte

mymain.top: $(SOURCEMYMAIN:.ml=.cmo)
	$(OCAMLMKTOP) -o $@ $(LIBSMAIN:=.cma) $(SOURCEMYMAIN:.ml=.cmo) 
clean:: 
	rm -f mymain.top



clean::
	rm -f commons/*.cm[iox] commons/*.o


#ocamlagrep/%: 
#	cd ocamlagrep; $(MAKE)

#SUBDIRS = ocamlagrep 

#clean::
#	for i in $(SUBDIRS) ; do cd $$i; $(MAKE) clean; cd ..;  done

#install:
#	cd compiler; $(MAKE) install
#depend:
#	cd compiler; $(MAKE) depend

#install:
#	cp scripts/*.lfs /usr/local/bin/
#	cp lfs /usr/local/bin/mount.lfs
#
#uninstall:
#	rm -f /usr/local/bin/*.lfs
#
#package:
#	cd "original/.ca/!todo/!RCS/!data/!thesis/!env/!cited/!history/!old/!backup/!figs/!html/!me/!paperasse/!perlfs/!publications/!website/"; tar cvfz ~/LFS-$(VERSION).tgz code/
#packagesmall:
#	cd "original/.ca/!docs/!todo/!RCS/!ext:ps/!name:man/!data/!thesis/!env/!cited/!history/!old/!backup/!figs/!html/!me/!paperasse/!perlfs/!publications/!website/"; tar cvfz ~/LFS-nodocs-$(VERSION).tgz code/






message_lexer.ml: message_lexer.mll
	$(OCAMLLEX) message_lexer.mll
beforedepend:: message_lexer.mll
clean::
	rm -f message_lexer.ml






#lexer.ml: lexer.mll
#	$(OCAMLLEX) lexer.mll
#clean::
#	rm -f lexer.ml
#beforedepend:: lexer.ml
#
#parser.ml parser.mli: parser.mly
#	$(OCAMLYACC) parser.mly
#clean::
#	rm -f parser.ml parser.mli parser.output
#beforedepend:: parser.ml parser.mli




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

.ml.cmo:
	$(OCAMLC) \
	 -c $<
.mli.cmi:
	$(OCAMLC) \
	 -c $<
.ml.cmx:
	$(OCAMLOPT) \
	 -c $<

clean::
	rm -f *.cm[iox] *.o

beforedepend::

depend:: beforedepend
	$(OCAMLDEP) *.mli *.ml > .depend

depend:: beforedepend
	$(OCAMLDEP) commons/*.mli commons/*.ml >> .depend

include .depend


