diff --git a/Changes b/Changes index 153cd4608f25..97f6394636b5 100644 --- a/Changes +++ b/Changes @@ -162,8 +162,8 @@ ___________ (Antonin Décimo, review by Miod Vallat, Gabriel Scherer, and David Allsopp) - #13???: Introduce a RuntimeID for use in filename mangling to allow different - configurations and different versions of ocamlrun to coexist harmoniously on a - single system. + configurations and different versions of ocamlrun and the shared runtime + libraries to coexist harmoniously on a single system. (David Allsopp, review by ???) ### Code generation and optimizations: diff --git a/Makefile b/Makefile index f25d0e9dd56e..c22914612de5 100644 --- a/Makefile +++ b/Makefile @@ -1321,9 +1321,9 @@ endif ifeq "$(UNIX_OR_WIN32)" "unix" ifeq "$(SUPPORTS_SHARED_LIBRARIES)" "true" runtime_BYTECODE_STATIC_LIBRARIES += runtime/libcamlrun_pic.$(A) -runtime_BYTECODE_SHARED_LIBRARIES += runtime/libcamlrun_shared.$(SO) +runtime_BYTECODE_SHARED_LIBRARIES += camlrun runtime_NATIVE_STATIC_LIBRARIES += runtime/libasmrun_pic.$(A) -runtime_NATIVE_SHARED_LIBRARIES += runtime/libasmrun_shared.$(SO) +runtime_NATIVE_SHARED_LIBRARIES += asmrun endif endif @@ -1374,13 +1374,15 @@ ocamlruni_CPPFLAGS = $(runtime_CPPFLAGS) -DCAML_INSTR .PHONY: runtime-all runtime-all: \ - $(runtime_BYTECODE_STATIC_LIBRARIES) $(runtime_BYTECODE_SHARED_LIBRARIES) \ + $(runtime_BYTECODE_STATIC_LIBRARIES) \ + $(runtime_BYTECODE_SHARED_LIBRARIES:%=runtime/lib%_shared$(EXT_DLL)) \ $(runtime_PROGRAMS:%=runtime/%$(EXE)) $(SAK) .PHONY: runtime-allopt ifeq "$(NATIVE_COMPILER)" "true" runtime-allopt: \ - $(runtime_NATIVE_STATIC_LIBRARIES) $(runtime_NATIVE_SHARED_LIBRARIES) + $(runtime_NATIVE_STATIC_LIBRARIES) \ + $(runtime_NATIVE_SHARED_LIBRARIES:%=runtime/lib%_shared$(EXT_DLL)) else runtime-allopt: $(error The build has been configured with --disable-native-compiler) @@ -2711,6 +2713,19 @@ install:: $(LN) "$(TARGET)-$(1)-$(BYTECODE_RUNTIME_ID)$(EXE)" \ "$(1)-$(BYTECODE_RUNTIME_ID)$(EXE)" endef +define INSTALL_RUNTIME_LIB +ifeq "$(2)" "BYTECODE" +install:: +else +installopt:: +endif + $(INSTALL_PROG) \ + runtime/lib$(1)_shared$(EXT_DLL) \ + "$(INSTALL_LIBDIR)/lib$(1)-$(TARGET)-$($(2)_RUNTIME_ID)$(EXT_DLL)" + cd "$(INSTALL_LIBDIR)" && \ + $(LN) "lib$(1)-$(TARGET)-$($(2)_RUNTIME_ID)$(EXT_DLL)" \ + "lib$(1)_shared$(EXT_DLL)" +endef $(foreach runtime, $(runtime_PROGRAMS), \ $(eval $(call INSTALL_RUNTIME,$(runtime)))) @@ -2718,10 +2733,11 @@ $(foreach runtime, $(runtime_PROGRAMS), \ install:: $(INSTALL_DATA) $(runtime_BYTECODE_STATIC_LIBRARIES) \ "$(INSTALL_LIBDIR)" -ifneq "$(runtime_BYTECODE_SHARED_LIBRARIES)" "" - $(INSTALL_PROG) $(runtime_BYTECODE_SHARED_LIBRARIES) \ - "$(INSTALL_LIBDIR)" -endif + +$(foreach shared_runtime, $(runtime_BYTECODE_SHARED_LIBRARIES), \ + $(eval $(call INSTALL_RUNTIME_LIB,$(shared_runtime),BYTECODE))) + +install:: $(INSTALL_DATA) runtime/caml/domain_state.tbl runtime/caml/*.h \ "$(INSTALL_INCDIR)" $(INSTALL_PROG) ocaml$(EXE) "$(INSTALL_BINDIR)" @@ -2874,11 +2890,13 @@ endif # Installation of the native-code compiler .PHONY: installopt -installopt: +installopt:: $(INSTALL_DATA) $(runtime_NATIVE_STATIC_LIBRARIES) "$(INSTALL_LIBDIR)" -ifneq "$(runtime_NATIVE_SHARED_LIBRARIES)" "" - $(INSTALL_PROG) $(runtime_NATIVE_SHARED_LIBRARIES) "$(INSTALL_LIBDIR)" -endif + +$(foreach shared_runtime, $(runtime_NATIVE_SHARED_LIBRARIES), \ + $(eval $(call INSTALL_RUNTIME_LIB,$(shared_runtime),NATIVE))) + +installopt:: ifeq "$(INSTALL_BYTECODE_PROGRAMS)" "true" $(call INSTALL_STRIPPED_BYTE_PROG,\ ocamlopt$(EXE),"$(INSTALL_BINDIR)/ocamlopt.byte$(EXE)") diff --git a/asmcomp/asmlink.ml b/asmcomp/asmlink.ml index ce021c1496ea..4a1d5e05c7db 100644 --- a/asmcomp/asmlink.ml +++ b/asmcomp/asmlink.ml @@ -105,12 +105,17 @@ let add_ccobjs origin l = end let runtime_lib () = - let libname = "libasmrun" ^ !Clflags.runtime_variant ^ ext_lib in - try - if !Clflags.nopervasives || not !Clflags.with_runtime then [] - else [ Load_path.find libname ] - with Not_found -> - raise(Error(File_not_found libname)) + if !Clflags.runtime_variant = "_shared" then + [Printf.sprintf "-lasmrun-%s-%s" + Config.target + Config.native_runtime_id] + else + let libname = "libasmrun" ^ !Clflags.runtime_variant ^ ext_lib in + try + if !Clflags.nopervasives || not !Clflags.with_runtime then [] + else [ Load_path.find libname ] + with Not_found -> + raise(Error(File_not_found libname)) (* First pass: determine which units are needed *) diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml index 2154c6762d53..770665366c03 100644 --- a/bytecomp/bytelink.ml +++ b/bytecomp/bytelink.ml @@ -718,13 +718,22 @@ value caml_startup_pooled_exn(char_os ** argv) if not with_main && !Clflags.debug then output_cds_file ((Filename.chop_extension outfile) ^ ".cds") +let runtime_library_name runtime_variant = + if runtime_variant = "_shared" then + Printf.sprintf "-lcamlrun-%s-%s" + Config.target + Config.bytecode_runtime_id + else + "-lcamlrun" ^ runtime_variant + (* Build a custom runtime *) let build_custom_runtime prim_name exec_name = let runtime_lib = if not !Clflags.with_runtime then "" - else "-lcamlrun" ^ !Clflags.runtime_variant in + else runtime_library_name !Clflags.runtime_variant + in let stable_name = if not !Clflags.keep_camlprimc_file then Some "camlprim.c" @@ -861,7 +870,8 @@ extern "C" { let runtime_lib = if not !Clflags.with_runtime then "" - else "-lcamlrun" ^ !Clflags.runtime_variant in + else runtime_library_name !Clflags.runtime_variant + in Ccomp.call_linker mode output_name ([obj_file] @ List.rev !Clflags.ccobjs @ [runtime_lib]) c_libs = 0