Decide at config time if natdynlink is supported or not, but always compile/install dynlink.cmxa to simplify 3rd party packages. A runtime exception signals an unsupported natdynlink.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10461 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Alain Frisch 2010-05-25 10:00:39 +00:00
parent 9d27a7fc8e
commit 47dbbc7d7f
8 changed files with 32 additions and 5 deletions

View File

@ -70,6 +70,7 @@ DEBUGGER=ocamldebugger
CC_PROFILE=
SYSTHREAD_SUPPORT=true
EXTRALIBS=
NATDYNLINK=true
CMXS=cmxs
########## Configuration for the bytecode compiler

View File

@ -70,6 +70,7 @@ CC_PROFILE=
SYSTHREAD_SUPPORT=true
EXTRALIBS=
CMXS=cmxs
NATDYNLINK=true
########## Configuration for the bytecode compiler

View File

@ -70,6 +70,7 @@ DEBUGGER=ocamldebugger
CC_PROFILE=
SYSTHREAD_SUPPORT=true
CMXS=cmxs
NATDYNLINK=true
########## Configuration for the bytecode compiler

14
configure vendored
View File

@ -511,17 +511,17 @@ mksharedlib=''
byteccrpath=''
mksharedlibrpath=''
natdynlinkopts=""
cmxs="cmxa"
natdynlink=false
if test $withsharedlibs = "yes"; then
case "$host" in
*-*-cygwin*)
cmxs="cmxs"
natdynlink=true
mksharedlib="$flexlink"
mkmaindll="$flexlink -maindll"
shared_libraries_supported=true;;
*-*-linux-gnu|*-*-linux|*-*-freebsd[3-9]*|*-*-openbsd*|*-*-netbsd*|*-*-gnu*)
cmxs="cmxs"
natdynlink=true
sharedcccompopts="-fPIC"
mksharedlib="$bytecc -shared"
bytecclinkopts="$bytecclinkopts -Wl,-E"
@ -614,6 +614,12 @@ if test -z "$mkmaindll"; then
mkmaindll=$mksharedlib
fi
if test $natdynlink = "true"; then
cmxs="cmxs"
else
cmxs="cmxa"
fi
# Configure the native-code compiler
arch=none
@ -1618,6 +1624,7 @@ echo "EXT_DLL=.so" >> Makefile
echo "EXTRALIBS=" >> Makefile
echo "CCOMPTYPE=cc" >> Makefile
echo "TOOLCHAIN=cc" >> Makefile
echo "NATDYNLINK=$natdynlink" >> Makefile
echo "CMXS=$cmxs" >> Makefile
echo "MKEXE=$mkexe" >> Makefile
echo "MKDLL=$mksharedlib" >> Makefile
@ -1666,6 +1673,7 @@ else
echo " options for linking....... $nativecclinkopts $cclibs"
echo " assembler ................ $as"
echo " preprocessed assembler ... $aspp"
echo " native dynlink ........... $natdynlink"
if test "$profiling" = "prof"; then
echo " profiling with gprof ..... supported"
else

View File

@ -58,9 +58,9 @@ dynlinkaux.cmo: $(COMPILEROBJS)
dynlinkaux.cmi: dynlinkaux.cmo
dynlink.cmx: dynlink.cmi natdynlink.ml
cp natdynlink.ml dynlink.mlopt
sed -e 's|%%NATDYNLINK%%|$(NATDYNLINK)|' natdynlink.ml > dynlink.mlopt
$(CAMLOPT) -c $(COMPFLAGS) -impl dynlink.mlopt
rm -f dynlink.mlopt
# rm -f dynlink.mlopt
extract_crc: dynlink.cma extract_crc.cmo
$(CAMLC) $(COMPFLAGS) -o extract_crc dynlink.cma extract_crc.cmo

View File

@ -18,6 +18,8 @@
open Dynlinkaux (* REMOVE_ME for ../../debugger/dynlink.ml *)
open Cmo_format
let supported = true
type linking_error =
Undefined_global of string
| Unavailable_primitive of string
@ -33,6 +35,7 @@ type error =
| File_not_found of string
| Cannot_open_dll of string
| Inconsistent_implementation of string
| Dynlink_not_supported
exception Error of error
@ -268,6 +271,8 @@ let error_message = function
"error loading shared library: " ^ reason
| Inconsistent_implementation name ->
"implementation mismatch on " ^ name
| Dynlink_not_supported ->
"dynlink not supported"
let is_native = false
let adapt_filename f = f

View File

@ -19,6 +19,10 @@ val is_native: bool
(** [true] if the program is native,
[false] if the program is bytecode. *)
val supported: bool
(** [true] if dynlink is supported for the current platform (always
[true] in bytecode, can be [false] for native code). *)
(** {6 Dynamic loading of compiled files} *)
val loadfile : string -> unit
@ -127,6 +131,7 @@ type error =
| File_not_found of string
| Cannot_open_dll of string
| Inconsistent_implementation of string
| Dynlink_not_supported
exception Error of error
(** Errors in dynamic linking are reported by raising the [Error]

View File

@ -15,6 +15,8 @@
(* Dynamic loading of .cmx files *)
let supported = %%NATDYNLINK%%
type handle
external ndl_open: string -> bool -> handle * string = "caml_natdynlink_open"
@ -37,6 +39,7 @@ type error =
| File_not_found of string
| Cannot_open_dll of string
| Inconsistent_implementation of string
| Dynlink_not_supported
exception Error of error
@ -93,6 +96,7 @@ let allow_extension = ref true
let inited = ref false
let default_available_units () =
if not supported then raise (Error Dynlink_not_supported);
let map : (string*Digest.t*Digest.t*string list) list =
Marshal.from_string (ndl_getmap ()) 0 in
let exe = Sys.executable_name in
@ -244,6 +248,8 @@ let error_message = function
"error loading shared library: " ^ reason
| Inconsistent_implementation name ->
"implementation mismatch on " ^ name
| Dynlink_not_supported ->
"dynlink not supported"
let is_native = true
let adapt_filename f = Filename.chop_extension f ^ ".cmxs"