chiark / gitweb /
initial stab at guile-wrapper/SWIG Makefile
authorstevenj <stevenj@alum.mit.edu>
Thu, 3 Jun 2010 02:06:55 +0000 (22:06 -0400)
committerstevenj <stevenj@alum.mit.edu>
Thu, 3 Jun 2010 02:06:55 +0000 (22:06 -0400)
darcs-hash:20100603020655-c8de0-45c3100538d44d29af80f43ac4c3d88cb06f148e.gz

Makefile.am
autogen.sh
configure.ac
swig/Makefile.am
swig/nlopt-guile.i

index 6e67693c2bf9f7505cb6b7cb885428b2a4c93ac1..63f0e9364c424777a2d35a2870c9ff2f5e891e25 100644 (file)
@@ -8,7 +8,7 @@ CXX_DIRS = stogo
 CXX_LIBS = stogo/libstogo.la
 endif
 
-SUBDIRS = util direct cdirect $(CXX_DIRS) praxis luksan crs mlsl mma cobyla newuoa lbfgs neldermead auglag bobyqa isres api . octave test
+SUBDIRS = util direct cdirect $(CXX_DIRS) praxis luksan crs mlsl mma cobyla newuoa lbfgs neldermead auglag bobyqa isres api . octave test swig
 EXTRA_DIST = autogen.sh nlopt.pc.in m4
 
 if WITH_NOCEDAL
index 143d469e10b9e949fc16be435f14681a0d89e09f..01e036460d57515ca86b9a40fb372e00f64e3726 100755 (executable)
@@ -14,6 +14,8 @@ while test $# -ge 1; do
     shift
 done
 
+touch swig/nlopt.scm.in
+
 # paranoia: sometimes autoconf doesn't get things right the first time
 autoreconf --verbose --install --symlink --force
 autoreconf --verbose --install --symlink --force
index ae7d3f97d4ed0083d26473ae397bf710cb1822de..b53f5ed5a651dfb32332a1daa7b267ed36019de2 100644 (file)
@@ -8,7 +8,7 @@ AM_CONFIG_HEADER(config.h)
 AC_CONFIG_MACRO_DIR([m4])
 AM_MAINTAINER_MODE
 AC_SUBST(SHARED_VERSION_INFO)
-AC_DISABLE_SHARED dnl to hell with shared libraries
+AC_DISABLE_SHARED dnl shared libraries are a PITA, disable by default
 
 dnl Checks for programs.
 AC_PROG_CC
@@ -79,6 +79,41 @@ if test -n "$have_lbfgs"; then
    AC_DEFINE(WITH_NOCEDAL, [1], [Define if we have the non-free Nocedal LBFGS code])
 fi
 
+dnl -----------------------------------------------------------------------
+dnl SWIG wrappers
+
+dnl Guile:
+AC_CHECK_PROG(GUILE_CONFIG, guile-config, guile-config, unknown)
+if test "x$GUILE_CONFIG" = "xunknown"; then
+   AC_MSG_WARN([can't find guile-config, disabling Guile wrapper])
+else
+   save_CPPFLAGS=$CPPFLAGS
+   save_LIBS=$LIBS
+   GUILE_CPPFLAGS=`$GUILE_CONFIG compile`
+   GUILE_LIBS=`$GUILE_CONFIG link`
+   CPPFLAGS="$CPPFLAGS $GUILE_CPPFLAGS"
+   LIBS="$GUILE_LIBS $LIBS"
+   AC_MSG_CHECKING([if linking to guile works])
+   AC_TRY_LINK_FUNC(scm_is_vector, [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
+        AC_MSG_WARN(guile-config is broken, disabling Guile wrapper)
+        GUILE_CONFIG="unknown"])
+   CPPFLAGS=$save_CPPFLAGS
+   LIBS=$save_LIBS
+fi
+AC_CHECK_PROG(GUILE, guile, guile, unknown)
+if test "x$GUILE" = xunknown; then
+   AC_MSG_WARN([can't find guile, disabling Guile wrapper])
+   GUILE_CONFIG=unknown
+else
+   AC_MSG_CHECKING([for Guile site installation directory])
+   GUILE_SITEDIR=`guile -c '(display (%site-dir))'`
+   AC_MSG_RESULT([$GUILE_SITEDIR])
+fi
+AC_SUBST(GUILE_SITEDIR)
+AC_SUBST(GUILE_CPPFLAGS)
+AC_SUBST(GUILE_LIBS)
+AM_CONDITIONAL(WITH_GUILE, test x"$GUILE_CONFIG" != "xunknown")
+
 dnl -----------------------------------------------------------------------
 dnl Compiling Octave plug-in
 
@@ -322,6 +357,8 @@ AC_CONFIG_FILES([
    bobyqa/Makefile
    isres/Makefile
    test/Makefile
+   swig/Makefile
+   swig/nlopt.scm
 ])
 
 AC_OUTPUT
index b362fa7c859ccb1136382f63c8883e3e45397b2c..deeaf5740e31e08f33c750bc282d4288dfe0b0c8 100644 (file)
@@ -1,13 +1,37 @@
-EXTRA_DIST = nlopt.i nlopt-guile.i
+EXTRA_DIST = nlopt.i nlopt-guile.i nlopt-enum-renames.i nlopt.scm.in
 
-BUILT_SOURCES = nlopt-guile.cpp nlopt-renames.i
+BUILT_SOURCES = nlopt-guile.cpp nlopt-enum-renames.i nlopt.scm.in
 
-HDR = $(top_srcdir)/api/nlopt.hpp
+HDR = $(top_builddir)/api/nlopt.hpp
+
+##############################################################################
+# Guile wrapper
+
+libnlopt@NLOPT_SUFFIX@_guile_la_SOURCES = nlopt-guile.cpp
+libnlopt@NLOPT_SUFFIX@_guile_la_LDFLAGS = -version-info @SHARED_VERSION_INFO@
+libnlopt@NLOPT_SUFFIX@_guile_la_CPPFLAGS = $(GUILE_CPPFLAGS) -I$(top_builddir)/api
+
+guiledir = $(GUILE_SITEDIR)
+if WITH_GUILE
+guile_DATA = nlopt.scm
+guilelib = libnlopt@NLOPT_SUFFIX@_guile.la
+endif
+
+
+
+##############################################################################
+
+lib_LTLIBRARIES = $(guilelib)
+
+##############################################################################
+# Generate wrappers via SWIG:
 
 if MAINTAINER_MODE
 
-nlopt-guile.cpp: nlopt.i nlopt-enum-renames.i nlopt-guile.i $(top_builddir)/api/nlopt.hpp
+nlopt-guile.cpp: nlopt.i nlopt-enum-renames.i nlopt-guile.i $(HDR)
        swig -I$(top_builddir)/api -outdir $(builddir) -c++ -guile -scmstub -o $@ nlopt.i
+       rm -f nlopt.scm.in
+       mv nlopt.scm nlopt.scm.in
 
 nlopt-enum-renames.i: $(top_srcdir)/api/nlopt.h
        (echo "// AUTOMATICALLY GENERATED -- DO NOT EDIT"; egrep 'NLOPT_[LG][DN]|NLOPT_NUM_ALGORITHMS' $(top_srcdir)/api/nlopt.h | sed 's/NLOPT_//g' |tr -d ' ' |tr '/' ',' |tr '=' ',' |cut -d, -f1 |while read name; do echo "%rename(NLOPT_$$name) nlopt::$$name;"; done; egrep 'NLOPT_[A-Z_]* =' $(top_srcdir)/api/nlopt.h | egrep -v 'NLOPT_[LG][DN]' | sed 's/NLOPT_//g' |tr -d ' ' |cut -d'=' -f1 | while read name; do echo "%rename(NLOPT_$$name) nlopt::$$name;"; done) > $@
index 7414b8ab086c004310d4795a434a93282108d9a3..faf23f82d72965f5be4c3153bea1c80afc29fdcb 100644 (file)
@@ -6,7 +6,7 @@ static double vfunc_guile(const std::vector<double> &x,
   SCM xscm = scm_c_make_vector(x.size(), SCM_UNSPECIFIED);
   for (unsigned i = 0; i < x.size(); ++i)
     scm_c_vector_set_x(xscm, i, scm_make_real(x[i]));
-  SCM ret = scm_call_2((SCM) f, xscm);
+  SCM ret = scm_call_1((SCM) f, xscm);
   if (scm_real_p(ret)) {
     if (grad.size()) throw std::invalid_argument("missing gradient");
     return scm_to_double(ret);
@@ -36,6 +36,6 @@ static double vfunc_guile(const std::vector<double> &x,
 %feature("constasvar", "1");
 
 %scheme %{ 
-(dynamic-link "libnlopt.so")
-(load-extension "libnlopt-guile.so" "SWIG_init")
+(dynamic-link "libnlopt@NLOPT_SUFFIX@.so")
+(load-extension "libnlopt@NLOPT_SUFFIX@_guile.so" "SWIG_init")
 %}