From 7c1e6f0443cb36fa14d00a0797065710fbcc70cf Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Wed, 2 Nov 2011 21:39:24 +0100
Subject: [PATCH] Move python-related files to a subdir

Fix search path for modules as well
---
 configure.ac                     |  1 +
 src/Makefile.am                  | 13 +++----------
 src/python/Makefile.am           | 23 +++++++++++++++++++++++
 src/{ => python}/nicefunction.py |  0
 src/{ => python}/test-python.cc  | 10 ++++++++--
 5 files changed, 35 insertions(+), 12 deletions(-)
 create mode 100644 src/python/Makefile.am
 rename src/{ => python}/nicefunction.py (100%)
 rename src/{ => python}/test-python.cc (79%)

diff --git a/configure.ac b/configure.ac
index effbc6d5..709f18f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,6 +21,7 @@ AC_CONFIG_FILES([
   Makefile
   src/Makefile
   src/octave/Makefile
+  src/python/Makefile
   doc/Makefile
   doc/doxygen/Makefile
   doc/doxygen/Doxyfile
diff --git a/src/Makefile.am b/src/Makefile.am
index 1a32ffaa..afb99399 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,6 @@
 SUBDIRS = octave
 
 check_PROGRAMS = \
-	test-python \
 	test-gradient-method
 
 bin_PROGRAMS = \
@@ -14,13 +13,10 @@ run-one-body-sample: one-body-sample
 one_body_sample_SOURCES = \
 	one-body-sample.cc
 
-test_python_SOURCES = \
-	test-python.cc
-
 test_gradient_method_SOURCES = \
 	test-gradient-method.cc
 
-TESTS= test-python test-gradient-method
+TESTS= test-gradient-method
 
 # Some are for clang, others are for gcc
 AM_CXXFLAGS = \
@@ -38,7 +34,6 @@ AM_CXXFLAGS = \
 AM_CPPFLAGS = \
 	$(DUNE_CPPFLAGS) \
 	$(ALUGRID_CPPFLAGS) \
-	$(PYTHON_CPPFLAGS) \
 	-I$(top_srcdir)
 
 # The libraries have to be given in reverse order (most basic libraries
@@ -47,12 +42,10 @@ AM_CPPFLAGS = \
 # here as well.
 LDADD = \
 	$(DUNE_LDFLAGS) $(DUNE_LIBS) \
-	$(ALUGRID_LDFLAGS) $(ALUGRID_LIBS) \
-	$(PYTHON_LIBS)
+	$(ALUGRID_LDFLAGS) $(ALUGRID_LIBS)
 AM_LDFLAGS = \
 	$(ALUGRID_LDFLAGS) \
-	$(DUNE_LDFLAGS) \
-	$(PYTHON_LDFLAGS)
+	$(DUNE_LDFLAGS)
 
 # don't follow the full GNU-standard
 # we need automake 1.5
diff --git a/src/python/Makefile.am b/src/python/Makefile.am
new file mode 100644
index 00000000..b1410531
--- /dev/null
+++ b/src/python/Makefile.am
@@ -0,0 +1,23 @@
+SUBDIRS =
+
+check_PROGRAMS = \
+	test-python
+
+TESTS = test-python
+
+test_python_SOURCES = \
+	test-python.cc
+test_python_CPPFLAGS= \
+	$(AM_CPPFLAGS) -DDUNE_NICE_FUNCTION_MODULE_PATH="\"$(srcdir)\""
+
+AM_CPPFLAGS = \
+	$(DUNE_CPPFLAGS) \
+	$(PYTHON_CPPFLAGS) \
+	-I$(top_srcdir)
+
+LDADD = \
+	$(DUNE_LDFLAGS) $(DUNE_LIBS) \
+	$(PYTHON_LIBS)
+AM_LDFLAGS = \
+	$(DUNE_LDFLAGS) \
+	$(PYTHON_LDFLAGS)
diff --git a/src/nicefunction.py b/src/python/nicefunction.py
similarity index 100%
rename from src/nicefunction.py
rename to src/python/nicefunction.py
diff --git a/src/test-python.cc b/src/python/test-python.cc
similarity index 79%
rename from src/test-python.cc
rename to src/python/test-python.cc
index 28a3658a..75f4c5eb 100644
--- a/src/test-python.cc
+++ b/src/python/test-python.cc
@@ -4,6 +4,10 @@
 #include "config.h"
 #endif
 
+#ifndef DUNE_NICE_FUNCTION_MODULE_PATH
+#error DUNE_NICE_FUNCTION_MODULE_PATH unset
+#endif
+
 #ifndef HAVE_PYTHON
 #error Python is necessary
 #else
@@ -27,8 +31,10 @@ int main() {
     Python::start();
 
     Python::run("import sys");
-    Python::run(
-        "sys.path.append('../../src')"); // FIXME: use path to source here
+    std::string importString("sys.path.append('");
+    importString += DUNE_NICE_FUNCTION_MODULE_PATH;
+    importString += "')";
+    Python::run(importString.c_str());
 
     Python::Reference module = Python::import("nicefunction");
     Python::Reference funcRef = module.get("Functions");
-- 
GitLab