From: stevenj Date: Thu, 3 Jun 2010 02:06:55 +0000 (-0400) Subject: initial stab at guile-wrapper/SWIG Makefile X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=090f1b6e5692033e13a965d0b5e0513e0ded27f0;p=nlopt.git initial stab at guile-wrapper/SWIG Makefile darcs-hash:20100603020655-c8de0-45c3100538d44d29af80f43ac4c3d88cb06f148e.gz --- diff --git a/Makefile.am b/Makefile.am index 6e67693..63f0e93 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/autogen.sh b/autogen.sh index 143d469..01e0364 100755 --- a/autogen.sh +++ b/autogen.sh @@ -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 diff --git a/configure.ac b/configure.ac index ae7d3f9..b53f5ed 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/swig/Makefile.am b/swig/Makefile.am index b362fa7..deeaf57 100644 --- a/swig/Makefile.am +++ b/swig/Makefile.am @@ -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) > $@ diff --git a/swig/nlopt-guile.i b/swig/nlopt-guile.i index 7414b8a..faf23f8 100644 --- a/swig/nlopt-guile.i +++ b/swig/nlopt-guile.i @@ -6,7 +6,7 @@ static double vfunc_guile(const std::vector &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 &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") %}