IR: Give 'DI' prefix to debug info metadata
[oota-llvm.git] / bindings / ocaml / Makefile.ocaml
index 1d2eff5ec7f906e4347a6a15b3b9fa76fd0beaa3..1f65a7b8f905f6900f8301d90e5cf7cf6feb8bf3 100644 (file)
@@ -32,6 +32,12 @@ endif
 
 include $(LEVEL)/Makefile.common
 
+# Used in out-of-tree builds of OCaml bindings only.
+ifdef SYSTEM_LLVM_CONFIG
+LLVM_CONFIG = $(SYSTEM_LLVM_CONFIG)
+LLVMLibsOptions += $(shell $(LLVM_CONFIG) --ldflags)
+endif
+
 # Intentionally ignore PROJ_prefix here. We want the ocaml stdlib. However, the
 # user can override this with OCAML_LIBDIR or configure --with-ocaml-libdir=.
 PROJ_libocamldir := $(DESTDIR)$(OCAML_LIBDIR)
@@ -53,10 +59,22 @@ endif
 #    from toplevels.
 ifneq ($(ObjectsO),)
 ifeq ($(ENABLE_SHARED),1)
-OCAMLSTUBS := 1
+OCAMLSTUBS     := 1
+OCAMLSTUBFLAGS := $(patsubst %,-cclib %, $(LLVMLibsOptions) -l$(LIBRARYNAME))
+endif
+endif
+
+# Avoid the need for LD_LIBRARY_PATH
+ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
+ifneq ($(HOST_OS),Darwin)
+OCAMLRPATH     := $(RPATH) -Wl,'$$ORIGIN/../../lib'
 endif
 endif
 
+# See http://caml.inria.fr/mantis/view.php?id=6642
+OCAMLORIGIN    := -ccopt -L'$$CAMLORIGIN/..' \
+                  -ccopt $(RPATH) -ccopt -Wl,'$$CAMLORIGIN/..'
+
 # Tools
 OCAMLCFLAGS += -I $(OcamlDir) $(addprefix -package ,$(FindlibPackages))
 
@@ -73,7 +91,7 @@ OCAMLAFLAGS += $(patsubst %,-cclib %, \
 endif
 endif
 
-ifneq ($(ENABLE_OPTIMIZED),1)
+ifneq ($(DEBUG_SYMBOLS),1)
   OCAMLDEBUGFLAG := -g
 endif
 
@@ -82,29 +100,20 @@ Compile.CMO  := $(strip $(OCAMLFIND) c -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
 Compile.CMX  := $(strip $(OCAMLFIND) opt -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o)
 
 ifdef OCAMLSTUBS
-# Avoid the need for LD_LIBRARY_PATH
-ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
-ifneq ($(HOST_OS),Darwin)
-OCAMLRPATH   := $(RPATH) -Wl,'$(SharedLibDir)'
-endif
-endif
-endif
-
-ifdef OCAMLSTUBS
-Archive.CMA  := $(strip $(OCAMLFIND) c -a -dllib -l$(LIBRARYNAME) $(OCAMLDEBUGFLAG) \
-                                       -o)
+# -dllib is engaged with ocamlc builds, $(OCAMLSTUBFLAGS) in ocamlc -custom builds.
+Archive.CMA  := $(strip $(OCAMLFIND) c -a -dllib -l$(LIBRARYNAME) $(OCAMLSTUBFLAGS) \
+                                                                                                                                                        $(OCAMLDEBUGFLAG) $(OCAMLORIGIN) -o)
 else
 Archive.CMA  := $(strip $(OCAMLFIND) c -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \
-                                       -o)
+                                       $(OCAMLORIGIN) -o)
 endif
 
 ifdef OCAMLSTUBS
-Archive.CMXA := $(strip $(OCAMLFIND) opt -a $(patsubst %,-cclib %, \
-                                    $(LLVMLibsOptions) -l$(LIBRARYNAME) \
-                                    -L$(SharedLibDir) $(OCAMLRPATH)) \
-                                    $(OCAMLDEBUGFLAG) -o)
+Archive.CMXA := $(strip $(OCAMLFIND) opt -a $(OCAMLSTUBFLAGS) $(OCAMLDEBUGFLAG) \
+                                         $(OCAMLORIGIN) -o)
 else
-Archive.CMXA := $(strip $(OCAMLFIND) opt -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o)
+Archive.CMXA := $(strip $(OCAMLFIND) opt -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \
+                                         $(OCAMLORIGIN) -o)
 endif
 
 # Source files
@@ -240,8 +249,8 @@ uninstall-local:: uninstall-shared
 
 $(SharedLib): $(ObjectsO) $(OcamlDir)/.dir
        $(Echo) "Building $(BuildMode) $(notdir $@)"
-       $(Verb) $(Link) $(SharedLinkOptions) $(OCAMLRPATH) $(LLVMLibsOptions) \
-                       -o $@ $(ObjectsO)
+       $(Verb) $(Link) $(SharedLinkOptions) $(OCAMLRPATH) -o $@ $(ObjectsO) \
+                       $(LLVMLibsOptions)
 
 clean-shared::
        -$(Verb) $(RM) -f $(SharedLib)
@@ -258,8 +267,9 @@ uninstall-shared::
 endif
 
 
-##===- Deposit dependent libraries adjacent to Ocaml libs -----------------===##
+##===- Deposit dependent libraries adjacent to OCaml libs -----------------===##
 
+ifndef SYSTEM_LLVM_CONFIG
 all-local:: build-deplibs
 clean-local:: clean-deplibs
 install-local:: install-deplibs
@@ -284,7 +294,7 @@ install-deplibs:
 
 uninstall-deplibs:
        $(Verb) $(RM) -f $(DestLibs)
-
+endif
 
 ##===- Build ocaml interfaces (.mli's -> .cmi's) --------------------------===##
 
@@ -431,6 +441,9 @@ printcamlvars::
        $(Echo) "LLVM_CONFIG  : " '$(LLVM_CONFIG)'
        $(Echo) "OCAMLCFLAGS  : " '$(OCAMLCFLAGS)'
        $(Echo) "OCAMLAFLAGS  : " '$(OCAMLAFLAGS)'
+       $(Echo) "OCAMLRPATH   : " '$(OCAMLRPATH)'
+       $(Echo) "OCAMLSTUBS   : " '$(OCAMLSTUBS)'
+       $(Echo) "OCAMLSTUBFLAGS : " '$(OCAMLSTUBFLAGS)'
        $(Echo) "OCAMLFIND    : " '$(OCAMLFIND)'
        $(Echo) "Compile.CMI  : " '$(Compile.CMI)'
        $(Echo) "Compile.CMO  : " '$(Compile.CMO)'
@@ -438,6 +451,7 @@ printcamlvars::
        $(Echo) "Compile.CMX  : " '$(Compile.CMX)'
        $(Echo) "Archive.CMXA : " '$(Archive.CMXA)'
        $(Echo) "CAML_LIBDIR  : " '$(CAML_LIBDIR)'
+       $(Echo) "LibraryA     : " '$(LibraryA)'
        $(Echo) "LibraryCMA   : " '$(LibraryCMA)'
        $(Echo) "LibraryCMXA  : " '$(LibraryCMXA)'
        $(Echo) "SharedLib    : " '$(SharedLib)'