diff options
author | Alain Frisch <alain@frisch.fr> | 2010-05-25 10:00:39 +0000 |
---|---|---|
committer | Alain Frisch <alain@frisch.fr> | 2010-05-25 10:00:39 +0000 |
commit | 47dbbc7d7f08b5eae905979eb09921ee50cd0d43 (patch) | |
tree | c943c5a71190b3cae9578f503dcbba7a8e0a120e | |
parent | 9d27a7fc8ec929763a78a46845f3deef5ee8aebe (diff) |
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
-rw-r--r-- | config/Makefile.mingw | 1 | ||||
-rw-r--r-- | config/Makefile.msvc | 1 | ||||
-rw-r--r-- | config/Makefile.msvc64 | 1 | ||||
-rwxr-xr-x | configure | 14 | ||||
-rw-r--r-- | otherlibs/dynlink/Makefile | 4 | ||||
-rw-r--r-- | otherlibs/dynlink/dynlink.ml | 5 | ||||
-rw-r--r-- | otherlibs/dynlink/dynlink.mli | 5 | ||||
-rw-r--r-- | otherlibs/dynlink/natdynlink.ml | 6 |
8 files changed, 32 insertions, 5 deletions
diff --git a/config/Makefile.mingw b/config/Makefile.mingw index d1e40bb1d..f2e408cc0 100644 --- a/config/Makefile.mingw +++ b/config/Makefile.mingw @@ -70,6 +70,7 @@ DEBUGGER=ocamldebugger CC_PROFILE= SYSTHREAD_SUPPORT=true EXTRALIBS= +NATDYNLINK=true CMXS=cmxs ########## Configuration for the bytecode compiler diff --git a/config/Makefile.msvc b/config/Makefile.msvc index 4bbf54451..b2dee2242 100644 --- a/config/Makefile.msvc +++ b/config/Makefile.msvc @@ -70,6 +70,7 @@ CC_PROFILE= SYSTHREAD_SUPPORT=true EXTRALIBS= CMXS=cmxs +NATDYNLINK=true ########## Configuration for the bytecode compiler diff --git a/config/Makefile.msvc64 b/config/Makefile.msvc64 index 3dd60b9d4..3c19e5922 100644 --- a/config/Makefile.msvc64 +++ b/config/Makefile.msvc64 @@ -70,6 +70,7 @@ DEBUGGER=ocamldebugger CC_PROFILE= SYSTHREAD_SUPPORT=true CMXS=cmxs +NATDYNLINK=true ########## Configuration for the bytecode compiler @@ -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 diff --git a/otherlibs/dynlink/Makefile b/otherlibs/dynlink/Makefile index 9b72fe598..da58af3da 100644 --- a/otherlibs/dynlink/Makefile +++ b/otherlibs/dynlink/Makefile @@ -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 diff --git a/otherlibs/dynlink/dynlink.ml b/otherlibs/dynlink/dynlink.ml index 0d324a854..d8d2f1162 100644 --- a/otherlibs/dynlink/dynlink.ml +++ b/otherlibs/dynlink/dynlink.ml @@ -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 diff --git a/otherlibs/dynlink/dynlink.mli b/otherlibs/dynlink/dynlink.mli index 7cca68c5a..ae8754798 100644 --- a/otherlibs/dynlink/dynlink.mli +++ b/otherlibs/dynlink/dynlink.mli @@ -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] diff --git a/otherlibs/dynlink/natdynlink.ml b/otherlibs/dynlink/natdynlink.ml index 6ab9b9850..e481dd870 100644 --- a/otherlibs/dynlink/natdynlink.ml +++ b/otherlibs/dynlink/natdynlink.ml @@ -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" |