Commit 7b429157 authored by Roland Levillain's avatar Roland Levillain
Browse files

Revive Swilena.

	* build-aux/pypath.m4, build-aux/swig.m4: New, imported.
	* build-aux/with-swilena.m4: New, imported from TC and adjusted.
	* configure.ac: Add support for Libtool, SWIG and Swilena.
	* Makefile.am (SUBDIRS): Append swilena.
	* swilena/: New directory.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@2096 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 6049e909
2008-07-22 Roland Levillain <roland@lrde.epita.fr>
Revive Swilena.
* build-aux/pypath.m4, build-aux/swig.m4: New, imported.
* build-aux/with-swilena.m4: New, imported from TC and adjusted.
* configure.ac: Add support for Libtool, SWIG and Swilena.
* Makefile.am (SUBDIRS): Append swilena.
* swilena/: New directory.
2008-06-23 Roland Levillain <roland@lrde.epita.fr>
Update external/README.
......
......@@ -3,3 +3,6 @@
ACLOCAL_AMFLAGS = -I build-aux
SUBDIRS = build-aux external milena
# FIXME: Make Swilena optional (see TC's equipment).
SUBDIRS += swilena
AC_DEFUN([adl_CHECK_PYTHON],
[AM_PATH_PYTHON([2.0])
AC_CACHE_CHECK([for $am_display_PYTHON includes directory],
[adl_cv_python_inc],
[adl_cv_python_inc=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_inc()" 2>/dev/null`])
AC_SUBST([PYTHONINC], [$adl_cv_python_inc])])
dnl @synopsis AC_PROG_SWIG([major.minor.micro])
dnl
dnl This macro searches for a SWIG installation on your system. If found you
dnl should call SWIG via $(SWIG). You can use the optional first argument to
dnl check if the version of the available SWIG is greater than or equal to the
dnl value of the argument. It should have the format: N[.N[.N]] (N is a
dnl number between 0 and 999. Only the first N is mandatory.)
dnl
dnl If the version argument is given (e.g. 1.3.17), AC_PROG_SWIG checks that the
dnl swig package is this version number or higher.
dnl
dnl In configure.in, use as:
dnl
dnl AC_PROG_SWIG(1.3.17)
dnl SWIG_ENABLE_CXX
dnl SWIG_MULTI_MODULE_SUPPORT
dnl SWIG_PYTHON
dnl
dnl @author Sebastian Huber <sebastian-huber@web.de>, Alan W. Irwin <irwin@beluga.phys.uvic.ca>, Rafael Laboissiere <rafael@laboissiere.net>, and Andrew Collier <abcollier@yahoo.com>.
dnl @version $Id: ac_pkg_swig.m4,v 1.2 2004/12/24 01:20:01 guidod Exp $
dnl
AC_DEFUN([AC_PROG_SWIG],[
AC_PATH_PROG([SWIG],[swig])
if test -z "$SWIG" ; then
AC_MSG_WARN([cannot find 'swig' program. You should look at http://www.swig.org])
SWIG='echo "Error: SWIG is not installed. You should look at http://www.swig.org" ; false'
elif test -n "$1" ; then
AC_MSG_CHECKING([for SWIG version])
[swig_version=`$SWIG -version 2>&1 | grep 'SWIG Version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`]
AC_MSG_RESULT([$swig_version])
if test -n "$swig_version" ; then
# Calculate the required version number components
[required=$1]
[required_major=`echo $required | sed 's/[^0-9].*//'`]
if test -z "$required_major" ; then
[required_major=0]
fi
[required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
[required_minor=`echo $required | sed 's/[^0-9].*//'`]
if test -z "$required_minor" ; then
[required_minor=0]
fi
[required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
[required_patch=`echo $required | sed 's/[^0-9].*//'`]
if test -z "$required_patch" ; then
[required_patch=0]
fi
# Calculate the available version number components
[available=$swig_version]
[available_major=`echo $available | sed 's/[^0-9].*//'`]
if test -z "$available_major" ; then
[available_major=0]
fi
[available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
[available_minor=`echo $available | sed 's/[^0-9].*//'`]
if test -z "$available_minor" ; then
[available_minor=0]
fi
[available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
[available_patch=`echo $available | sed 's/[^0-9].*//'`]
if test -z "$available_patch" ; then
[available_patch=0]
fi
if test $available_major -ne $required_major \
-o $available_minor -ne $required_minor \
-o $available_patch -lt $required_patch ; then
AC_MSG_WARN([SWIG version >= $1 is required. You have $swig_version. You should look at http://www.swig.org])
SWIG='echo "Error: SWIG version >= $1 is required. You have '"$swig_version"'. You should look at http://www.swig.org" ; false'
else
AC_MSG_NOTICE([SWIG executable is '$SWIG'])
SWIG_LIB=`$SWIG -swiglib`
AC_MSG_NOTICE([SWIG library directory is '$SWIG_LIB'])
fi
else
AC_MSG_WARN([cannot determine SWIG version])
SWIG='echo "Error: Cannot determine SWIG version. You should look at http://www.swig.org" ; false'
fi
fi
AC_SUBST([SWIG_LIB])
])
# SWIG_ENABLE_CXX()
#
# Enable SWIG C++ support. This affects all invocations of $(SWIG).
AC_DEFUN([SWIG_ENABLE_CXX],[
AC_REQUIRE([AC_PROG_SWIG])
AC_REQUIRE([AC_PROG_CXX])
SWIG="$SWIG -c++"
])
# SWIG_MULTI_MODULE_SUPPORT()
#
# Enable support for multiple modules. This effects all invocations
# of $(SWIG). You have to link all generated modules against the
# appropriate SWIG runtime library. If you want to build Python
# modules for example, use the SWIG_PYTHON() macro and link the
# modules against $(SWIG_PYTHON_LIBS).
#
AC_DEFUN([SWIG_MULTI_MODULE_SUPPORT],[
AC_REQUIRE([AC_PROG_SWIG])
SWIG="$SWIG -noruntime"
])
# SWIG_PYTHON([use-shadow-classes = {no, yes}])
#
# Checks for Python and provides the $(SWIG_PYTHON_CPPFLAGS),
# and $(SWIG_PYTHON_OPT) output variables.
#
# $(SWIG_PYTHON_OPT) contains all necessary SWIG options to generate
# code for Python. Shadow classes are enabled unless the value of the
# optional first argument is exactly 'no'. If you need multi module
# support (provided by the SWIG_MULTI_MODULE_SUPPORT() macro) use
# $(SWIG_PYTHON_LIBS) to link against the appropriate library. It
# contains the SWIG Python runtime library that is needed by the type
# check system for example.
AC_DEFUN([SWIG_PYTHON],[
AC_REQUIRE([AC_PROG_SWIG])
AC_REQUIRE([AC_PYTHON_DEVEL])
test "x$1" != "xno" || swig_shadow=" -noproxy"
AC_SUBST([SWIG_PYTHON_OPT],[-python$swig_shadow])
AC_SUBST([SWIG_PYTHON_CPPFLAGS],[$PYTHON_CPPFLAGS])
])
dnl @synopsis AC_LIB_WAD
dnl
dnl This macro searches for installed WAD library.
dnl
AC_DEFUN([AC_LIB_WAD],
[
AC_REQUIRE([AC_PYTHON_DEVEL])
AC_ARG_ENABLE(wad,
AC_HELP_STRING([--enable-wad], [enable wad module]),
[
case "${enableval}" in
no) ;;
*) if test "x${enableval}" = xyes;
then
check_wad="yes"
fi ;;
esac
], [])
if test -n "$check_wad";
then
AC_CHECK_LIB(wadpy, _init, [WADPY=-lwadpy], [], $PYTHON_LDFLAGS $PYTHON_EXTRA_LIBS)
AC_SUBST(WADPY)
fi
])
# -*- Autoconf -*-
# FIXME: Revamp and make it generic, so that it can shared among
# Olena, TC and clspr.
# _OLN_WITH_SWIG(HAS-SWIG, HAS-NOT)
# ---------------------------------
# Check whether SWIG is requested, enabled, or disabled. If
# requested, check that Python is present as needed. If enabled,
# actually enable only if the environment is complete.
AC_DEFUN([_OLN_WITH_SWIG],
# FIXME: `with-swig' used to be set to `auto', but `no' is prefered
# now, as
# 1. users don't necessarily want to build Swilena by default;
# 2. the `auto' flag is not honored by the checks for Python and Ruby.
[AC_ARG_WITH([swig],
[AC_HELP_STRING([--with-swig],
[require SWIG modules (defaults to no)])],
[],
[with_swig=no])
case $with_swig:$enable_shared in
auto:no)
AC_MSG_NOTICE([SWIG use disabled: dynamic libraries disabled])
with_swig=no
;;
esac
if test x$with_swig != xno; then
oln_has_swig=yes
AM_PATH_PYTHON([2.3])
adl_CHECK_PYTHON
# Check for Python and SWIG.
save_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS -I$PYTHONINC"
AC_CHECK_HEADERS([Python.h],
[python_headers=yes],
[python_headers=no])
if test x$python_headers = xno; then
oln_has_swig=no
if test x$with_swig = xyes; then
AC_MSG_ERROR(
[Python.h is required to build SWIG modules.
Add `-I python_include_path' to `CPPFLAGS'
or `--without-swig' to disable SWIG modules.])
fi
fi
CPPFLAGS=$save_CPPFLAGS
# Check for Ruby.
AC_CHECK_PROGS([RUBY], [ruby], [$am_aux_dir/missing ruby])
if test "x$RUBY" = "x$am_aux_dir/missing ruby"; then
AC_MSG_ERROR([no suitable Ruby interpreter found])
fi
AC_ARG_VAR([RUBY_CPPFLAGS], [Path to ruby.h])
AC_ARG_WITH([ruby-includedir], [Include path for ruby.h],
[RUBY_CPPFLAGS="-I$withval"],
[RUBY_CPPFLAGS="-I`$RUBY -e 'puts $:.join("\n")' | \
while read line
do
if [[ -f ${line}/ruby.h ]]; then
echo $line
fi
done`"])
save_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $RUBY_CPPFLAGS"
AC_CHECK_HEADERS([ruby.h], [],
[AC_MSG_ERROR(
[You need Ruby development files to compile the Ruby interface.])])
CPPFLAGS=$save_CPPFLAGS
AC_PROG_SWIG([1.3.29])
if (eval "$SWIG -version") >/dev/null 2>&1; then :; else
oln_has_swig=no
fi
case $with_swig:$oln_has_swig in
yes:no)
AC_MSG_ERROR([SWIG 1.3.29 is required.
Use `--without-swig' to disable SWIG modules.]);;
esac
fi
case $oln_has_swig in
yes) $1;;
* ) $2;;
esac
])
# OLN_WITH_SWILENA(WITH, WITHOUT)
# -------------------------------
# Should we build Swilena or not.
AC_DEFUN([OLN_WITH_SWILENA],
[AC_CACHE_CHECK([whether building Swilena],
[oln_cv_with_swilena],
[_OLN_WITH_SWIG([oln_cv_with_swilena=yes],
[oln_cv_with_swilena=no])])
case $oln_cv_with_swilena in
yes) $1;;
no ) $2;;
*) AC_MSG_ERROR([incorrect oln_cv_with_swilena value: $oln_cv_with_swilena]);;
esac
])
......@@ -98,6 +98,19 @@ OLN_WITH_CFITSIO
AM_CONDITIONAL([CFITSIO], [test x$oln_have_cfitsio = xyes])
## --------- ##
## Swilena. ##
## --------- ##
AC_PROG_LIBTOOL
OLN_WITH_SWILENA([with_swilena=yes], [with_swilena=no])
AM_CONDITIONAL([ENABLE_SWILENA], [test x$with_swilena = xyes])
AC_CONFIG_FILES([swilena/Makefile swilena/python/Makefile])
AC_CONFIG_FILES([swilena/run], [chmod +x swilena/run])
## --------------- ##
## Configuration. ##
## --------------- ##
......
2008-07-22 Roland Levillain <roland@lrde.epita.fr>
Revive Swilena.
* swilena/image2d.i: New SWIG wrapper.
* swilena/run.in: New helper, imported from TC.
* swilena/Makefile.am: New.
* swilena/run.mk: New, imported from TC and adjusted.
* swilena/python/: New directory.
* swilena/python/ltihooks.py: New, imported.
* swilena/python/test.py: New test.
* swilena/python/Makefile.am: New.
$Rev$
$Id$
$Date$
Local Variables:
ispell-local-dictionary: "american"
coding: iso-latin-1
End:
## Process this file through Automake to produce Makefile.in -*- Makefile -*-
SUBDIRS = python
EXTRA_DIST = image2d.i
check_SCRIPTS = run
// -*- C++ -*-
// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License.
// reasons why the executable file might be covered by the GNU General
// Public License.
/// \file image2d.i
/// \brief A simple wrapping of mln::image2d<int> along with some
/// algorithms.
%module image2d
/*------.
| int. |
`------*/
%include "cpointer.i"
// Wrap a class interface around an "int *" (see
// // http://www.swig.org/Doc1.3/Library.html#Library_nn4).
// %pointer_class(int, intp);
/* Create some functions for working with "int *" */
%pointer_functions(int, intp);
/*---------------.
| mln::point2d. |
`---------------*/
%{
#include "mln/core/point.hh"
#include "mln/core/point2d.hh"
%}
%include "mln/core/point.hh";
%include "mln/core/point2d.hh";
/* FIXME: Ignore `mln::point_<M,C>::origin' to circumvent a swig bug.
Without this ignore clause, the generated code would trigger this
error :
image2d-wrap.cc:3115:144: error: macro "SWIG_as_voidptr" passed 2
arguments, but takes just 1
image2d-wrap.cc: In function 'PyObject* point2d_origin_get()':
image2d-wrap.cc:3115: error: 'SWIG_as_voidptr' was not declared in this
scope
Check whether this bug has been fixed in a recent release of SWIG
or if it has been reported. */
%ignore mln::point_<mln::grid::square,int>::origin;
// Ignoring to_h_vec saves us the wrapping of
%ignore mln::point_<mln::grid::square,int>::to_h_vec;
// Swig tries to wrap everything by default; prevent it from wrapping
// invalid methods (1D and 3D ctors for a point2d).
%ignore mln::point_<mln::grid::square,int>::point_(const literal::zero_t&);
%ignore mln::point_<mln::grid::square,int>::point_(const literal::one_t&);
%ignore mln::point_<mln::grid::square,int>::point_(int);
%ignore mln::point_<mln::grid::square,int>::point_(int, int, int);
// point2d.
%template(point2d) mln::point_<mln::grid::square,int>;
/*--------------------.
| mln::image2d<int>. |
`--------------------*/
%{
#include "mln/core/image2d.hh"
%}
%include "mln/core/box2d.hh";
%include "mln/core/dpoint2d.hh";
%include "mln/core/concept/image.hh";
// FIXME: Wrap mln::image2d by hand, for Milena macros disturb swig.
// Annotate the original source code instead?
namespace mln
{
template <typename T>
struct image2d
/* FIXME: This is a simple wrapping; ignore the base class (for the
moment). */
// : public internal::image_primary_< box2d, image2d<T> >
/* FIXME: Cheat, so that generic algorithms can use mln::image2d. */
: public Image< image2d<T> >
{
// Warning: just to make effective types appear in Doxygen:
typedef box2d pset;
typedef point2d psite;
typedef point2d point;
typedef dpoint2d dpoint;
// FIXME: Those typedefs disturb swig.
// typedef mln_fwd_piter(box2d) fwd_piter;
// typedef mln_bkd_piter(box2d) bkd_piter;
typedef line_piter_<point> line_piter;
// End of warning.
/// Value associated type.
typedef T value;
/// Return type of read-only access.
typedef const T& rvalue;
/// Return type of read-write access.
typedef T& lvalue;
/// Skeleton.
typedef image2d< tag::value_<T> > skeleton;
/// Value_Set associated type.
typedef mln::value::set<T> vset;
/// Constructor without argument.
image2d();
/// Constructor with the numbers of rows and columns and the
/// border thickness.
image2d(int nrows, int ncols, unsigned bdr = border::thickness);
/// Constructor with a box and the border thickness (default is
/// 3).
image2d(const box2d& b, unsigned bdr = border::thickness);
/// Initialize an empty image.
void init_(const box2d& b, unsigned bdr = border::thickness);
/// Test if \p p is valid.
bool owns_(const point2d& p) const;
/// Give the set of values of the image.
const vset& values() const;
/// Give the definition domain.
const box2d& domain() const;
/// Give the border thickness.
unsigned border() const;
/// Give the number of cells (points including border ones).
std::size_t ncells() const;
/// Read-only access to the image value located at point \p p.
const T& operator()(const point2d& p) const;
/// Read-write access to the image value located at point \p p.
T& operator()(const point2d& p);
// FIXME: swig won't wrap this operator.
// /// Read-only access to the image value located at offset \p o.
// const T& operator[](unsigned o) const;
// FIXME: swig won't wrap this operator.
// /// Read-write access to the image value located at offset \p o.
// T& operator[](unsigned o);
/// Read-only access to the image value located at (\p row, \p col).
const T& at(int row, int col) const;
/// Read-write access to the image value located at (\p row, \p col).
T& at(int row, int col);
/// Fast Image method
/// Give the offset corresponding to the delta-point \p dp.
int offset(const dpoint2d& dp) const;
/// Give the point corresponding to the offset \p o.
point2d point_at_offset(unsigned o) const;
/// Give a hook to the value buffer.
const T* buffer() const;
/// Give a hook to the value buffer.
T* buffer();
/// Resize image border with new_border.
void resize_(unsigned new_border);
};
} // end of namespace mln
%template(image2d_int) mln::image2d<int>;
/*-------------------.
| mln::level::fill. |
`-------------------*/
%{
#include "mln/level/fill.hh"
%}
// FIXME: Wrap mln::level::fill by hand, for mln_value(I) disturbs
// swig. Annotate the original source code instead?
namespace mln
{
namespace level
{
template <typename I>
void fill(mln::Image<I>& ima, const typename I::value& v);
} // end of namespace mln::level
} // end of namespace mln
%template(fill_image2d_int) mln::level::fill< mln::image2d<int> >;
/*----------------------.
| mln::debug::println. |
`----------------------*/
%{
#include "mln/debug/println.hh"
%}
%include "mln/debug/println.hh"
%template(println_image2d_int) mln::debug::println< mln::image2d<int> >;
## Process this file through Automake to produce Makefile.in -*- Makefile -*-
## ------------------ ##
## Generic material. ##
## ------------------ ##
## FIXME: Factor as much as possible. See how we handled this in TC.
CLEANFILES =
AM_CPPFLAGS = -I$(PYTHONINC) -I$(top_srcdir)/milena
AM_SWIGFLAGS = -c++ -python -I$(top_srcdir)/milena
## We build modules, not plain libs.
AM_LDFLAGS = -avoid-version -module -shared
#### All the modules depend on libhw.
##AM_LIBADD = $(top_builddir)/libhw.la
## Run Swig to create the C++ wrapper files, the Python interface
## files, and the dependency Makefile snippets.
%-wrap.cc %.py: $(top_srcdir)/swilena/%.i
if $(SWIG) $(AM_SWIGFLAGS) $(SWIGFLAGS) -MD -MF "$(DEPDIR)/$*-wrap.Tcc" -o $@ $<; then \
mv -f "$(DEPDIR)/$*-wrap.Tcc" "$(DEPDIR)/$*-wrap.Pcc";\
else \
rm -f "$(DEPDIR)/$*-wrap.Tcc"; exit 1;\
fi
# ltihooks.py: Python import hooks that understand Libtool libraries.
python_PYTHON = ltihooks.py
## ----------------- ##
## Wrapped modules. ##
## ----------------- ##
## FIXME: All of this should be generated.
## Don't forget to add a `deps-reset' target as in TC.
## image2d.
pyexec_LTLIBRARIES = _image2d.la
nodist__image2d_la_SOURCES = image2d-wrap.cc
_image2d_la_LIBADD = $(AM_LIBADD)
CLEANFILES += $(nodist__image2d_la_SOURCES) image2d.py image2d.py[co]
## Include the dependency files. Copied from Automake's generated
## case for C++.
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/_image2d-wrap.Pcc@am__quote@
nodist_python_PYTHON = image2d.py
## ------- ##
## Tests. ##
## ------- ##
include $(top_srcdir)/swilena/run.mk
## FIXME: Do we really need to pass top_srcdir and top_builddir to run?