Added info about dynamic linking to doc

Added dynamic targets to example makefiles
Added ocaml_dynamic and ocaml_dynamic_cpp targets to Examples/Makefile.in
Added OCAMLFIND and OCAMLDLGEN AC_SUBST lines in configure.in
Currently, dynamic linking relies on ocamlfind and Gerd Stolpmann's Dl package,
as well as some tricky elf linking.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4413 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Art Yerkes 2003-02-27 09:25:00 +00:00
commit a1fa5ec2c1
8 changed files with 99 additions and 8 deletions

View file

@ -62,11 +62,12 @@ best way to determine whether your system will work is to compile the
examples and test-suite which come with SWIG. You can do this by running
<tt>make check</tt> from the SWIG root directory after installing SWIG.
The Ocaml module has been tested using the system's dynamic linking (the
usual -lxxx against libxxx.so, but not using the explicit dynamic linking
provided by the Dl package <a
href="http://www.ocaml-programming.de/packages/documentation/dl/"> http://www.ocaml-programming.de/packages/documentation/dl/
</a>, although I suspect that it will work without a problem. If anyone
would like to evaluate this support, I will share the results here.
usual -lxxx against libxxx.so, as well as with Gerd Stolpmann's
<a
href="http://www.ocaml-programming.de/packages/documentation/dl/">Dl package
</a>. The ocaml_dynamic and ocaml_dynamic_cpp targets in the
file Examples/Makefile illustrate how to compile and link SWIG modules that
will be loaded dynamically. This has only been tested on Linux so far.
<a name="n3"></a><H3>16.1.1 Running SWIG</H3>

View file

@ -19,6 +19,13 @@ static::
INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ocaml_static
dynamic::
$(MAKE) -f $(TOP)/Makefile TOP='$(TOP)' \
IOBJS='$(IOBJS)' PROGFILE='$(PROGFILE)' \
SRCS='$(SRCS)' SWIG='$(SWIG)' MLFILE='$(MLFILE)' \
INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ocaml_dynamic
clean::
$(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean
rm -f *.gif

View file

@ -19,6 +19,13 @@ static::
INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ocaml_static
dynamic::
$(MAKE) -f $(TOP)/Makefile TOP='$(TOP)' \
IOBJS='$(IOBJS)' PROGFILE='$(PROGFILE)' \
SRCS='$(SRCS)' SWIG='$(SWIG)' MLFILE='$(MLFILE)' \
INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ocaml_static
clean::
$(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean
rm -f *.gif

View file

@ -508,6 +508,8 @@ mzscheme_clean:
##################################################################
OCC=@OCAMLC@
OCAMLDLGEN=@OCAMLDLGEN@
OCAMLFIND=@OCAMLFIND@
NOLINK ?= false
ocaml_static: $(SRCS)
@ -522,9 +524,25 @@ ocaml_static: $(SRCS)
$(PROGFILE:%.ml=%.cmo) \
$(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)"
ocaml_dynamic: $(SRCS)
$(SWIG) -ocaml $(SWIGOPT) $(INTERFACE)
$(OCC) -g -c -ccopt -g -ccopt "$(INCLUDES)" $(ISRCS) $(SRCS)
$(CXXSHARED) $(CCSHARED) $(CFLAGS) -o $(INTERFACE:%.i=%@SO@) \
$(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) $(LIBS)
$(OCAMLDLGEN) $(INTERFACE:%.i=%.ml) $(INTERFACE:%.i=%@SO@) > \
$(INTERFACE:%.i=%_dynamic.ml)
mv $(INTERFACE:%.i=%_dynamic.ml) $(INTERFACE:%.i=%.ml)
rm $(INTERFACE:%.i=%.mli)
$(OCAMLFIND) $(OCC) -g -c -package dl $(INTERFACE:%.i=%.ml)
test -z "$(PROGFILE)" || test -f "$(PROGFILE)" && \
$(OCC) -c $(PROGFILE)
$(NOLINK) || $(OCAMLFIND) \
$(OCC) -g -ccopt -g -cclib -g -custom -o $(TARGET) \
-package dl -linkpkg \
$(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo)
ocaml_static_cpp: $(SRCS)
$(SWIG) -ocaml -c++ $(SWIGOPT) \
$(INTERFACE)
$(SWIG) -ocaml -c++ $(SWIGOPT) $(INTERFACE)
cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c)
$(OCC) -cc '$(CXX)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \
$(ICXXSRCS:%.cxx=%.c) $(SRCS) $(CXXSRCS)
@ -535,7 +553,29 @@ ocaml_static_cpp: $(SRCS)
$(NOLINK) || $(OCC) -g -ccopt -g -cclib -g -custom -o $(TARGET) \
$(INTERFACE:%.i=%.cmo) \
$(PROGFILE:%.ml=%.cmo) \
$(INTERFACE:%.i=%_wrap.@OBJEXT@) -cclib "$(LIBS)" -cc '$(CXX)'
$(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \
-cclib "$(LIBS)" -cc '$(CXX)'
ocaml_dynamic_cpp: $(SRCS)
$(SWIG) -ocaml -c++ $(SWIGOPT) $(INTERFACE)
cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c)
$(OCC) -cc '$(CXX)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \
$(ICXXSRCS:%.cxx=%.c) $(SRCS) $(CXXSRCS) -ccopt -fPIC
$(CXXSHARED) $(CXXFLAGS) -o $(INTERFACE:%.i=%@SO@) \
$(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \
$(CPP_DLLIBS) $(LIBS)
$(OCAMLDLGEN) $(INTERFACE:%.i=%.ml) $(INTERFACE:%.i=%@SO@) > \
$(INTERFACE:%.i=%_dynamic.ml)
mv $(INTERFACE:%.i=%_dynamic.ml) $(INTERFACE:%.i=%.ml)
rm $(INTERFACE:%.i=%.mli)
$(OCAMLFIND) $(OCC) -g -c -package dl $(INTERFACE:%.i=%.ml)
test -z "$(PROGFILE)" || test -f "$(PROGFILE)" && \
$(OCC) -c $(PROGFILE)
$(NOLINK) || $(OCAMLFIND) \
$(OCC) -cclib -export-dynamic -g -ccopt -g -cclib -g -custom \
-o $(TARGET) \
-package dl -linkpkg \
$(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) -cc '$(CXX)'
ocaml_static_multi_cpp: $(SRCS)
$(SWIG) -c -ocaml -c++ $(SWIGOPT) \

View file

@ -9,6 +9,12 @@ OBJS = example.o
all:: static
dynamic::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
ocaml_dynamic
static::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \

View file

@ -12,6 +12,11 @@ static::
PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
ocaml_static_cpp
dynamic::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
ocaml_dynamic_cpp
clean::
$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean

View file

@ -12,6 +12,11 @@ static::
PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
ocaml_static_cpp
dynamic::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
ocaml_dynamic_cpp
clean::
$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean

View file

@ -914,6 +914,22 @@ AC_SUBST(PHP4INC)
AC_ARG_WITH(ocaml,[ --with-ocaml=path Set location of ocaml executable],[ OCAMLBIN="$withval"], [OCAMLBIN=])
AC_ARG_WITH(ocamlc,[ --with-ocamlc=path Set location of ocamlc executable],[ OCAMLC="$withval"], [OCAMLC=])
AC_ARG_WITH(ocamldlgen,[ --with-ocamldlgen=path Set location of ocamldlgen],[ OCAMLDLGEN="$withval" ], [OCAMLDLGEN=])
AC_ARG_WITH(ocamlfind,[ --with-ocamlfind=path Set location of ocamlfind],[OCAMLFIND="$withval"],[OCAMLFIND=])
AC_MSG_CHECKING(for Ocaml DL load generator)
if test -z "$OCAMLDLGEN"; then
AC_CHECK_PROGS(OCAMLDLGEN, ocamldlgen, ocamldlgen)
else
OCAMLDLGEN="$OCAMLDLGEN"
fi
AC_MSG_CHECKING(for Ocaml package tool)
if test -z "$OCAMLFIND"; then
AC_CHECK_PROGS(OCAMLFIND, ocamlfind, ocamlfind)
else
OCAMLFIND="$OCAMLFIND"
fi
AC_MSG_CHECKING(for Ocaml compiler)
if test -z "$OCAMLC"; then
@ -945,10 +961,14 @@ fi
export OCAMLINC
export OCAMLBIN
export OCAMLC
export OCAMLDLGEN
export OCAMLFIND
AC_SUBST(OCAMLINC)
AC_SUBST(OCAMLBIN)
AC_SUBST(OCAMLC)
AC_SUBST(OCAMLDLGEN)
AC_SUBST(OCAMLFIND)
#----------------------------------------------------------------
# Look for Pike