Description: autotoolization/pytoolization: harden: build directory
 Attempt to harden the building machinery by (1) implementing a more
 autotools way to perform external build, by (2) distinguishing the
 build directory wrt to the PARI/GP support, and (3) by adding the
 possibily to pass arguments to `configure' through a dedicated
 environment variable, named `PYSETUP_CONFIGURE_FLAGS'. Meant to be
 submitted to the upstream maintainer team.
Origin: vendor, Debian
Forwarded: https://github.com/sagemath/cysignals/pull/38
Author: Jerome Benoit <calculus@rezozer.net>
Last-Update: 2016-11-02

--- a/setup.py
+++ b/setup.py
@@ -16,10 +16,7 @@
 
 opj = os.path.join
 
-
-cythonize_dir = "build"
-
-ac_configure_flags = ""
+ac_configure_flags = os.environ.get("PYSETUP_CONFIGURE_FLAGS","--without-pari")
 if "--without-pari" in sys.argv:
 	ac_configure_flags = "--without-pari"
 	sys.argv.remove("--without-pari")
@@ -27,6 +24,11 @@
 	ac_configure_flags = "--with-pari"
 	sys.argv.remove("--with-pari")
 
+cythonize_dir = "build/XXXX"
+if "--without-pari" in ac_configure_flags:
+	cythonize_dir = "build/bare"
+elif "--with-pari" in ac_configure_flags:
+	cythonize_dir = "build/pari"
 
 kwds = dict(include_dirs=[opj("src", "cysignals"),
                           opj(cythonize_dir, "src"),
@@ -146,8 +148,11 @@
             f = open(configure_init_pxd_file, "r")
         except IOError:
             import subprocess
-            subprocess.check_call(["make", "configure"])
-            subprocess.check_call(["sh", "configure" + ac_configure_flags ])
+            subprocess.check_call(
+                "make configure && mkdir -p " + cythonize_dir +
+                " && " +
+                "{ cd " + cythonize_dir + " ; ../../configure " + ac_configure_flags + " ; }" ,
+              shell=True)
             f = open(configure_init_pxd_file, "r")
         with f:
             return f.read()
--- a/configure.ac
+++ b/configure.ac
@@ -7,7 +7,7 @@
 AC_INIT([cysignals], VERSION, [https://github.com/sagemath/cysignals/issues])
 AC_COPYRIGHT([GNU Lesser General Public License version 3 or later])
 AC_CONFIG_SRCDIR([configure.ac])
-AC_CONFIG_HEADERS([build/src/config.h:src/config.h.in build/src/cysignals/debug.h:src/cysignals/debug.h.in])
+AC_CONFIG_HEADERS([src/config.h src/cysignals/debug.h])
 
 AC_ARG_ENABLE(debug,
         AS_HELP_STRING([--enable-debug], [enable debug output]))
@@ -38,11 +38,11 @@
 )
 
 
-AC_CONFIG_COMMANDS([build/src/cysignals/__init__.pxd],
+AC_CONFIG_COMMANDS([src/cysignals/__init__.pxd],
     # Generate a file __init__.pxd to set correct compiler options.
     [[
-			echo "# distutils: extra_compile_args = $EXTRACOMPILEARGS" > build/src/cysignals/__init__.pxd
-			echo "# distutils: extra_link_args = $EXTRALINKARGS" >> build/src/cysignals/__init__.pxd
+			echo "# distutils: extra_compile_args = $EXTRACOMPILEARGS" > src/cysignals/__init__.pxd
+			echo "# distutils: extra_link_args = $EXTRALINKARGS" >> src/cysignals/__init__.pxd
 		]],
     [
 			EXTRACOMPILEARGS="$PARI_CPPFLAGS $PARI_CFLAGS"
