# Makefile for lablgtk.

OCAMLFINDDEPS = -package cairo2
COMPILER = $(OCAMLFIND) $(CAMLC) $(OCAMLFINDDEPS) $(MLFLAGS) $(MLBYTEFLAGS) -w s-3+52 -warn-error A-52 -c
LINKER = $(CAMLC) $(MLFLAGS) $(MLBYTEFLAGS)
COMPOPT = $(OCAMLFIND) $(CAMLOPT) $(OCAMLFINDDEPS) $(MLFLAGS) -w s -c
LINKOPT = $(CAMLOPT) $(MLFLAGS)
LIBRARIAN = $(CAMLMKLIB) -verbose -ocamlc "$(CAMLC)" -ocamlopt "$(CAMLOPT)"
TOPLEVEL = $(OCAMLFIND) $(CAMLMKTOP) $(OCAMLFINDDEPS) cairo.cma $(MLFLAGS)
CAMLP4 = $(CAMLP4O) pr_o.cmo

CONFIG = ../config.make

# protect against missing definitions
BINDIR = ""
LIBDIR = `ocamlfind query cairo2`
INSTALLDIR = $(LIBDIR)/lablgtk3
DLLDIR = $(LIBDIR)/stublibs

include $(CONFIG)
#GTKCFLAGS += -Werror -Wno-error=deprecated-declarations
GTKCFLAGS += -Wno-deprecated-declarations

TARGETS = varcc$(XE) lablgtktop$(XE) lablgtk3$(XB) gdk_pixbuf_mlsource3$(XE) \
	$(THINITOBJS) build.ml

all: dist byte
world: dist byte $(CAMLBEST)
install: findlib-install
uninstall: findlib-uninstall

MLLIBS = lablgtk.cma
CLIBS = liblablgtk3$(XA)
#MLLINK = unix.cma str.cma

# For -DG_LOG_DOMAIN=\"LablGTK\"
ifneq ($(TOOLCHAIN),msvc)
GTKCFLAGS += -imacros ml_domain.h
else
GTKCFLAGS += /FI ml_domain.h
endif

# compile using a custom version of mlvalues.h, where value is abstract
ifdef ABSVALUE
GTKCFLAGS += -Iabsvalue -DABSVALUE
endif

GTKCFLAGS += -I`ocamlfind query cairo2`

ifdef DEBUG
CFLAGS = -g $(GTKCFLAGS)
CUSTOM = -custom
#MLLINK += -cclib -lcamlrund
MLBYTEFLAGS = -g -dtypes
else
CFLAGS = -DG_DISABLE_ASSERT -DG_DISABLE_CAST_CHECKS $(GTKCFLAGS)
ifneq ($(TOOLCHAIN),msvc)
CFLAGS += -O
endif
endif

ifeq ($(THREADS_LIB),system)
THFLAGS = -thread
else
THFLAGS = -vmthread
CUSTOM = -custom
endif
THLINK = unix.cma threads.cma

ifdef USE_CC
CCOMPILER = $(CC) -c -I"$(LIBDIR)" $(CFLAGS)
else
CCOMPILER = $(CAMLC) -c -ccopt '$(CFLAGS)' -verbose
endif

ifdef USE_GL
ifdef LABLGLDIR
MLFLAGS += -I $(LABLGLDIR)
endif
MLLINK += lablgl.cma
MLLIBS += lablgtkgl.cma
CLIBS += liblablgtkgl3$(XA)
GLMLOBJS = glGtk.cmo
GLCOBJS = ml_gtkgl$(XO)
endif

#ifdef USE_GNOME
#MLLIBS += lablgnome.cma
#CLIBS += liblablgnome$(XA)
#GNOMEMLOBJS = gtkXmHTML.cmo gHtml.cmo
#GNOMECOBJS = ml_gtkxmhtml$(XO)
#endif

TARGETS += lablgladecc$(XE)

ifdef USE_GNOMECANVAS
MLLIBS += lablgnomecanvas.cma
CLIBS += liblablgnomecanvas$(XA)
GNOMECANVASMLOBJS = gnomeCanvas.cmo gnoCanvas.cmo
GNOMECANVASCOBJS = ml_gnomecanvas$(XO)
endif

ifdef USE_GNOMEUI
MLLIBS += lablgnomeui.cma
CLIBS += liblablgnomeui$(XA)
GNOMEUIMLOBJS = gnomeDruid.cmo gnoDruid.cmo
GNOMEUICOBJS = ml_gnomedruid$(XO)

ifdef USE_PANEL
MLLIBS += lablpanel.cma
CLIBS += liblablpanel$(XA)
PANELMLOBJS = panel.cmo
PANELCOBJS = ml_panel$(XO)
endif
endif


ifdef USE_RSVG
MLLIBS += lablrsvg.cma
CLIBS += liblablrsvg$(XA)
RSVGMLOBJS = rsvg.cmo
RSVGCOBJS = ml_rsvg$(XO)
$(RSVGCOBJS) : CFLAGS+=$(HAVE_SVGZ)
endif

ifdef USE_GTKSPELL
MLLIBS += lablgtkspell.cma
CLIBS += liblablgtkspell3$(XA)
GTKSPELLMLOBJS = gtkSpell.cmo
GTKSPELLCOBJS = ml_gtkspell$(XO)
endif

ifdef USE_GTKSOURCEVIEW3
ml_gtksourceview3.o: CFLAGS=$(GTKSOURCEVIEW3CFLAGS)
MLLIBS += lablgtksourceview3.cma
CLIBS += liblablgtksourceview3$(XA)
GTKSOURCEVIEW3MLOBJS = gtkSourceView3.cmo gSourceView3.cmo
GTKSOURCEVIEW3COBJS = ml_gtksourceview3$(XO)
GTKSOURCEVIEW3MLOBJSENUM = sourceView3Enums.cmo
GTKSOURCEVIEW3PROPS = gtkSourceView3.props
BEFORE_DEPEND += $(GTKSOURCEVIEW3PROPS:%.props=%Props.ml) $(GTKSOURCEVIEW3PROPS:%.props= o%Props.ml) $(GTKSOURCEVIEWMLOBJSENUM:%.cmo=%.ml)
EXTRA_OBJS += $(GTKSOURCEVIEW3MLOBJSENUM)
GTKSOURCEVIEW3ALLMLOBJS = $(GTKSOURCEVIEW3MLOBJSENUM) \
	$(GTKSOURCEVIEW3PROPS:%.props=%Props.cmo) \
	$(GTKSOURCEVIEW3PROPS:%.props=o%Props.cmo) $(GTKSOURCEVIEW3MLOBJS)
lablgtksourceview3.cma liblablgtksourceview3$(XA): \
  $(GTKSOURCEVIEW3COBJS) $(GTKSOURCEVIEW3ALLMLOBJS)
	$(LIBRARIAN) -o lablgtksourceview3 $^ $(GTKSOURCEVIEW3LIBS)
lablgtksourceview3.cmxa: \
  $(GTKSOURCEVIEW3COBJS) $(GTKSOURCEVIEW3ALLMLOBJS:.cmo=.cmx)
	$(LIBRARIAN) -o lablgtksourceview3 $^ $(GTKSOURCEVIEW3LIBS)
lablgtksourceview3.cmxs: DYNLINKLIBS=$(GTKSOURCEVIEW3_LIBS)
GTKSOURCEVIEWINSTALL=gtkSourceView3_types.mli
endif

ifdef USE_GTKQUARTZ
CFLAGS += -DHAS_GTKQUARTZ
endif
# Rules
.SUFFIXES: .ml .mli .cmo .cmi .cmx .cmxs .cmxa .c $(XO) .d$(XO) .var .h .opt .def .ml4
.c$(XO):
	$(CCOMPILER) $<
.cpp$(XO):
	$(CCOMPILER) $<
.c.d$(XO):
	$(CAMLC) -c -ccopt '-MT -DCAML_DLL -Fo$@ $(CFLAGS)' $<
.ml.cmo:
	$(COMPILER) $(PRINCIPAL) $<
.mli.cmi:
	$(COMPILER) $<
.ml.cmx:
	$(COMPOPT) $<
ifneq ($(CAMLP4O),no)
.ml4.ml:
	$(CAMLP4O) -impl $< -o $@
endif
#.ml4.cmo:
#	$(CAMLC) -c -pp "$(CAMLP4O) -impl" -impl $<
.cmxa.cmxs:
	$(CAMLOPT) -verbose -o $@ -shared -linkall -I . \
        -ccopt '$(filter -L%, $(DYNLINKLIBS))' $<

%_tags.h %_tags.c %Enums.ml: %_tags.var varcc$(XE)
	./varcc $<

%Props.ml o%Props.ml: %.props propcc$(XE)
	./propcc $<

# Files
GTKOBJS =  ml_gtk$(XO) ml_pango$(XO) ml_gtkaction$(XO) \
	ml_gtkbin$(XO) ml_gtkbutton$(XO) \
	ml_gtkassistant$(XO) \
	ml_gtkedit$(XO) ml_gtkfile$(XO) \
	ml_gtkmenu$(XO) ml_gtkmisc$(XO) \
	ml_gtkpack$(XO) ml_gtkrange$(XO) ml_gtkstock$(XO) \
	ml_gtktext$(XO) ml_gtktree$(XO) ml_gtkbuilder$(XO)
COBJS = ml_gdkpixbuf$(XO) ml_gdk$(XO) ml_glib$(XO) ml_gobject$(XO) \
	ml_gpointer$(XO) ml_gvaluecaml$(XO) wrappers$(XO) $(GTKOBJS) \
        cairo_pango_stubs$(XO)
GTKPROPS += gtkBase.props gtkContainers.props gtkBin.props gtkButton.props \
        gtkEdit.props gtkMenu.props gtkMisc.props gtkPack.props \
	gtkRange.props gtkText.props gtkTree.props gtkFile.props \
	gtkAction.props gtkAssistant.props gtkBuilder.props
MLOBJS1 =  gaux.cmo gpointer.cmo gutf8.cmo glib.cmo gobject.cmo
ENUMOBJS += gdkEnums.cmo pangoEnums.cmo gtkEnums.cmo
MLOBJS2 = pango.cmo gdk.cmo gdkEvent.cmo gdkKeysyms.cmo gdkPixbuf.cmo \
	gtk.cmo gtkSignal.cmo gtkStock.cmo gtkObject.cmo
MLOBJS3 = gtkData.cmo gtkBase.cmo gtkContainers.cmo gtkPack.cmo gtkButton.cmo \
	gtkAssistant.cmo \
	gtkMenu.cmo gtkMisc.cmo gtkWindow.cmo \
	gtkBin.cmo gtkEdit.cmo gtkRange.cmo gtkText.cmo gtkTree.cmo \
	gtkBuilder.cmo gtkFile.cmo gtkMain.cmo \
	gPango.cmo gDraw.cmo ogtkBaseProps.cmo gObj.cmo gData.cmo
MLOBJS4 = gMain.cmo gContainer.cmo gPack.cmo gButton.cmo gText.cmo \
	gMenu.cmo gMisc.cmo gTree.cmo gFile.cmo gWindow.cmo \
	gAssistant.cmo gBuilder.cmo \
	gBin.cmo gEdit.cmo gRange.cmo gAction.cmo \
	gUtil.cmo gToolbox.cmo cairo_pango.cmo
MLOBJS =  $(MLOBJS1) $(ENUMOBJS) $(MLOBJS2) $(GTKPROPS:.props=Props.cmo) \
	$(MLOBJS3) $(GTKPROPS:%.props=o%Props.cmo) $(MLOBJS4)
THOBJS = gtkThread.cmo
INITOBJS = gtkInit.cmo
ifdef USE_GTKQUARTZ
THINITOBJS = gtkThTop.cmo
else
THINITOBJS = gtkThInit.cmo
endif
EXTRAOBJS = $(INITOBJS) $(THOBJS) $(THINITOBJS)
ALLOBJS = $(MLOBJS) $(GLMLOBJS) $(GNOMEMLOBJS) \
	$(RSVGMLOBJS) $(GNOMECANVASMLOBJS) $(GNOMEUIMLOBJS) $(PANELMLOBJS) \
	$(GTKSOURCEVIEW3MLOBJS) $(GTKSPELLMLOBJS) \
	$(INITOBJS)
ALLTHOBJS = $(THOBJS) $(THINITOBJS)
PROPOBJS = $(GTKPROPS:%.props=%Props.cmo) $(GTKPROPS:%.props=o%Props.cmo)
ML4SRC = check_externals.ml propcc.ml varcc.ml

# Targets
byte:: $(TARGETS) $(INITOBJS)
opt::  $(TARGETS) lablgtkopt

depend:
	$(MAKE) real-depend USE_GL=1 USE_RSVG=1 \
	  USE_GNOMECANVAS=1 USE_GNOMEUI=1 USE_PANEL=1 USE_GTKSPELL=1 \
	  USE_GTKSOURCEVIEW3=1
real-depend: $(ENUMOBJS:.cmo=.ml) $(PROPOBJS:.cmo=.ml) $(BEFORE_DEPEND)
	ocamldep $(ALLOBJS:.cmo=.ml) $(PROPOBJS:.cmo=.ml) \
	  $(ALLTHOBJS:.cmo=.ml) $(BEFORE_DEPEND) *.mli > .depend

ifeq ($(THREADS_LIB),no)
lablgtktop$(XE): $(MLLIBS) $(CONFIG)
	$(TOPLEVEL) $(CUSTOM) -o $@ $(MLLINK) -I . $(MLLIBS)
else
lablgtktop$(XE): $(MLLIBS) $(THOBJS) $(CONFIG)
	$(TOPLEVEL) $(THFLAGS) $(CUSTOM) -o $@ $(THLINK) $(MLLINK) \
	   -I . $(MLLIBS) $(THOBJS)
endif

lablgtk3: Makefile $(CONFIG) lablgtk3.in
	sed -e "s|@INSTALLDIR@|$(LABLGTKDIR)|g" \
	    -e "s|@LABLGLDIR@|$(LABLGLDIR)|g" \
	    -e "s|@MLLIBS@|$(MLLINK) $(MLLIBS)|g" \
	    -e "s|@INITOBJS@|$(INITOBJS)|g" \
	    -e "s|@THOBJS@|$(THOBJS)|g" \
	    -e "s|@THINITOBJS@|$(THINITOBJS)|g" \
	    -e "s|@USEDLL@|$(HAS_DLL_SUPPORT)|g" \
	    -e "s|@THREADS_LIB@|$(THREADS_LIB)|g" \
	    < lablgtk3.in > $@
	chmod 755 $@

lablgtk3.bat: lablgtk3.bat.in
	cp lablgtk3.bat.in lablgtk3.bat

build.ml: Makefile $(CONFIG) build.ml.in
	sed -e "s|@LABLGTK_MLS@|$(MLOBJS:.cmo=)|" \
	    -e "s|@EXTRA_MLS@|$(EXTRAOBJS:.cmo=)|" \
	    -e "s|@PROP_MLS@|$(PROPOBJS:.cmo=)|" \
	    -e "s|@GTKLIBS@|$(GTKLIBS)|" \
	    -e "s|@RSVG_MLS@|$(RSVGMLOBJS:.cmo=)|" \
	    -e "s|@RSVG_LIBS@|$(RSVGLIBS)|" \
	    -e "s|@CANVAS_MLS@|$(GNOMECANVASMLOBJS:.cmo=)|" \
	    -e "s|@CANVAS_LIBS@|$(GNOMECANVASLIBS)|" \
	    -e "s|@SOURCEVIEW3_MLS@|$(GTKSOURCEVIEW3ALLMLOBJS:.cmo=)|" \
	    -e "s|@SOURCEVIEW3_LIBS@|$(GTKSOURCEVIEW3LIBS)|" \
	    -e "s|@TOOLCHAIN@|$(TOOLCHAIN)|" \
	    < build.ml.in > $@

gdk_pixbuf_mlsource3$(XE) : lablgtk.cma gdk_pixbuf_mlsource.ml
	$(OCAMLFIND) $(CAMLC) $(OCAMLFINDDEPS) -o $@ -I . cairo.cma $^

lablgtkopt:: $(MLLIBS:.cma=.cmxa) $(INITOBJS:.cmo=.cmx)
ifeq ($(THREADS_LIB),system)
lablgtkopt:: $(THOBJS:.cmo=.cmx)
endif

ifeq ($(HAS_NATIVE_DYNLINK),yes)
lablgtkopt::  $(MLLIBS:.cma=.cmxs)
endif

LABLGLADECCOBJS = gutf8.cmo xml_lexer.cmo lablgladecc.cmo

lablgladecc$(XE): $(LABLGLADECCOBJS)
	$(LINKER) -o $@ $(LABLGLADECCOBJS)

testcc$(XE): lablgladecc$(XE) lablgtktop
	./lablgladecc -test > testcc.ml
	./lablgtktop testcc.ml
	rm -f testcc.ml

PREOBJS= $(MLOBJS) $(EXTRAOBJS) $(RSVGMLOBJS) \
	$(GNOMECANVASMLOBJS) $(GTKSOURCEVIEW2ALLMLOBJS)

# Install ml sources and C binaries, can then rebuild using build.ml
preinstall:
	mkdir -p "$(INSTALLDIR)" "$(BINDIR)" "$(DLLDIR)"
	cp $(PREOBJS:.cmo=.ml) $(GTKSOURCEVIEW3INSTALL) "$(INSTALLDIR)"
	for f in $(PREOBJS:.cmo=.mli); do \
	  if test -f $$f; then cp $$f "$(INSTALLDIR)"; fi; done
	cp build.ml "$(INSTALLDIR)"
	cp lablgtk3$(XB) gdk_pixbuf_mlsource3$(XE) "$(BINDIR)"
	cp lablgladecc$(XE) "$(BINDIR)/lablgladecc3$(XE)"
	cp $(CLIBS) "$(INSTALLDIR)"
	cp $(CLIBS:lib%$(XA)=dll%$(XS)) "$(DLLDIR)"

# Install directly to $(INSTALLDIR), without using ocamlfind
old-install:
	mkdir -p "$(INSTALLDIR)" "$(BINDIR)" "$(DLLDIR)"
	cp $(ALLOBJS:.cmo=.cmi) $(EXTRA_OBJS:.cmo=.cmi) "$(INSTALLDIR)"
	cp -p ../META *.mli "$(INSTALLDIR)"
	cp -p $(ALLOBJS:.cmo=.ml) $(ALLTHOBJS:.cmo=.ml) \
	      $(EXTRA_OBJS:.cmo=.ml) build.ml "$(INSTALLDIR)"
	cp $(EXTRA_MLLIBS) $(MLLIBS) $(INITOBJS) "$(INSTALLDIR)"
	cp $(CLIBS) "$(INSTALLDIR)"
	cd "$(INSTALLDIR)" && $(RANLIB) $(CLIBS)
	cp varcc$(XE) propcc$(XE) "$(INSTALLDIR)"
	if test $(THREADS_LIB) != no; \
	   then cp $(ALLTHOBJS) $(ALLTHOBJS:.cmo=.cmi) "$(INSTALLDIR)"; \
	fi
	if test $(THREADS_LIB) = vm || test $(HAS_DLL_SUPPORT) != yes; \
	   then cp lablgtktop$(XE) "$(INSTALLDIR)"; \
	fi
	cp -p *.h "$(INSTALLDIR)"
	@if test -f lablgtk.cmxa; then $(MAKE) old-installopt; fi
	@if test -f dlllablgtk3$(XS); then $(MAKE) old-installdll; fi
	cp lablgtk3$(XB) "$(BINDIR)"
	if test -f lablgladecc$(XE); then \
	   cp lablgladecc$(XE) "$(BINDIR)/lablgladecc3$(XE)"; fi
	cp gdk_pixbuf_mlsource3$(XE) "$(BINDIR)"

old-installdll:
	cp $(CLIBS:lib%$(XA)=dll%$(XS)) "$(DLLDIR)" || \
	   echo "Couldn't install dlls in default location: $(DLLDIR)"
	if test -f dlllablgtk3$(XA); then \
	  cp $(CLIBS:lib%$(XA)=dll%$(XA)) "$(INSTALLDIR)"; fi

old-installopt:
	cp $(MLLIBS:.cma=.cmxa) $(MLLIBS:.cma=$(XA)) $(EXTRA_MLLIBS:.cma=.cmxa) $(EXTRA_MLLIBS:.cma=$(XA)) "$(INSTALLDIR)"
ifeq ($(HAS_NATIVE_DYNLINK),yes)
	cp $(MLLIBS:.cma=.cmxs) $(EXTRA_MLLIBS:.cma=.cmxs) "$(INSTALLDIR)"
endif
	cd "$(INSTALLDIR)" && $(RANLIB) $(MLLIBS:.cma=$(XA)) $(EXTRA_MLLIBS:.cma=$(XA))
	cp $(ALLOBJS:.cmo=.cmx) $(EXTRA_OBJS:.cmo=.cmx) "$(INSTALLDIR)"
	cp $(INITOBJS:.cmo=$(XO)) "$(INSTALLDIR)"
	if test -f gtkThread.cmx; then \
	   cp $(THOBJS:.cmo=.cmx) $(THOBJS:.cmo=$(XO)) "$(INSTALLDIR)"; fi

old-uninstall:
	rm -r "$(INSTALLDIR)"
	for f in $(CLIBS:lib%$(XA)=dll%$(XS)); \
	  do rm "$(DLLDIR)"/$$f; done
	for f in lablgladecc3$(XE) lablgtk3$(XB) gdk_pixbuf_mlsource3$(XE); \
	  do rm -f "$(BINDIR)"/$$f; done

# Install using ocamlfind
findlib-install:
	@if test "$(OCAMLFIND)" = no; then \
	  echo "Cannot use ocamlfind, use old-install."; \
	  exit 2; fi
	mkdir -p "$(BINDIR)"
	mkdir -p "$(DESTDIR)$(FINDLIBDIR)"
	@if test -f "$(DESTDIR)$(OCAMLLDCONF)"; then :; else \
	  mkdir -p "`dirname $(DESTDIR)$(OCAMLLDCONF)`"; \
	  touch "$(DESTDIR)$(OCAMLLDCONF)"; fi
	$(OCAMLFIND) install -destdir "$(DESTDIR)$(FINDLIBDIR)" \
	  -ldconf "$(DESTDIR)$(OCAMLLDCONF)" \
    lablgtk3 ../META \
    build.ml \
    $(CLIBS) \
    $(ALLOBJS:.cmo=.cmi) $(EXTRA_OBJS:.cmo=.cmi) \
    *.mli \
    $(ALLOBJS:.cmo=.ml) $(ALLTHOBJS:.cmo=.ml) $(EXTRA_OBJS:.cmo=.ml) \
    $(EXTRA_MLLIBS) $(MLLIBS) $(INITOBJS) \
    varcc$(XE) propcc$(XE) \
    `if test $(THREADS_LIB) != no; \
      then echo $(ALLTHOBJS) $(ALLTHOBJS:.cmo=.cmi) ; \
    fi` \
    `if test $(THREADS_LIB) = vm || test $(HAS_DLL_SUPPORT) != yes; \
      then echo lablgtktop$(XE) ; \
    fi` \
    *.h \
    `if test -f lablgtk.cmxa; \
      then \
        echo $(MLLIBS:.cma=.cmxa) $(MLLIBS:.cma=$(XA)) \
          $(EXTRA_MLLIBS:.cma=.cmxa) $(EXTRA_MLLIBS:.cma=$(XA)) ; \
          if test "$(HAS_NATIVE_DYNLINK)" = "yes" ; \
            then echo $(MLLIBS:.cma=.cmxs) $(EXTRA_MLLIBS:.cma=.cmxs) ; \
          fi; \
        echo  $(ALLOBJS:.cmo=.cmx) $(EXTRA_OBJS:.cmo=.cmx) ; \
        echo $(INITOBJS:.cmo=$(XO)) ; \
        if test -f gtkThread.cmx; then \
          echo $(THOBJS:.cmo=.cmx) $(THOBJS:.cmo=$(XO)) ; \
        fi ; \
    fi` \
    `if test -f dlllablgtk3$(XS); \
      then \
        echo "-dll $(CLIBS:lib%$(XA)=dll%$(XS)) -nodll" ; \
    fi` \
    `if test -f dlllablgtk3$(XA); \
      then \
        echo $(CLIBS:lib%$(XA)=dll%$(XA)) ; \
    fi`
	rm -f lablgtk3
	$(MAKE) lablgtk3 LABLGTKDIR="$(FINDLIBDIR)/lablgtk3"
	cp lablgtk3$(XB) "$(BINDIR)"
	if test -f lablgladecc$(XE); then \
	  cp lablgladecc$(XE) "$(BINDIR)/lablgladecc3$(XE)"; \
	fi
	cp gdk_pixbuf_mlsource3$(XE) "$(BINDIR)"
	$(RANLIB) $(CLIBS:%="$(FLINSTALLDIR)"/%)
	@if test -f lablgtk.cmxa; then \
	  echo "Execute $(RANLIB) in $(FLINSTALLDIR)"; \
	  $(RANLIB) $(MLLIBS:%.cma="$(FLINSTALLDIR)"/%$(XA)) \
		    $(EXTRA_MLLIBS:%.cma="$(FLINSTALLDIR)"/%$(XA)) ; \
	 fi

findlib-uninstall:
	$(OCAMLFIND) remove lablgtk3
	for f in lablgladecc3$(XE) lablgtk3$(XB) gdk_pixbuf_mlsource3$(XE); \
	  do rm -f "$(BINDIR)"/$$f; done

lablgtk.cma liblablgtk3$(XA): $(COBJS) $(MLOBJS)
	$(LIBRARIAN) -o lablgtk -oc lablgtk3 $^ $(GTKLIBS)
lablgtk.cmxa: $(COBJS) $(MLOBJS:.cmo=.cmx)
	$(LIBRARIAN) -o lablgtk -oc lablgtk3 $^ $(GTKLIBS)
lablgtk.cmxs: DYNLINKLIBS=$(GTK_LIBS)

lablgtkgl.cma liblablgtkgl3$(XA): $(GLCOBJS) $(GLMLOBJS)
	$(LIBRARIAN) -o lablgtkgl -oc lablgtkgl3 $^ $(GTKGLLIBS)
lablgtkgl.cmxa: $(GLCOBJS) $(GLMLOBJS:.cmo=.cmx)
	$(LIBRARIAN) -o lablgtkgl -oc lablgtkgl3 $^ $(GTKGLLIBS)
lablgtkgl.cmxs: DYNLINKLIBS=$(GTKGL_LIBS)

lablrsvg.cma liblablrsvg$(XA): $(RSVGCOBJS) $(RSVGMLOBJS)
	$(LIBRARIAN) -o lablrsvg $^ $(RSVGLIBS)
lablrsvg.cmxa: $(RSVGCOBJS) $(RSVGMLOBJS:.cmo=.cmx)
	$(LIBRARIAN) -o lablrsvg $^ $(RSVGLIBS)
lablrsvg.cmxs: DYNLINKLIBS=$(RSVG_LIBS)

lablgnomecanvas.cma liblablgnomecanvas$(XA): \
		$(GNOMECANVASCOBJS) $(GNOMECANVASMLOBJS)
	$(LIBRARIAN) -o lablgnomecanvas $^ $(GNOMECANVASLIBS)
lablgnomecanvas.cmxa: $(GNOMECANVASCOBJS) $(GNOMECANVASMLOBJS:.cmo=.cmx)
	$(LIBRARIAN) -o lablgnomecanvas $^ $(GNOMECANVASLIBS)
# gnoCanvas.cmo: COMPILER+= -i
lablgnomecanvas.cmxs: DYNLINKLIBS=$(GNOMECANVAS_LIBS)

lablgnomeui.cma liblablgnomeui$(XA): $(GNOMEUICOBJS) $(GNOMEUIMLOBJS)
	$(LIBRARIAN) -o lablgnomeui $^ $(GNOMEUILIBS)
lablgnomeui.cmxa: $(GNOMEUICOBJS) $(GNOMEUIMLOBJS:.cmo=.cmx)
	$(LIBRARIAN) -o lablgnomeui $^ $(GNOMEUILIBS)
# gnoDruid.cmo: COMPILER+= -i
lablgnomeui.cmxs: DYNLINKLIBS=$(GNOMEUI_LIBS)

lablpanel.cma liblablpanel$(XA): $(PANELCOBJS) $(PANELMLOBJS)
	$(LIBRARIAN) -o lablpanel $^ $(PANELLIBS)
lablpanel.cmxa: $(PANELCOBJS) $(PANELMLOBJS:.cmo=.cmx)
	$(LIBRARIAN) -o lablpanel $^ $(PANELLIBS)
lablpanel.cmxs: DYNLINKLIBS=$(PANEL_LIBS)

lablgtkspell.cma liblablgtkspell$(XA): $(GTKSPELLCOBJS) $(GTKSPELLMLOBJS)
	$(LIBRARIAN) -o lablgtkspell -oc lablgtkspell3 $^ $(GTKSPELLLIBS)
lablgtkspell.cmxa: $(GTKSPELLCOBJS) $(GTKSPELLMLOBJS:.cmo=.cmx)
	$(LIBRARIAN) -o lablgtkspell -oc lablgtkspell3 $^ $(GTKSPELLLIBS)
lablgtkspell.cmxs: DYNLINKLIBS=$(GTKSPELL_LIBS)

#gtkSignal.ml: gtkSignal.ml4
#	$(CAMLP4O) pa_macro.cmo $(HAS_PRINTEXC_BACKTRACE) -impl $< -o $@

gtkThread.cmo: gtkThread.ml $(CONFIG)
	$(COMPILER) $(THFLAGS) $<

gtkThread.cmi: gtkThread.mli $(CONFIG)
	$(COMPILER) $(THFLAGS) $<

gtkThread.cmx: gtkThread.ml $(CONFIG)
	$(COMPOPT) $(THFLAGS) $<

gtkThTop.cmo: gtkThTop.ml $(CONFIG)
	$(COMPILER) $(THFLAGS) -I +compiler-libs $<

xml_lexer.ml: xml_lexer.mll
	$(CAMLLEX) xml_lexer.mll
xml_lexer.cmo xml_lexer.cmx : xml_lexer.cmi

varcc$(XE): varcc.cmo
	$(LINKER) -o $@ $<
	rm -f *_tags.h *_tags.c

propcc$(XE): propcc.cmo
	$(LINKER) -o $@ $<

check_externals$(XE): check_externals.cmo
	$(LINKER) -o $@ $<

clean:
	rm -f *.cm* *.o *.a *.so *.exe *.obj *.lib *.dll *_tags.[ch] *.gch \
	  $(TARGETS) xml_lexer.ml propcc$(XE) check_externals$(XE) \
	  *Enums.ml *Props.ml
	rm -f \#*\# *~

dist: $(ML4SRC)
dist-clean:
	rm -f $(ML4SRC)


DOCFILES = gPango.ml gDraw.mli gObj.mli gMain.mli gData.mli \
	gContainer.mli gBin.mli gPack.mli gButton.mli gText.mli \
        gMenu.mli gMisc.mli gTree.mli gBuilder.mli gFile.mli gWindow.mli \
        gEdit.mli gRange.mli gAction.mli gUtil.mli gToolbox.mli \
	gaux.ml gpointer.mli glib.mli gobject.mli \
        gdkEnums.ml pangoEnums.ml gtkEnums.ml \
        gdk.mli gdkEvent.ml gdkPixbuf.mli \
        gtk.ml pango.ml gtkSignal.mli gtkObject.ml \
        gtkStock.ml gtkData.ml gtkBase.ml gtkPack.ml gtkButton.ml \
        gtkMenu.ml gtkMisc.ml gtkWindow.ml \
        gtkEdit.ml gtkRange.ml gtkText.ml gtkTree.ml gtkBuilder.ml \
        gtkFile.ml gtkMain.ml \
        $(GTKPROPS:%.props=%Props.ml)
DOCFILES += xml_lexer.mli
ifdef USE_GL
DOCFILES += glGtk.mli
endif
ifdef USE_RSVG
DOCFILES += rsvg.mli
endif
ifdef USE_GNOMECANVAS
DOCFILES += gnomeCanvas.ml gnoCanvas.mli
endif
ifdef USE_GNOMEUI
DOCFILES += gnomeDruid.ml gnoDruid.mli
endif
ifdef USE_PANEL
DOCFILES += panel.mli
endif
ifdef USE_GTKSPELL
DOCFILES += gtkSpell.mli
endif
ifdef USE_GTKSOURCEVIEW3
DOCFILES += gSourceView3.mli
endif

OCAMLDOC = ocamldoc
lablgtk.odoc : $(DOCFILES) $(ALLOBJS)
	$(OCAMLDOC) -dump $@ $(if $(LABLGLDIR),-I $(LABLGLDIR)) $(DOCFILES)
gtkdoc.cmo : gtkdoc.ml
	$(CAMLC) -I +ocamldoc -pp "$(CAMLP4O) pa_macro.cmo $(ODOC_DEF)" -c $<
DOCDIR=../doc
#DOC_URI=file:///usr/share/gtk-doc/html
DOC_BASE_URI=$(if $(DOC_URI),-base-uri $(DOC_URI))
doc : lablgtk.odoc gtkdoc.cmo
	mkdir -p $(DOCDIR)/html
	$(OCAMLDOC) -sort -g ./gtkdoc.cmo $(DOC_BASE_URI) -t LablGTK -d $(DOCDIR)/html -load $<
doc_texi : lablgtk.odoc
	$(OCAMLDOC) -texi -t LablGTK -o $(DOCDIR)/lablgtk3.texi -load $<

$(GTKOBJS): pango_tags.h gtk_tags.h ml_gtk.h gdk_tags.h ml_gdk.h \
	    ml_gobject.h ml_glib.h wrappers.h
$(GNOMEUICOBJS) : gnomeui_tags.h
$(PANELCOBJS) : panel_tags.h
$(GTKSOURCEVIEW3COBJS):  ml_glib.h ml_gdk.h ml_gtk.h ml_gobject.h ml_gdkpixbuf.h ml_pango.h \
			gtk_tags.h gdk_tags.h ml_gtktext.h sourceView3_tags.h wrappers.h

ml_glib$(XO): glib_tags.h ml_glib.h wrappers.h
ml_gobject$(XO): gobject_tags.h ml_gvaluecaml.h wrappers.h
ml_gvaluecaml$(XO): ml_gobject.h wrappers.h
ml_gdk$(XO): gdk_tags.h ml_gdk.h ml_gpointer.h \
	pango_tags.h ml_pango.h wrappers.h
ml_gtk$(XO) ml_gtktext$(XO): ml_pango.h
ml_gtkgl$(XO): gtkgl_tags.h ml_gtk.h ml_gdk.h wrappers.h
ml_gtkxmhtml$(XO): gtkxmhtml_tags.h ml_gtk.h ml_gdk.h wrappers.h
ml_gpointer$(XO): ml_gpointer.h
ml_gdkpixbuf$(XO): ml_gdkpixbuf.h gdkpixbuf_tags.h ml_gdk.h gdk_tags.h \
	wrappers.h ml_gpointer.h
ml_pango$(XO): pango_tags.h ml_pango.h
ml_rsvg$(XO): ml_gobject.h ml_gdkpixbuf.h wrappers.h
ml_gnomecanvas$(XO): ml_gtk.h ml_gobject.h wrappers.h
ml_gnomedruid$(XO): ml_gtk.h ml_gobject.h wrappers.h
ml_panel$(XO): ml_gtk.h ml_gobject.h wrappers.h

include .depend
