CC = gcc
CAMLC = ocamlc -g -thread
CAMLMKTOP = ocamlmktop -g -thread
CAMLO = ocamlopt -thread
CAMLINC = -I ..

ZOBJS = unix.cma threads.cma ../gtk.cma ../libmlgtk.a
ZOBJSOPT = unix.cmxa threads.cmxa ../gtk.cmxa ../libmlgtk.a

.PHONY : clean distclean depend all all_opt

# To define GTKDEFINES, GLIB_CFLAGS and GLIB_LIBS:
include ../detect_gtk

LDFLAGS = "${GLIB_LIBS} $(shell gtk-config --libs)	\
		-lunix -lthreads -lpthread"
LDFLAGSOPT = "${GLIB_LIBS} $(shell gtk-config --libs)	\
		-lunix -lthreadsnat -lpthread"
#LDFLAGS = "${GLIB_LIBS} $(shell gtk-config --libs) -lunix -lthreads"

TESTS = tut_1 tut_2 tut_3 tut_4 tut_cat tut_threads
XTESTS = tut_1_opt tut_2_opt tut_3_opt tut_4_opt tut_cat_opt

all: $(TESTS) 
all_opt: $(XTESTS) 

#tut_3:	../../gtk.cma ../../libmlgtk.a tut_3.cmo
#	$(CAMLMKTOP) -custom -o $@ -cclib $(LDFLAGS) unix.cma threads.cma $^

t%: t%.cmo
	$(CAMLC) -custom -o $@ -cclib $(LDFLAGS)	\
		$(ZOBJS) $+

t%_opt: t%.cmx
	$(CAMLO) -o $@ -cclib $(LDFLAGSOPT)		\
		$(ZOBJSOPT) $+

tut_cat: pty.cmo tut_cat.cmo
	$(CAMLC) -custom -o $@ -cclib $(LDFLAGS)	\
		$(ZOBJS) $+

tut_cat_opt: pty.cmx tut_cat.cmx
	$(CAMLO) -o $@ -cclib $(LDFLAGSOPT)		\
		$(ZOBJSOPT) $+

tut_threads:  tut_threads.cmo
	$(CAMLMKTOP) -custom -o $@ -cclib $(LDFLAGS) 	\
		$(ZOBJS) $^

clean:
	-rm -f *.cm* *.o $(TESTS) $(XTESTS)

distclean: clean
	-rm .depend

depend:
	ocamldep $(CAMLINC) *.ml* >.depend

.depend:
	ocamldep *.ml* >.depend

.ml.cmo:
	$(CAMLC) $(CAMLINC) $(ZFLAGS) -c $<
.ml.cmx:
	$(CAMLO) $(CAMLINC) $(ZFLAGSOPT) -c $<
.mli.cmi:
	$(CAMLC) $(CAMLINC) $(ZFLAGS) -c $<

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

include .depend
