# HG changeset patch
# User Martin Albrecht <malb@informatik.uni-bremen.de>
# Date 1314631562 -3600
# Node ID 2498b66c3d46ecae81c02d1f39b0651391135778
# Parent  4313fad4ecad5c8045f4a7de3a4a4289e38c4bef
#11574 compile Sage extensions with SSE2 when needed by M4RI

diff -r 4313fad4ecad -r 2498b66c3d46 module_list.py
--- a/module_list.py	Mon May 30 17:11:13 2011 +0100
+++ b/module_list.py	Mon Aug 29 16:26:02 2011 +0100
@@ -58,10 +58,26 @@
 ginac_depends = [SAGE_INC + 'pynac/ginac.h']
 
 #########################################################
+### M4RI flags
+#########################################################
+
+import ast
+m4ri_have_sse2 = False
+for line in open(SAGE_INC + "m4ri/m4ri_config.h"):
+    if not line.startswith("#define __M4RI_HAVE_SSE2"):
+        continue
+    m4ri_have_sse2 = bool(ast.literal_eval(line[len("#define __M4RI_HAVE_SSE2"):].strip()))
+    break
+
+if m4ri_have_sse2:
+    m4ri_extra_compile_args = ['-msse', '-msse2']
+else:
+    m4ri_extra_compile_args = []
+
+#########################################################
 ### PolyBoRi defines
 #########################################################
 
-import ast
 polybori_extra_compile_args = []
 for line in open(SAGE_LOCAL + "/share/polybori/flags.conf"):
     if not line.startswith("CPPDEFINES"):
@@ -883,7 +899,8 @@
     # TODO -- change to use BLAS at some point.
     Extension('sage.matrix.matrix_integer_dense',
               sources = ['sage/matrix/matrix_integer_dense.pyx'],
-              extra_compile_args = ['-std=c99'],
+              extra_compile_args = ['-std=c99'] + m4ri_extra_compile_args,
+              depends = [SAGE_INC + 'm4ri/m4ri.h'],
               # order matters for cygwin!!
               libraries = ['iml', 'pari', 'm', 'gmp', BLAS, BLAS2]),
 
@@ -894,7 +911,7 @@
     Extension('sage.matrix.matrix_mod2_dense',
               sources = ['sage/matrix/matrix_mod2_dense.pyx'],
               libraries = ['gmp','m4ri', 'gd', 'png12', 'z'],
-              extra_compile_args = ['-std=c99'],
+              extra_compile_args = ['-std=c99'] + m4ri_extra_compile_args,
               depends = [SAGE_INC + "png.h", SAGE_INC + "m4ri/m4ri.h"]),
 
     Extension('sage.matrix.matrix_modn_dense',
@@ -1096,7 +1113,7 @@
     Extension('sage.modules.vector_mod2_dense',
               sources = ['sage/modules/vector_mod2_dense.pyx'],
               libraries = ['gmp','m4ri', 'png12', 'gd'],
-              extra_compile_args = ['-std=c99'],
+              extra_compile_args = ['-std=c99'] + m4ri_extra_compile_args,
               depends = [SAGE_INC + "png.h", SAGE_INC + "m4ri/m4ri.h"]),
     
     Extension('sage.modules.vector_rational_dense',
@@ -1479,7 +1496,9 @@
     Extension('sage.rings.polynomial.polynomial_gf2x',
               sources = ['sage/rings/polynomial/polynomial_gf2x.pyx'],
               libraries = ['ntl', 'stdc++', 'gmp'],
+              extra_compile_args = m4ri_extra_compile_args,
               language = 'c++',
+              depends = [SAGE_INC + 'm4ri/m4ri.h'],
               include_dirs = ['sage/libs/ntl/']),
 
     Extension('sage.rings.polynomial.polynomial_zz_pex',
@@ -1529,8 +1548,8 @@
                               SAGE_INC + 'polybori',
                               SAGE_INC + 'polybori/groebner',
                               "sage/libs/polybori"],
-              depends = [SAGE_INC + "polybori/polybori.h"],
-              extra_compile_args = polybori_extra_compile_args,
+              depends = [SAGE_INC + "polybori/polybori.h", SAGE_INC + 'm4ri/m4ri.h'],
+              extra_compile_args = polybori_extra_compile_args + m4ri_extra_compile_args,
               language = 'c++'),
 
     Extension('sage.rings.polynomial.polynomial_real_mpfr_dense',
