# An ocaml library is a unique project type in the context of LLVM, so rules are
# here rather than in Makefile.rules.
#
+# Reference materials on installing ocaml libraries:
+#
+# https://fedoraproject.org/wiki/Packaging/OCaml
+# http://pkg-ocaml-maint.alioth.debian.org/ocaml_packaging_policy.txt
+#
##===----------------------------------------------------------------------===##
include $(LEVEL)/Makefile.config
-# Find the ocaml stdlib root. /usr/local/lib/ocaml is the default when built
-# from source; distros use something like /usr/lib/ocaml/3.10.0.
-ifndef OCAML_LIBDIR
-OCAML_LIBDIR := $(shell $(OCAMLC) -where)
-endif
-
-# CFLAGS needs to be set before Makefile.rules is included. Yes, ocaml puts its
-# includes under its libdir.
-CFLAGS += -I$(OCAML_LIBDIR)
+# CFLAGS needs to be set before Makefile.rules is included.
+CFLAGS += -I$(shell $(OCAMLC) -where)
include $(LEVEL)/Makefile.common
# Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the
-# user can override this with OCAML_LIBDIR.
+# user can override this with OCAML_LIBDIR or configure --with-ocaml-libdir=.
PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR)
OcamlDir := $(LibDir)/ocaml
# Tools
OCAMLCFLAGS += -I $(OcamlDir) -I $(ObjDir)
OCAMLAFLAGS += $(patsubst %,-cclib %, \
- $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \
- $(UsedLibs) -l$(LIBRARYNAME))
-
-Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
-Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) -o)
-Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) -o)
-
-Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) -o)
-Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) -o)
+ $(filter-out -L$(LibDir),-l$(LIBRARYNAME) \
+ $(shell $(LLVM_CONFIG) --ldflags)) \
+ $(UsedLibs))
+
+# -g was introduced in 3.10.0.
+#ifneq ($(ENABLE_OPTIMIZED),1)
+# OCAMLDEBUGFLAG := -g
+#endif
+
+Compile.CMI := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
+Compile.CMO := $(strip $(OCAMLC) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
+Archive.CMA := $(strip $(OCAMLC) -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \
+ -o)
+
+Compile.CMX := $(strip $(OCAMLOPT) -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
+Archive.CMXA := $(strip $(OCAMLOPT) -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o)
# Source files
OcamlSources1 := $(sort $(wildcard $(PROJ_SRC_DIR)/*.ml))
OutputCMXA := $(LibraryCMXA:$(ObjDir)/%.cmxa=$(OcamlDir)/%.cmxa)
OutputsCMI := $(ObjectsCMI:$(ObjDir)/%.cmi=$(OcamlDir)/%.cmi)
OutputsCMX := $(ObjectsCMX:$(ObjDir)/%.cmx=$(OcamlDir)/%.cmx)
+OutputLibs := $(UsedLibNames:%=$(OcamlDir)/%)
# Installation targets
DestA := $(PROJ_libocamldir)/lib$(LIBRARYNAME).a
DestCMA := $(PROJ_libocamldir)/$(LIBRARYNAME).cma
DestCMXA := $(PROJ_libocamldir)/$(LIBRARYNAME).cmxa
+DestLibs := $(UsedLibNames:%=$(PROJ_libocamldir)/%)
##===- Dependencies -------------------------------------------------------===##
-$(Verb) $(RM) -f $(DestA)
+##===- Deposit dependent libraries adjacent to Ocaml libs -----------------===##
+
+all-local:: build-deplibs
+clean-local:: clean-deplibs
+install-local:: install-deplibs
+uninstall-local:: uninstall-deplibs
+
+build-deplibs: $(OutputLibs)
+
+$(OcamlDir)/%.a: $(LibDir)/%.a
+ $(Verb) ln -sf $< $@
+
+$(OcamlDir)/%.o: $(LibDir)/%.o
+ $(Verb) ln -sf $< $@
+
+clean-deplibs:
+ $(Verb) rm -f $(OutputLibs)
+
+install-deplibs:
+ $(Verb) for i in $(DestLibs:$(PROJ_libocamldir)/%=%); do \
+ ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
+ done
+
+uninstall-deplibs:
+ $(Verb) rm -f $(DestLibs)
+
+
##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
all-local:: build-cmis
$(LibraryCMA): $(ObjectsCMO) $(OcamlDir)/.dir
$(Echo) "Archiving $(notdir $@) for $(BuildMode) build"
$(Verb) $(Archive.CMA) $@ $(ObjectsCMO)
- $(Verb) for i in $(UsedLibNames); do \
- ln -sf "$(LibDir)/$$i" "$(OcamlDir)/$$i"; \
- done
$(ObjDir)/%.cmo: $(ObjDir)/%.ml
$(Echo) "Compiling $(notdir $<) for $(BuildMode) build"
$(Echo) "Installing $(BuildMode) $(DestCMA)"
$(Verb) $(MKDIR) $(PROJ_libocamldir)
$(Verb) $(DataInstall) $(OutputCMA) "$(DestCMA)"
- $(Verb) for i in $(UsedLibNames); do \
- $(EchoCmd) "Installing $(BuildMode) $(PROJ_libocamldir)/$$i"; \
- ln -sf "$(PROJ_libdir)/$$i" "$(PROJ_libocamldir)/$$i"; \
- done
uninstall-cma::
$(Echo) "Uninstalling $(DestCMA)"
-$(Verb) $(RM) -f $(DestCMA)
- $(Verb) for i in $(UsedLibNames); do \
- $(EchoCmd) "Uninstalling $(PROJ_libocamldir)/$$i"; \
- $(RM) -f "$(PROJ_libocamldir)/$$i"; \
- done
##===- Build optimized ocaml archive (.ml's -> .cmx's -> .cmxa, .a) -------===##