summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2015-02-08 11:18:29 +0000
committerGabriel Scherer <gabriel.scherer@gmail.com>2015-02-08 11:18:29 +0000
commit41e0ecf2ef1f45e2f8d0d189ea0693d22c2cc619 (patch)
tree8fd70f003d050512ad0960eddc81cf9cd754235d
parente7df5313a5a5d4e98630fe33716bd03caf99a467 (diff)
downloadocaml-41e0ecf2ef1f45e2f8d0d189ea0693d22c2cc619.tar.gz
PR#6642: replace $CAMLORIGIN in -ccopt with the path to cma or cmxa
(Peter Zotov) git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15828 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--Changes2
-rw-r--r--asmcomp/asmlink.ml7
-rw-r--r--bytecomp/bytelink.ml7
-rw-r--r--man/ocamlc.m8
-rw-r--r--man/ocamlopt.m7
-rw-r--r--utils/misc.ml11
-rw-r--r--utils/misc.mli4
7 files changed, 37 insertions, 9 deletions
diff --git a/Changes b/Changes
index 0d0e06c1cf..43417aa898 100644
--- a/Changes
+++ b/Changes
@@ -98,6 +98,8 @@ Compilers:
(Vincent Laporte, Peter Zotov)
- PR#6600: make -short-paths faster by building the printing map
incrementally (Jacques Garrigue)
+- PR#6642: replace $CAMLORIGIN in -ccopt with the path to cma or cmxa
+ (Peter Zotov, Gabriel Scherer, review by Damien Doligez)
Toplevel and debugger:
- PR#5958: generalized polymorphic #install_printer
diff --git a/asmcomp/asmlink.ml b/asmcomp/asmlink.ml
index e11095978a..c4d80ecff2 100644
--- a/asmcomp/asmlink.ml
+++ b/asmcomp/asmlink.ml
@@ -91,10 +91,11 @@ let extract_crc_implementations () =
let lib_ccobjs = ref []
let lib_ccopts = ref []
-let add_ccobjs l =
+let add_ccobjs origin l =
if not !Clflags.no_auto_link then begin
lib_ccobjs := l.lib_ccobjs @ !lib_ccobjs;
- lib_ccopts := l.lib_ccopts @ !lib_ccopts
+ let replace_origin = Misc.replace_substring ~before:"$CAMLORIGIN" ~after:origin in
+ lib_ccopts := List.map replace_origin l.lib_ccopts @ !lib_ccopts
end
let runtime_lib () =
@@ -179,7 +180,7 @@ let scan_file obj_name tolink = match read_file obj_name with
| Library (file_name,infos) ->
(* This is an archive file. Each unit contained in it will be linked
in only if needed. *)
- add_ccobjs infos;
+ add_ccobjs (Filename.dirname file_name) infos;
List.fold_right
(fun (info, crc) reqd ->
if info.ui_force_link
diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml
index 0e615c8dae..c4c35bf954 100644
--- a/bytecomp/bytelink.ml
+++ b/bytecomp/bytelink.ml
@@ -42,7 +42,7 @@ let lib_ccobjs = ref []
let lib_ccopts = ref []
let lib_dllibs = ref []
-let add_ccobjs l =
+let add_ccobjs origin l =
if not !Clflags.no_auto_link then begin
if
String.length !Clflags.use_runtime = 0
@@ -50,7 +50,8 @@ let add_ccobjs l =
then begin
if l.lib_custom then Clflags.custom_runtime := true;
lib_ccobjs := l.lib_ccobjs @ !lib_ccobjs;
- lib_ccopts := l.lib_ccopts @ !lib_ccopts;
+ let replace_origin = Misc.replace_substring ~before:"$CAMLORIGIN" ~after:origin in
+ lib_ccopts := List.map replace_origin l.lib_ccopts @ !lib_ccopts;
end;
lib_dllibs := l.lib_dllibs @ !lib_dllibs
end
@@ -132,7 +133,7 @@ let scan_file obj_name tolink =
seek_in ic pos_toc;
let toc = (input_value ic : library) in
close_in ic;
- add_ccobjs toc;
+ add_ccobjs (Filename.dirname file_name) toc;
let required =
List.fold_right
(fun compunit reqd ->
diff --git a/man/ocamlc.m b/man/ocamlc.m
index 26ce50f7c2..3b526f7eec 100644
--- a/man/ocamlc.m
+++ b/man/ocamlc.m
@@ -191,8 +191,12 @@ linking with this library automatically adds back the
options as if they had been provided on the
command line, unless the
.B -noautolink
-option is given.
-.TP
+option is given. Additionally, a substring
+.B $CAMLORIGIN
+inside a
+.BR \ \-ccopt
+options will be replaced by the full path to the .cma library,
+excluding the filename.
.B \-absname
Show absolute filenames in error messages.
.TP
diff --git a/man/ocamlopt.m b/man/ocamlopt.m
index 15b0c3b89f..fa3db5df8c 100644
--- a/man/ocamlopt.m
+++ b/man/ocamlopt.m
@@ -153,7 +153,12 @@ linking with this library automatically adds back the
options as if they had been provided on the
command line, unless the
.B \-noautolink
-option is given.
+option is given. Additionally, a substring
+.B $CAMLORIGIN
+inside a
+.BR \ \-ccopt
+options will be replaced by the full path to the .cma library,
+excluding the filename.
.TP
.B \-absname
Show absolute filenames in error messages.
diff --git a/utils/misc.ml b/utils/misc.ml
index 0f94be92a9..82328ef26a 100644
--- a/utils/misc.ml
+++ b/utils/misc.ml
@@ -204,6 +204,17 @@ let search_substring pat str start =
else search (i+1) 0
in search start 0
+let replace_substring ~before ~after str =
+ let rec search acc curr =
+ match search_substring before str curr with
+ | next ->
+ let prefix = String.sub str curr (next - curr) in
+ search (prefix :: acc) (next + String.length before)
+ | exception Not_found ->
+ let suffix = String.sub str curr (String.length str - curr) in
+ List.rev (suffix :: acc)
+ in String.concat after (search [] 0)
+
let rev_split_words s =
let rec split1 res i =
if i >= String.length s then res else begin
diff --git a/utils/misc.mli b/utils/misc.mli
index 48bbb46beb..1ff1d2cccf 100644
--- a/utils/misc.mli
+++ b/utils/misc.mli
@@ -104,6 +104,10 @@ val search_substring: string -> string -> int -> int
at offset [start] in [str]. Raise [Not_found] if [pat]
does not occur. *)
+val replace_substring: before:string -> after:string -> string -> string
+ (* [search_substring ~before ~after str] replaces all occurences
+ of [before] with [after] in [str] and returns the resulting string. *)
+
val rev_split_words: string -> string list
(* [rev_split_words s] splits [s] in blank-separated words, and return
the list of words in reverse order. *)