

CMXA_LIB = unix.cmxa nums.cmxa str.cmxa bdd.cmxa polka.cmxa luc4ocaml.cmxa 
CMA_LIB=luc4ocaml.cma
LUC4OCAML_INSTALL_DIR = -I ../../../lib
# LUC4OCAML_INSTALL_DIR = -I +lucky


MAIN=rabbit

EXE=

ifeq ($(HOSTTYPE),win32)
   EXE=.exe
	LD_ARCH=-DWIN32
endif
ifeq ($(HOSTTYPE),cygwin)
	LD_ARCH=-DWIN32
endif
ifeq ($(HOSTTYPE),mac)
	LD_ARCH=-DMAC
endif
LUCKY=../../../bin/lucky$(EXE)
LUTIN=../../../bin/lutin$(EXE)
LUCKY_CPP=../../../bin/lucky_cpp




$(MAIN).opt:$(MAIN).ml
	ocamlopt.opt -cc g++ -cclib -lgmp $(LUC4OCAML_INSTALL_DIR) graphics.cmxa $(CMXA_LIB)  $(MAIN).ml -o $(MAIN).opt

$(MAIN):$(MAIN).ml
	ocamlc.opt $(LUC4OCAML_INSTALL_DIR) graphics.cma $(CMA_LIB)  $(MAIN).ml -o $(MAIN)


demo: $(MAIN).opt
	time ./$(MAIN).opt  50000 0.001 line

demo2: $(MAIN).opt
	time ./$(MAIN).opt 10000 0.0 line

clean:
	rm -rf *.top *.cmi *.cmo *.cmx *.o *.cma *.cmxa *.a *.cmi *.cmo *.cmi *.cmx *.o  *~ $(MAIN) $(MAIN).opt *~ *.pp_luc debug_bdd* Data *.pp_luc



%_lut.luc: crazy_rabbit.lut
	$(LUTIN) -o $@ $< -main $*

lut: moving-obstacle3.lut
	lutin -o moving-obstacle3-lut.luc moving-obstacle3.lut -main moving_obstacle
	lutin -o rabbit-speed-lut.luc rabbit-speed.lut -main 

test: clean $(MAIN).opt 
	./$(MAIN).opt 1000 0.0 test | grep -v "The random engine is initialized with the seed"
	rm -f test.res && diff -u -i $(MAIN).out.exp $(MAIN).out > test.res && \
	[ ! -s test.res ] && make clean 

utest:
	cp $(MAIN).out $(MAIN).out.exp




# A FAIRE
#
# 1 - determiner les sommets de l'obstacle avec get_vertices pour pouvoir
#     afficher le vrai obstacle
# 2 - Colorer l'obstacle en bleu pour pouvoir remettre les anciens points de
# la trajectoire

# 

###############################################################################
#
# one can use unixisms to compose lucky programs ...
rif:rabbit-speed.luc
	rm -f speed.rif; $(LUCKY) -l 2000 -pp $(LUCKY_CPP) rabbit-speed.luc $(LD_ARCH) | \
		grep outs | cut -d ' ' -f 2 | awk '{print $$1 " 0.0 500.0 0.0 500.0"}' | \
		$(LUCKY) rabbit-dir.luc > speed.rif

# gnuplot-rif has been messed-up (w.r.t. var declaration) by the one-lines above...
# so we remove the inputs decl
view_rif: rif
	rm -f speed2.rif ; cat speed.rif | sed -e 's/#inputs \"Speed\":real \"x_min\":real \"x_max\":real \"y_min\":real \"y_max\":real/#inputs/' > speed2.rif  && \
	gnuplot-rif -x11 speed2.rif

