summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2003-07-03 15:13:23 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2003-07-03 15:13:23 +0000
commitb0a3c8014ba5eacad56670d4501ad241dd7debe8 (patch)
tree33cc2547e7c08f83cda45eb52dcac8b9b0a4c4f6
parente140b9ea5c8e3644622c22540ef43b628d64fee8 (diff)
Faire marcher ocamlopt -pack sous Win32-msvc
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5651 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--Makefile1
-rw-r--r--asmcomp/asmpackager.ml17
-rw-r--r--config/Makefile-templ4
-rw-r--r--config/Makefile.mingw1
-rw-r--r--config/Makefile.msvc5
-rw-r--r--utils/config.mli4
-rw-r--r--utils/config.mlp1
7 files changed, 27 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index cf9adaedb..5683940e5 100644
--- a/Makefile
+++ b/Makefile
@@ -326,6 +326,7 @@ utils/config.ml: utils/config.mlp config/Makefile
-e 's|%%NATIVECC%%|$(NATIVECC) $(NATIVECCCOMPOPTS)|' \
-e 's|%%NATIVELINK%%|$(NATIVECC) $(NATIVECCLINKOPTS)|' \
-e 's|%%PARTIALLD%%|ld -r $(NATIVECCLINKOPTS)|' \
+ -e 's|%%PACKLD%%|ld -r $(NATIVECCLINKOPTS)|' \
-e 's|%%BYTECCLIBS%%|$(BYTECCLIBS)|' \
-e 's|%%NATIVECCLIBS%%|$(NATIVECCLIBS)|' \
-e 's|%%RANLIBCMD%%|$(RANLIBCMD)|' \
diff --git a/asmcomp/asmpackager.ml b/asmcomp/asmpackager.ml
index a428b8b45..b80e01e2f 100644
--- a/asmcomp/asmpackager.ml
+++ b/asmcomp/asmpackager.ml
@@ -70,7 +70,8 @@ let extract_symbols units symbolfile =
with Not_found -> search_substring " D " l 0) in
let j = try search_substring "__" l i
with Not_found -> String.length l in
- if List.mem (String.sub l i (j - i)) units then
+ let k = if l.[i] = '_' then i + 1 else i in
+ if List.mem (String.sub l k (j - k)) units then
symbs := (String.sub l i (String.length l - i)) :: !symbs
with Not_found ->
()
@@ -82,6 +83,16 @@ let extract_symbols units symbolfile =
let max_cmdline_length = 3500 (* safe approximation *)
+let remove_leading_underscore s =
+ if String.length s > 0 && s.[0] = '_'
+ then String.sub s 1 (String.length s - 1)
+ else s
+
+let prefix_symbol p s =
+ if String.length s > 0 && s.[0] = '_'
+ then "_" ^ p ^ "__" ^ String.sub s 1 (String.length s - 1)
+ else p ^ "__" ^ s
+
let rename_in_object_file units pref objfile =
let symbolfile = Filename.temp_file "camlsymbols" "" in
try
@@ -109,12 +120,12 @@ let rename_in_object_file units pref objfile =
Buffer.reset cmdline;
Buffer.add_string cmdline Config.binutils_objcopy
end;
- bprintf cmdline " --redefine-sym '%s=%s__%s'" s pref s;
+ bprintf cmdline " --redefine-sym '%s=%s'" s (prefix_symbol pref s);
call_objcopy rem in
Buffer.add_string cmdline Config.binutils_objcopy;
call_objcopy symbols_to_rename;
remove_file symbolfile;
- symbols_to_rename
+ List.map remove_leading_underscore symbols_to_rename
with x ->
remove_file symbolfile;
raise x
diff --git a/config/Makefile-templ b/config/Makefile-templ
index 99ea105fd..d442a8c3e 100644
--- a/config/Makefile-templ
+++ b/config/Makefile-templ
@@ -226,6 +226,10 @@ SHARPBANGSCRIPTS=true
#CC_PROFILE=-pg
#CC_PROFILE=-xpg
+### How to perform a partial link
+PARTIALLD=ld -r $(NATIVECCLINKOPTS)
+PACKLD=$(PARTIALLD)
+
### Path to the "objcopy" program from GNU binutils.
# You need a sufficiently recent version of the binutils so that
# the option --redefine-sym is supported by objcopy.
diff --git a/config/Makefile.mingw b/config/Makefile.mingw
index db21187f7..9a0e8dd8c 100644
--- a/config/Makefile.mingw
+++ b/config/Makefile.mingw
@@ -99,6 +99,7 @@ NATIVECCLINKOPTS=
### Build partially-linked object file
PARTIALLD=ld -r $(NATIVECCLINKOPTS)
+PACKLD=$(PARTIALLD)
### nm and objcopy from GNU binutils
BINUTILS_NM=nm
diff --git a/config/Makefile.msvc b/config/Makefile.msvc
index 089b67eb2..4e3c26456 100644
--- a/config/Makefile.msvc
+++ b/config/Makefile.msvc
@@ -99,10 +99,11 @@ NATIVECCLINKOPTS=/MT
### Build partially-linked object file
PARTIALLD=lib /nologo /debugtype:cv
+PACKLD=ld -r --oformat pe-i386
### nm and objcopy are missing
-BINUTILS_NM=
-BINUTILS_OBJCOPY=
+BINUTILS_NM=nm
+BINUTILS_OBJCOPY=objcopy
############# Configuration for the contributed libraries
diff --git a/utils/config.mli b/utils/config.mli
index 01f3ff0c2..a53fe24f2 100644
--- a/utils/config.mli
+++ b/utils/config.mli
@@ -43,7 +43,9 @@ val native_c_linker: string
val native_c_libraries: string
(* The C libraries to link with native-code programs *)
val native_partial_linker: string
- (* The linker to use for partial links (-output-obj option) *)
+ (* The linker to use for partial links (ocamlopt -output-obj) *)
+val native_pack_linker: string
+ (* The linker to use for packaging (ocamlopt -pack) *)
val ranlib: string
(* Command to randomize a library, or "" if not needed *)
val binutils_nm: string
diff --git a/utils/config.mlp b/utils/config.mlp
index 71954c405..370adbc38 100644
--- a/utils/config.mlp
+++ b/utils/config.mlp
@@ -33,6 +33,7 @@ let native_c_compiler = "%%NATIVECC%%"
let native_c_linker = "%%NATIVELINK%%"
let native_c_libraries = "%%NATIVECCLIBS%%"
let native_partial_linker = "%%PARTIALLD%%"
+let native_pack_linker = "%%PACKLD%%"
let ranlib = "%%RANLIBCMD%%"
let binutils_nm = "%%BINUTILS_NM%%"
let binutils_objcopy = "%%BINUTILS_OBJCOPY%%"