[llvm] r221139 - [OCaml] Avoid embedding absolute paths into executables.

Peter Zotov whitequark at whitequark.org
Mon Nov 3 01:51:35 PST 2014


Author: whitequark
Date: Mon Nov  3 03:51:34 2014
New Revision: 221139

URL: http://llvm.org/viewvc/llvm-project?rev=221139&view=rev
Log:
[OCaml] Avoid embedding absolute paths into executables.

Bindings built out-of-tree, e.g. via OPAM, should append
a line to META.llvm like the following:

linkopts = "-cclib -L$libdir -cclib -Wl,-rpath,$libdir"

where $libdir is the lib/ directory where LLVM libraries are
installed.

Modified:
    llvm/trunk/bindings/ocaml/Makefile.ocaml
    llvm/trunk/test/lit.cfg

Modified: llvm/trunk/bindings/ocaml/Makefile.ocaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/Makefile.ocaml?rev=221139&r1=221138&r2=221139&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/Makefile.ocaml (original)
+++ llvm/trunk/bindings/ocaml/Makefile.ocaml Mon Nov  3 03:51:34 2014
@@ -53,7 +53,15 @@ 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
 
@@ -82,15 +90,6 @@ Compile.CMO  := $(strip $(OCAMLFIND) c -
 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)
 else
@@ -99,10 +98,7 @@ Archive.CMA  := $(strip $(OCAMLFIND) c -
 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) -o)
 else
 Archive.CMXA := $(strip $(OCAMLFIND) opt -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o)
 endif
@@ -431,6 +427,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 +437,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)'

Modified: llvm/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/lit.cfg?rev=221139&r1=221138&r2=221139&view=diff
==============================================================================
--- llvm/trunk/test/lit.cfg (original)
+++ llvm/trunk/test/lit.cfg Mon Nov  3 03:51:34 2014
@@ -201,7 +201,8 @@ config.substitutions.append( ('%ocamlc',
     "%s ocamlc %s" % (config.ocamlfind_executable, config.ocaml_flags)) )
 if config.have_ocamlopt in ('1', 'TRUE'):
     config.substitutions.append( ('%ocamlopt',
-        "%s ocamlopt %s" % (config.ocamlfind_executable, config.ocaml_flags)) )
+        "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" %
+            (config.ocamlfind_executable, llvm_lib_dir, llvm_lib_dir, config.ocaml_flags)) )
 else:
     config.substitutions.append( ('%ocamlopt', "true" ) )
 





More information about the llvm-commits mailing list