#**************************************************************************
#*                                                                        *
#*                                 OCaml                                  *
#*                                                                        *
#*             Florian Angeletti, projet Cambium, Inria Paris             *
#*                                                                        *
#*   Copyright 2020 Institut National de Recherche en Informatique et     *
#*     en Automatique.                                                    *
#*                                                                        *
#*   All rights reserved.  This file is distributed under the terms of    *
#*   the GNU Lesser General Public License version 2.1, with the          *
#*   special exception on linking described in the file LICENSE.          *
#*                                                                        *
#**************************************************************************

OCAMLDOC = $(ROOTDIR)/ocamldoc/ocamldoc$(EXE)
OCAMLDOC_OPT = $(ROOTDIR)/ocamldoc/ocamldoc.opt$(EXE)

ifeq "$(TARGET)" "$(HOST)"
  ifeq "$(SUPPORTS_SHARED_LIBRARIES)" "true"
    OCAMLDOC_RUN_BYTE = $(OCAMLRUN) -I $(ROOTDIR)/otherlibs/$(UNIXLIB) \
                                    -I $(ROOTDIR)/otherlibs/str ./$(OCAMLDOC)
  else
    # if shared-libraries are not supported, unix.cma and str.cma
    # are compiled with -custom, so ocamldoc also uses -custom,
    # and (ocamlrun ocamldoc) does not work.
    OCAMLDOC_RUN_BYTE = ./$(OCAMLDOC)
  endif
else
  OCAMLDOC_RUN_BYTE = $(OCAMLRUN) ./$(OCAMLDOC)
endif

OCAMLDOC_RUN_OPT = ./$(OCAMLDOC_OPT)

OCAMLDOC_RUN_PLUGINS = $(OCAMLDOC_RUN_BYTE)

ifeq "$(wildcard $(OCAMLDOC_OPT))" ""
  OCAMLDOC_RUN = $(OCAMLDOC_RUN_BYTE)
else
  OCAMLDOC_RUN = $(OCAMLDOC_RUN_OPT)
endif
