From 3cae1d138c53a3fd042de3d2c9d9a07cf0650e0f Mon Sep 17 00:00:00 2001
From: "Daniel M. Pelt" <D.M.Pelt@cwi.nl>
Date: Tue, 24 Feb 2015 12:35:45 +0100
Subject: Added Python interface

---
 build/linux/Makefile.in  | 45 +++++++++++++++++++++++++++++++++++++++++++--
 build/linux/configure.ac | 31 ++++++++++++++++++++++++-------
 2 files changed, 67 insertions(+), 9 deletions(-)

(limited to 'build/linux')

diff --git a/build/linux/Makefile.in b/build/linux/Makefile.in
index 685e1e5..fe1ba91 100644
--- a/build/linux/Makefile.in
+++ b/build/linux/Makefile.in
@@ -1,5 +1,7 @@
 cuda=@HAVECUDA@
 matlab=@HAVEMATLAB@
+python=@HAVEPYTHON@
+
 
 MATLAB_ROOT=@MATLAB_ROOT@
 
@@ -9,6 +11,10 @@ ifeq ($(matlab),yes)
 TARGETS+=mex
 endif
 
+ifeq ($(python),yes)
+TARGETS+=py
+endif
+
 all: $(TARGETS)
 
 prefix=@prefix@
@@ -39,6 +45,14 @@ CXXFLAGS+=-fopenmp
 LDFLAGS+=-fopenmp
 endif
 
+ifeq ($(python),yes)
+PYCPPFLAGS  = ${CPPFLAGS}
+PYCPPFLAGS  += -I../include
+PYLDFLAGS = ${LDFLAGS}
+PYLDFLAGS   += -L../build/linux/.libs
+PYTHON      = @PYTHON@
+endif
+
 BOOST_CPPFLAGS=
 BOOST_LDFLAGS=
 
@@ -53,7 +67,7 @@ LD=@CXX@
 SHELL=@SHELL@
 
 ifeq ($(matlab),yes)
-MEXFLAGS  = -cxx 
+MEXFLAGS  = -cxx
 MEXLDFLAGS='$$LDFLAGS $(LDFLAGS)'
 MEXLIBS   = -L.libs -lut
 MEXSUFFIX = @MEXSUFFIX@
@@ -226,6 +240,14 @@ mex: $(MATLAB_MEX)
 	$(MEX) LDFLAGS=$(MEXLDFLAGS) $(MEXFLAGS) $(LIBS) $(MEXLIBS) -lastra -output $* $*.o $(MATLAB_CXX_OBJECTS)
 endif
 
+ifeq ($(python),yes)
+py: libastra.la
+	cd ../../python; CPPFLAGS="${PYCPPFLAGS}" LDFLAGS="${PYLDFLAGS}" $(PYTHON) builder.py install \
+	--install-base=./finalbuild --install-headers=./finalbuild --install-purelib=./finalbuild \
+	--install-platlib=./finalbuild --install-scripts=./finalbuild --install-data=./finalbuild
+endif
+
+
 libastra.la: $(ALL_OBJECTS)
 	./libtool --mode=link --tag=CXX $(LD) -rpath $(LIBDIR) -o $@ $(LDFLAGS) $(LIBS) $+
 
@@ -278,6 +300,8 @@ clean:
 	rm -f $(addsuffix /*.d,$(DEPDIRS))
 	rm -f $(addsuffix /*,$(LIBDIRS))
 	rm -f $(TEST_OBJECTS) test.bin
+	rm -fr ../../python/finalbuild/
+	rm -fr ../../python/build/
 
 distclean: clean
 	rm -f config.guess config.sub ltmain.sh libtool install-sh
@@ -286,7 +310,7 @@ distclean: clean
 	rm -rf autom4te.cache
 	rm -f configure Makefile
 
-install: install-libraries install-matlab
+install: install-libraries install-matlab install-python
 
 install-libraries: libastra.la
 	./install-sh -m 755 -d @libdir@
@@ -306,6 +330,23 @@ else
 install-matlab:
 endif
 
+ifeq ($(python),yes)
+# TODO: This install location doesn't work well for /usr or /usr/local
+install-python: py
+	./install-sh -m 755 -d @prefix@/python
+	./install-sh -m 755 -d @prefix@/python/astra
+	./install-sh -m 644 ../../python/finalbuild/astra/*.so @prefix@/python/astra
+	./install-sh -m 644 ../../python/finalbuild/astra/*.py @prefix@/python/astra
+	./install-sh -m 644 ../../python/finalbuild/*.egg-info @prefix@/python/
+	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
+	@echo "To use ASTRA in Python, add @prefix@/python/ to your PYTHONPATH"
+	@echo "and @libdir@ to your LD_LIBRARY_PATH."
+	@echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
+# TODO: docs
+else
+install-python:
+endif
+
 
 Makefile: Makefile.in config.status
 	CONFIG_HEADERS= CONFIG_LINKS= CONFIG_FILES=$@ $(SHELL) ./config.status
diff --git a/build/linux/configure.ac b/build/linux/configure.ac
index f99c4d3..7ad03c3 100644
--- a/build/linux/configure.ac
+++ b/build/linux/configure.ac
@@ -1,26 +1,26 @@
 dnl -----------------------------------------------------------------------
 dnl Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp
 dnl            2014-2015, CWI, Amsterdam
-dnl 
+dnl
 dnl Contact: astra@uantwerpen.be
 dnl Website: http://sf.net/projects/astra-toolbox
-dnl 
+dnl
 dnl This file is part of the ASTRA Toolbox.
-dnl 
-dnl 
+dnl
+dnl
 dnl The ASTRA Toolbox is free software: you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
 dnl the Free Software Foundation, either version 3 of the License, or
 dnl (at your option) any later version.
-dnl 
+dnl
 dnl The ASTRA Toolbox is distributed in the hope that it will be useful,
 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 dnl GNU General Public License for more details.
-dnl 
+dnl
 dnl You should have received a copy of the GNU General Public License
 dnl along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
-dnl 
+dnl
 dnl -----------------------------------------------------------------------
 dnl $Id$
 
@@ -166,6 +166,23 @@ fi
 
 AC_SUBST(HAVEMATLAB)
 
+# python
+
+AC_ARG_WITH(python, [[  --with-python=path      path of Python (optional)]],,)
+
+PY_PATH=$PATH
+HAVEPYTHON=no
+if test x"$with_python" != x; then
+  PY_PATH="$with_python:$PY_PATH"
+  AC_PATH_PROG([PYTHON], [python], [no], [$PY_PATH])
+  if test x"$PYTHON" != xno; then
+    HAVEPYTHON=yes
+    AC_SUBST(PYTHON)
+  fi
+fi
+
+AC_SUBST(HAVEPYTHON)
+
 
 # TODO:
 
-- 
cgit v1.2.3


From 153b480b267a2d62e3b2d671d8018ab6e55dc8c4 Mon Sep 17 00:00:00 2001
From: "Daniel M. Pelt" <D.M.Pelt@cwi.nl>
Date: Tue, 24 Feb 2015 14:19:34 +0100
Subject: Better Python configure checks

---
 build/linux/configure.ac | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

(limited to 'build/linux')

diff --git a/build/linux/configure.ac b/build/linux/configure.ac
index f4cc82e..f9755f9 100644
--- a/build/linux/configure.ac
+++ b/build/linux/configure.ac
@@ -162,17 +162,34 @@ AC_SUBST(HAVEMATLAB)
 
 # python
 
-AC_ARG_WITH(python, [[  --with-python=path      path of Python (optional)]],,)
+AC_ARG_WITH(python, [[  --with-python=path      path of Python binary (optional)]],,)
 
-PY_PATH=$PATH
 HAVEPYTHON=no
 if test x"$with_python" != x; then
-  PY_PATH="$with_python:$PY_PATH"
-  AC_PATH_PROG([PYTHON], [python], [no], [$PY_PATH])
-  if test x"$PYTHON" != xno; then
-    HAVEPYTHON=yes
-    AC_SUBST(PYTHON)
+  AC_CHECK_FILE([$with_python],[PYTHON=$with_python],[AC_PATH_PROG([PYTHON], [$with_python], [AC_MSG_ERROR(Python binary not found)], [$PATH])])
+  HAVEPYTHON=yes
+  AC_SUBST(PYTHON)
+  AC_MSG_CHECKING(for numpy module)
+  echo "import numpy" | $PYTHON -
+  if test $? -ne 0 ; then
+    AC_MSG_RESULT(not found)
+    AC_MSG_ERROR(You need the numpy module to use the ASTRA toolbox in Python)
   fi
+  AC_MSG_RESULT(found)
+  AC_MSG_CHECKING(for Cython module)
+  echo "import Cython;from distutils.version import LooseVersion;assert(LooseVersion(Cython.__version__)>=LooseVersion('0.13'))" | $PYTHON -
+  if test $? -ne 0 ; then
+    AC_MSG_RESULT(not found)
+    AC_MSG_ERROR(You need the Cython module (version >=0.13) to use the ASTRA toolbox in Python)
+  fi
+  AC_MSG_RESULT(found)
+  AC_MSG_CHECKING(for six module)
+  echo "import six" | $PYTHON -
+  if test $? -ne 0 ; then
+    AC_MSG_RESULT(not found)
+    AC_MSG_ERROR(You need the six module to use the ASTRA toolbox in Python)
+  fi
+  AC_MSG_RESULT(found)
 fi
 
 AC_SUBST(HAVEPYTHON)
-- 
cgit v1.2.3


From 22f0c35dd2576b0121992ab09fe89e68c6532459 Mon Sep 17 00:00:00 2001
From: Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>
Date: Wed, 25 Feb 2015 10:48:59 +0100
Subject: Simplify with-python handling

---
 build/linux/configure.ac | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

(limited to 'build/linux')

diff --git a/build/linux/configure.ac b/build/linux/configure.ac
index f9755f9..525ca9d 100644
--- a/build/linux/configure.ac
+++ b/build/linux/configure.ac
@@ -165,8 +165,18 @@ AC_SUBST(HAVEMATLAB)
 AC_ARG_WITH(python, [[  --with-python=path      path of Python binary (optional)]],,)
 
 HAVEPYTHON=no
-if test x"$with_python" != x; then
-  AC_CHECK_FILE([$with_python],[PYTHON=$with_python],[AC_PATH_PROG([PYTHON], [$with_python], [AC_MSG_ERROR(Python binary not found)], [$PATH])])
+if test x"$with_python" != x -a x"$with_python" != xno; then
+  if test x"$with_python" = xyes; then
+    PYTHON=python
+  else
+    PYTHON="$with_python"
+  fi
+  AC_MSG_CHECKING(for python)
+  ASTRA_RUN_LOGOUTPUT(echo 'import sys' | $PYTHON -)
+  if test $? -ne 0; then
+    AC_MSG_ERROR(Python binary not found)]
+  fi
+  AC_MSG_RESULT([$PYTHON])
   HAVEPYTHON=yes
   AC_SUBST(PYTHON)
   AC_MSG_CHECKING(for numpy module)
@@ -215,6 +225,7 @@ echo
 echo "Summary of ASTRA Toolbox build options:"
 echo "  CUDA   : $HAVECUDA"
 echo "  Matlab : $HAVEMATLAB"
+echo "  Python : $HAVEPYTHON"
 echo
 echo "  prefix : $prefix"
 echo
-- 
cgit v1.2.3


From e0aca18f687e9f49223ffb24b9be354bed4b150a Mon Sep 17 00:00:00 2001
From: Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>
Date: Wed, 25 Feb 2015 10:49:08 +0100
Subject: Add logging for python module checks

---
 build/linux/acinclude.m4 | 12 ++++++++++++
 build/linux/configure.ac | 28 ++++++++++++++++------------
 2 files changed, 28 insertions(+), 12 deletions(-)

(limited to 'build/linux')

diff --git a/build/linux/acinclude.m4 b/build/linux/acinclude.m4
index 713b5d3..e4b6de7 100644
--- a/build/linux/acinclude.m4
+++ b/build/linux/acinclude.m4
@@ -70,6 +70,18 @@ AC_DEFUN([ASTRA_RUN_LOGOUTPUT],[{
  }])
 
 
+dnl ASTRA_TRY_PYTHON(code, action-if-ok, action-if-not-ok)
+AC_DEFUN([ASTRA_TRY_PYTHON],[
+cat >conftest.py <<_ACEOF
+$1
+_ACEOF
+ASTRA_RUN_LOGOUTPUT($PYTHON conftest.py)
+AS_IF([test $? = 0],[$2],[
+  AS_ECHO(["$as_me: failed program was:"]) >&AS_MESSAGE_LOG_FD
+  sed 's/^/| /' conftest.py >&AS_MESSAGE_LOG_FD
+  $3])
+])
+
 
 dnl ASTRA_CHECK_NVCC(variable-to-set,cppflags-to-set)
 AC_DEFUN([ASTRA_CHECK_NVCC],[
diff --git a/build/linux/configure.ac b/build/linux/configure.ac
index 525ca9d..b97a7a0 100644
--- a/build/linux/configure.ac
+++ b/build/linux/configure.ac
@@ -180,26 +180,30 @@ if test x"$with_python" != x -a x"$with_python" != xno; then
   HAVEPYTHON=yes
   AC_SUBST(PYTHON)
   AC_MSG_CHECKING(for numpy module)
-  echo "import numpy" | $PYTHON -
-  if test $? -ne 0 ; then
-    AC_MSG_RESULT(not found)
+  ASTRA_TRY_PYTHON([import numpy],,HAVEPYTHON=no)
+  if test x$HAVEPYTHON = xno; then
+    AC_MSG_RESULT(no)
     AC_MSG_ERROR(You need the numpy module to use the ASTRA toolbox in Python)
   fi
-  AC_MSG_RESULT(found)
+  AC_MSG_RESULT(yes)
   AC_MSG_CHECKING(for Cython module)
-  echo "import Cython;from distutils.version import LooseVersion;assert(LooseVersion(Cython.__version__)>=LooseVersion('0.13'))" | $PYTHON -
-  if test $? -ne 0 ; then
-    AC_MSG_RESULT(not found)
+  ASTRA_TRY_PYTHON([
+import Cython
+from distutils.version import LooseVersion
+assert(LooseVersion(Cython.__version__)>=LooseVersion("0.13"))
+],,HAVEPYTHON=no)
+  if test x$HAVEPYTHON = xno; then
+    AC_MSG_RESULT(no)
     AC_MSG_ERROR(You need the Cython module (version >=0.13) to use the ASTRA toolbox in Python)
   fi
-  AC_MSG_RESULT(found)
+  AC_MSG_RESULT(yes)
   AC_MSG_CHECKING(for six module)
-  echo "import six" | $PYTHON -
-  if test $? -ne 0 ; then
-    AC_MSG_RESULT(not found)
+  ASTRA_TRY_PYTHON([import six])
+  if test x$HAVEPYTHON = xno; then
+    AC_MSG_RESULT(no)
     AC_MSG_ERROR(You need the six module to use the ASTRA toolbox in Python)
   fi
-  AC_MSG_RESULT(found)
+  AC_MSG_RESULT(yes)
 fi
 
 AC_SUBST(HAVEPYTHON)
-- 
cgit v1.2.3