CAMLC=ocamlc
CAMLCOMP=$(CAMLC) -c
COMPFLAGS=-I ../libsupport -I ../lib -I ../frx

all: safetk.mli safetk.ml safetk.cmi safetk.cmo safefrx.cmi safefrx.cmo

# support.ml / protocol.ml: defined by hand
# tk:
#   types extracted from tkgen.ml
#   functions from tkgen.mli (generated)
#   and from tkgen.ml (builtin)

include ../lib/modules


# Extract type definitions
# Add sharing
tktypes.ml: ../lib/tk.ml
	sed -n -e '/^(\* type \*)$$/,/^(\* \/type \*)$$/p' ../lib/tk.ml | \
	sed -e '/^(\* type \*)$$/d' -e '/^(\* \/type \*)$$/d' | \
        sed -e 's/^type \([a-z][a-zA-Z_]*\) =$$/type \1 = Tk.\1 =/' \
         > tktypes.ml

tkfunctions.ml: ../lib/tk.ml
	(sed -n -e '/^FUNCTION$$/,/^\/FUNCTION$$/p' ../lib/tk.ml |\
         sed -e '/FUNCTION/d'; \
	cat ../lib/tkgen.mli) | \
	sed -e '/^(\* unsafe \*)$$/,/^(\* \/unsafe \*)$$/d' \
        > tkfunctions.ml

safetk.ml: support.ml protocol.ml tktypes.ml tkfunctions.ml textvariable.ml
	(cat support.ml;\
	cat protocol.ml;\
	cat textvariable.ml;\
	cat tk.ml; \
	for i in optionmenu.cmo dialog.cmo ; do\
	 m=`basename $$i .cmo`;\
	 mm=`./capitalize $$m`;\
	 echo "module $$mm = $$mm";\
	done;\
	for i in $(WIDGETOBJS) ; do\
	 m=`basename $$i .cmo`;\
	 mm=`./capitalize $$m`;\
	 echo "module $$mm = $$mm";\
	done) > safetk.ml

safetk.mli: support.mli protocol.mli tktypes.ml tkfunctions.ml textvariable.mli
	(cat support.mli;\
	cat protocol.mli;\
	cat textvariable.mli;\
	echo "module Tk : sig";\
	echo "open Support";\
	echo "open Textvariable";\
	  cat report.ml;\
	  cat tktypes.ml;\
	  cat tkfunctions.ml;\
	  echo "end";\
	for i in optionmenu.cmo dialog.cmo ; do\
	 m=`basename $$i .cmo`;\
	 mm=`./capitalize $$m`;\
	 echo "module $$mm : sig";\
	 sed -e '/^(\* unsafe \*)$$/,/^(\* \/unsafe \*)$$/d' ../libsupport/$$m.mli;\
	 echo "end";\
	 echo;\
	done;\
	for i in $(WIDGETOBJS) ; do\
	 m=`basename $$i .cmo`;\
	 mm=`./capitalize $$m`;\
	 echo "module $$mm : sig";\
	 sed -e '/^(\* unsafe \*)$$/,/^(\* \/unsafe \*)$$/d' ../lib/$$m.mli;\
	 echo "end";\
	 echo;\
	done) > safetk.mli


clean:
	rm -f *.cm? safetk.ml safetk.mli tktypes.ml tkfunctions.ml

.SUFFIXES :
.SUFFIXES : .mli .ml .cmi .cmo .mlp

.mli.cmi:
	$(CAMLCOMP) $(COMPFLAGS) $<

.ml.cmo:
	$(CAMLCOMP) $(COMPFLAGS) $<

