Skip to content

Commit

Permalink
Suite ajout DLLs
Browse files Browse the repository at this point in the history
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/dynamic_loading@3655 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information
xavierleroy committed Aug 24, 2001
1 parent 52d36c8 commit cd65a61
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 44 deletions.
6 changes: 4 additions & 2 deletions Makefile
Expand Up @@ -57,11 +57,11 @@ COMP=bytecomp/lambda.cmo bytecomp/printlambda.cmo \
bytecomp/typeopt.cmo bytecomp/switch.cmo bytecomp/matching.cmo \
bytecomp/translobj.cmo bytecomp/translcore.cmo \
bytecomp/translclass.cmo bytecomp/translmod.cmo \
bytecomp/simplif.cmo bytecomp/runtimedef.cmo
bytecomp/simplif.cmo bytecomp/runtimedef.cmo bytecomp/dll.cmo

BYTECOMP=bytecomp/meta.cmo bytecomp/instruct.cmo bytecomp/bytegen.cmo \
bytecomp/printinstr.cmo bytecomp/opcodes.cmo bytecomp/emitcode.cmo \
bytecomp/bytesections.cmo bytecomp/dll.cmo bytecomp/symtable.cmo \
bytecomp/bytesections.cmo bytecomp/symtable.cmo \
bytecomp/bytelibrarian.cmo bytecomp/bytelink.cmo

ASMCOMP=asmcomp/arch.cmo asmcomp/cmm.cmo asmcomp/printcmm.cmo \
Expand Down Expand Up @@ -278,9 +278,11 @@ utils/config.ml: utils/config.mlp config/Makefile
-e 's|%%BYTERUN%%|$(BINDIR)/ocamlrun|' \
-e 's|%%BYTECC%%|$(BYTECC) $(BYTECCCOMPOPTS)|' \
-e 's|%%BYTELINK%%|$(BYTECC) $(BYTECCLINKOPTS)|' \
-e 's|%%BYTECCRPATH%%|$(BYTECCRPATH)|' \
-e 's|%%NATIVECC%%|$(NATIVECC) $(NATIVECCCOMPOPTS)|' \
-e 's|%%NATIVELINK%%|$(NATIVECC) $(NATIVECCLINKOPTS)|' \
-e 's|%%PARTIALLD%%|ld -r $(NATIVECCLINKOPTS)|' \
-e 's|%%NATIVECCRPATH%%|$(NATIVECCRPATH)|' \
-e 's|%%BYTECCLIBS%%|$(BYTECCLIBS)|' \
-e 's|%%NATIVECCLIBS%%|$(NATIVECCLIBS)|' \
-e 's|%%RANLIBCMD%%|$(RANLIBCMD)|' \
Expand Down
8 changes: 7 additions & 1 deletion asmcomp/asmlink.ml
Expand Up @@ -233,7 +233,7 @@ let call_linker file_list startup_file =
(String.concat " " (List.rev file_list))
| _ ->
if not !Clflags.output_c_object then
Printf.sprintf "%s %s -o %s -I%s %s %s %s %s %s %s %s"
Printf.sprintf "%s %s -o %s -I%s %s %s %s %s %s %s %s %s"
!Clflags.c_linker
(if !Clflags.gprofile then "-pg" else "")
!Clflags.exec_name
Expand All @@ -244,6 +244,12 @@ let call_linker file_list startup_file =
(String.concat " "
(List.map (fun dir -> if dir = "" then "" else "-L" ^ dir)
!load_path))
(String.concat " "
(List.map (fun dir -> if dir = "" then "" else
Config.native_c_rpath ^ " " ^ dir)
(!Clflags.dllpaths @
Dll.ld_library_path_contents() @
Dll.ld_conf_contents())))
(String.concat " " (List.rev !Clflags.ccobjs))
runtime_lib
c_lib
Expand Down
8 changes: 5 additions & 3 deletions bytecomp/bytelink.ml
Expand Up @@ -417,9 +417,11 @@ let build_custom_runtime prim_name exec_name =
(List.map (fun dir -> if dir = "" then "" else "-L" ^ dir)
!load_path))
(String.concat " "
(List.map (fun dir -> if dir = "" then "" else "-Wl,-rpath " ^ dir)
(Dll.ld_library_path_contents()
@ Dll.ld_conf_contents())))
(List.map (fun dir -> if dir = "" then "" else
Config.bytecomp_c_rpath ^ " " ^ dir)
(!Clflags.dllpaths @
Dll.ld_library_path_contents() @
Dll.ld_conf_contents())))
(String.concat " " (List.rev !Clflags.ccobjs))
Config.bytecomp_c_libraries)
| "Win32" ->
Expand Down
2 changes: 1 addition & 1 deletion byterun/Makefile
Expand Up @@ -71,7 +71,7 @@ clean:
rm -f primitives prims.c opnames.h jumptbl.h

primitives : $(PRIMS)
sed -n -e '/\/\* ML \*\//s/.* \([a-z0-9_][a-z0-9_]*\) *(.*/\1/p' \
sed -n -e "s/CAMLprim value \([a-z0-9_][a-z0-9_]*\).*/\1/p" \
$(PRIMS) > primitives

prims.c : primitives
Expand Down
29 changes: 26 additions & 3 deletions config/Makefile-templ
Expand Up @@ -54,7 +54,10 @@ SHARPBANGSCRIPTS=true

### Additional link-time options for $(BYTECC)
### If using GCC on a Dec Alpha under OSF1:
#BYTECCLINKOPTS=-Xlinker -taso
#BYTECCLINKOPTS=-Wl,-T,12000000 -Wl,-D,14000000
# To support dynamic loading of shared libraries (they need to look at
# our own symbols):
#BYTECCLINKOPTS=-Wl,-E
# Otherwise:
#BYTECCLINKOPTS=

Expand All @@ -79,6 +82,22 @@ SHARPBANGSCRIPTS=true
#RANLIB=ar rs
#RANLIBCMD=

### Shared library support
# Extension for shared libraries: so if supported, a if not supported
#SO=so
#SO=a
# Set to nothing if shared libraries supported, and to -custom if not supported
#CUSTOM_IF_NOT_SHARED=
#CUSTOM_IF_NOT_SHARED=-custom
# Options to $(BYTECC) to produce shared objects (e.g. PIC)
#SHAREDCCCOMPOPTS=-fPIC
# How to build a shared library, invoked with output .so as first arg
# and object files as remaining args
#MKSHAREDLIB=gcc -shared -o
# Compile-time option to $(BYTECC) to add a directory to be searched
# at run-time for shared libraries
#BYTECCRPATH=-Wl,-rpath

############# Configuration for the native-code compiler

### Name of architecture for the native-code compiler
Expand Down Expand Up @@ -159,6 +178,10 @@ SHARPBANGSCRIPTS=true
### Additional link-time options for $(NATIVECC)
#NATIVECCLINKOPTS=

# Compile-time option to $(NATIVECC) to add a directory to be searched
# at run-time for shared libraries
#NATIVECCRPATH=-Wl,-rpath

### Flags for the assembler
# For the Alpha or the Mips:
#ASFLAGS=-O2
Expand Down Expand Up @@ -234,9 +257,9 @@ BIGNUM_ARCH=alpha
### Link-time options to ocamlc or ocamlopt for linking with X11 libraries
# Needed for the "graph" and "labltk" packages
# Usually:
#X11_LINK=-cclib -lX11
#X11_LINK=-lX11
# For SunOS with OpenLook:
#X11_LINK=-cclib -L$(X11_LIB) -cclib -lX11
#X11_LINK=-L$(X11_LIB) -lX11

### -I options for finding the include file ndbm.h
# Needed for the "dbm" package
Expand Down
5 changes: 5 additions & 0 deletions config/s-templ.h
Expand Up @@ -50,6 +50,11 @@

/* Define HAS_STRERROR if you have strerror(). */

#define SUPPORT_DYNAMIC_LINKING

/* Define SUPPORT_DYNAMIC_LINKING if dynamic loading of C stub code
via dlopen() is available. */

/* 2. For the Unix library. */

#define HAS_SOCKETS
Expand Down
77 changes: 61 additions & 16 deletions configure
Expand Up @@ -33,6 +33,7 @@ tk_libs=''
posix_threads=no
verbose=no
withcurses=yes
withsharedlibs=yes

gcc_warnings="-Wall -Wno-unused"

Expand All @@ -57,7 +58,10 @@ while : ; do
ccoption="$2"; shift;;
-lib*)
cclibs="$2 $cclibs"; shift;;
-no-curses) withcurses=no;;
-no-curses)
withcurses=no;;
-no-shared-libs)
withsharedlibs=no;;
-x11include*|--x11include*)
x11_include_dir=$2; shift;;
-x11lib*|--x11lib*)
Expand Down Expand Up @@ -355,6 +359,35 @@ if $int64_supported; then
esac
fi

# Shared library support

shared_libraries_supported=false
sharedcccompopts=''
mksharedlib=''
byteccrpath=''

if sh ./hasgot -ldl dlopen; then
echo "dlopen() found."
echo "#define HAS_DLOPEN" >> s.h
dllib=-ldl

if test $withsharedlibs = "yes"; then
case "$host" in
*-*-linux-gnu|*-*-linux)
sharedcccompopts="-fPIC"
mksharedlib="gcc -shared -o"
bytecclinkopts="$bytecclinkopts -Wl,-E"
byteccrpath="-Wl,-rpath"
shared_libraries_supported=true;;
esac
fi

if $shared_libraries_supported; then
echo "Dynamic loading of shared libraries is supported."
echo "#define SUPPORT_DYNAMIC_LINKING" >> s.h
fi
fi

# Configure the native-code compiler

arch=none
Expand Down Expand Up @@ -401,6 +434,7 @@ fi

nativecccompopts=''
nativecclinkopts=''
nativeccrpath="$byteccrpath"

case "$arch,$nativecc,$system,$host_type" in
alpha,cc*,digital,*) nativecccompopts=-std1;;
Expand Down Expand Up @@ -735,12 +769,6 @@ if sh ./hasgot -i locale.h && sh ./hasgot setlocale; then
echo "#define HAS_LOCALE" >> s.h
fi

if sh ./hasgot -ldl dlopen; then
echo "dlopen() found."
echo "#define HAS_DLOPEN" >> s.h
dllib=-ldl
fi

if sh ./hasgot -i sys/types.h -i sys/mman.h && sh ./hasgot mmap munmap; then
echo "mmap() found."
echo "#define HAS_MMAP" >> s.h
Expand Down Expand Up @@ -807,18 +835,18 @@ if test "$posix_threads" = "yes"; then
nativecccompopts="$nativecccompopts -D_REENTRANT"
case "$host" in
*-*-solaris*)
pthread_link="-cclib -lpthread -cclib -lposix4";;
pthread_link="-lpthread -lposix4";;
*-*-freebsd*)
pthread_link="-ccopt -pthread"
pthread_link="-pthread"
bytecccompopts="$bytecccompopts -D_THREAD_SAFE"
nativecccompopts="$nativecccompopts -D_THREAD_SAFE";;
*-*-openbsd*)
pthread_link="-ccopt -pthread"
pthread_link="-pthread"
bytecccompopts="$bytecccompopts -pthread"
asppflags="$asppflags -pthread"
nativecccompopts="$nativecccompopts -pthread";;
*)
pthread_link="-cclib -lpthread";;
pthread_link="-lpthread";;
esac
echo "Options for linking with POSIX threads: $pthread_link"
echo "PTHREAD_LINK=$pthread_link" >> Makefile
Expand Down Expand Up @@ -871,9 +899,9 @@ do
test -f $dir/libX11.so || \
test -f $dir/libX11.sa; then
if test $dir = /usr/lib; then
x11_link="-cclib -lX11"
x11_link="-lX11"
else
x11_link="-ccopt -L$dir -cclib -lX11"
x11_link="-L$dir -lX11"
x11_libs="-L$dir"
fi
break
Expand Down Expand Up @@ -908,9 +936,9 @@ for dir in /usr/include /usr/include/gdbm /usr/include/db1; do
if sh ./hasgot dbm_open; then
dbm_link=""
elif sh ./hasgot -lndbm dbm_open; then
dbm_link="-cclib -lndbm"
dbm_link="-lndbm"
elif sh ./hasgot -ldb1 dbm_open; then
dbm_link="-cclib -ldb1"
dbm_link="-ldb1"
else
dbm_include="not found"
fi
Expand Down Expand Up @@ -1023,7 +1051,6 @@ if test $has_tk = true; then
fi

if test $has_tk = true; then
tk_libs=`echo $tk_libs | sed -e 's/-l/-cclib &/g' -e 's/-[LW]/-ccopt &/g' `
echo "TK_DEFS=$tk_defs" >> Makefile
echo "TK_LINK=$tk_libs" >> Makefile
otherlibraries="$otherlibraries labltk"
Expand All @@ -1039,14 +1066,25 @@ echo "BYTECC=$bytecc" >> Makefile
echo "BYTECCCOMPOPTS=$bytecccompopts" >> Makefile
echo "BYTECCLINKOPTS=$bytecclinkopts" >> Makefile
echo "BYTECCLIBS=$cclibs $dllib $curseslibs" >> Makefile
echo "BYTECCRPATH=$byteccrpath" >> Makefile
echo "EXE=$exe" >> Makefile
echo "SHAREDCCCOMPOPTS=$sharedcccompopts" >> Makefile
echo "MKSHAREDLIB=$mksharedlib" >> Makefile
if $shared_libraries_supported; then
echo "SO=so" >> Makefile
echo "CUSTOM_IF_NOT_SHARED=" >> Makefile
else
echo "SO=a" >> Makefile
echo "CUSTOM_IF_NOT_SHARED=-custom" >> Makefile
fi

echo "ARCH=$arch" >> Makefile
echo "MODEL=$model" >> Makefile
echo "SYSTEM=$system" >> Makefile
echo "NATIVECC=$nativecc" >> Makefile
echo "NATIVECCCOMPOPTS=$nativecccompopts" >> Makefile
echo "NATIVECCLINKOPTS=$nativecclinkopts" >> Makefile
echo "NATIVECCRPATH=$nativeccrpath" >> Makefile
echo "NATIVECCLIBS=$cclibs" >> Makefile
echo "ASFLAGS=$asflags" >> Makefile
echo "ASPP=$aspp" >> Makefile
Expand Down Expand Up @@ -1076,6 +1114,13 @@ echo "Configuration for the bytecode compiler:"
echo " C compiler used........... $bytecc"
echo " options for compiling..... $bytecccompopts"
echo " options for linking....... $bytecclinkopts $cclibs $dllib $curseslibs"
if $shared_libraries_supported; then
echo " shared libraries are supported"
echo " options for compiling..... $sharedcccompopts $bytecccompopts"
echo " command for building...... $mksharedlib <target>.so <objects>"
else
echo " shared libraries not supported"
fi

echo "Configuration for the native-code compiler:"
if test "$arch" = "none"; then
Expand Down
1 change: 1 addition & 0 deletions driver/main.ml
Expand Up @@ -74,6 +74,7 @@ module Options = Main_args.Make_options (struct
let _cclib s = ccobjs := s :: !ccobjs
let _ccopt s = ccopts := s :: !ccopts
let _custom = set custom_runtime
let _dllpath s = dllpaths := !dllpaths @ [s]
let _g = set debug
let _i = set print_types
let _I s = include_dirs := s :: !include_dirs
Expand Down
2 changes: 2 additions & 0 deletions driver/main_args.ml
Expand Up @@ -20,6 +20,7 @@ module Make_options (F :
val _cclib : string -> unit
val _ccopt : string -> unit
val _custom : unit -> unit
val _dllpath : string -> unit
val _g : unit -> unit
val _i : unit -> unit
val _I : string -> unit
Expand Down Expand Up @@ -62,6 +63,7 @@ struct
"-ccopt", Arg.String F._ccopt,
"<opt> Pass option <opt> to the C compiler and linker";
"-custom", Arg.Unit F._custom, " Link in custom mode";
"-dllpath", Arg.String F._dllpath, "<dir> Add <dir> to the run-time search path for shared libraries";
"-g", Arg.Unit F._g, " Save debugging information";
"-i", Arg.Unit F._i, " Print the types";
"-I", Arg.String F._I,
Expand Down
1 change: 1 addition & 0 deletions driver/main_args.mli
Expand Up @@ -20,6 +20,7 @@ module Make_options (F :
val _cclib : string -> unit
val _ccopt : string -> unit
val _custom : unit -> unit
val _dllpath : string -> unit
val _g : unit -> unit
val _i : unit -> unit
val _I : string -> unit
Expand Down
2 changes: 2 additions & 0 deletions driver/optmain.ml
Expand Up @@ -73,6 +73,8 @@ let main () =
"<opt> Pass option <opt> to the C compiler and linker";
"-compact", Arg.Clear optimize_for_speed,
" Optimize code size rather than speed";
"-dllpath", Arg.String (fun s -> dllpaths := !dllpaths @ [s]),
"<dir> Add <dir> to the run-time search path for shared libraries";
"-i", Arg.Set print_types, " Print the types";
"-I", Arg.String(fun dir -> include_dirs := dir :: !include_dirs),
"<dir> Add <dir> to the list of include directories";
Expand Down
2 changes: 1 addition & 1 deletion otherlibs/bigarray/Makefile
Expand Up @@ -46,7 +46,7 @@ bigarray.cmxa: $(CAML_OBJS:.cmo=.cmx)
install:
cp bigarray.cmi bigarray.mli libbigarray.a bigarray.cma $(LIBDIR)
cd $(LIBDIR); $(RANLIB) libbigarray.a
if test -f libbigarray.so; then cp libbigarray.so $(LIBDIR)
if test -f libbigarray.so; then cp libbigarray.so $(LIBDIR); fi
cp bigarray.h $(LIBDIR)/caml/bigarray.h

installopt:
Expand Down

0 comments on commit cd65a61

Please sign in to comment.