# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1252420417 -7200
#      Tue Sep 08 16:33:37 2009 +0200
# Node ID 734a8a5abf98d9c17359382fa4b33168a1c37624
# Parent  42004883d4cd6b42f7898a93df8537d5b87a662d
fix gecode version detection

diff --git a/MANIFEST.in b/MANIFEST.in
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -11,5 +11,6 @@
 include TODO 
 include ChangeLog
 include DEPENDS
+include data/gecode_version.cc
 
 recursive-include tools *.py *.rql
diff --git a/__pkginfo__.py b/__pkginfo__.py
--- a/__pkginfo__.py
+++ b/__pkginfo__.py
@@ -32,11 +32,32 @@
 pyversions = ['2.4']
 
 
+import os, subprocess
 from distutils.core import Extension
 
 include_dirs = []
 
-ext_modules = [ Extension('rql_solve',
-                          ['gecode_solver.cpp'],
-                          libraries=['gecodeint', 'gecodekernel', 'gecodesearch'],
-                          ) ]
+def gecode_version():
+    import os, subprocess
+    version = [0,0,0]
+    if os.path.exists('data/gecode_version.cc'):
+        try:
+            res = os.system("g++ -o gecode_version data/gecode_version.cc")
+            p = subprocess.Popen("./gecode_version",stdout=subprocess.PIPE)
+            vers = p.stdout.read()
+            version = [int(c) for c in vers.strip().split('.')]
+        except OSError:
+            pass
+    return version
+
+def encode_version(a,b,c):
+    return ((a<<16)+(b<<8)+c)
+
+GECODE_VERSION = encode_version(*gecode_version())
+
+ext_modules = [Extension('rql_solve',
+                         ['gecode_solver.cpp'],
+                         libraries=['gecodeint', 'gecodekernel', 'gecodesearch'],
+                         extra_compile_args=['-DGE_VERSION=%s' % GECODE_VERSION],
+                         )
+               ]
diff --git a/data/gecode_version.cc b/data/gecode_version.cc
new file mode 100644
--- /dev/null
+++ b/data/gecode_version.cc
@@ -0,0 +1,10 @@
+#include "gecode/support.hh"
+#include <stdio.h>
+
+int main() {
+#ifndef GECODE_VERSION
+    printf("2.1.2\n");
+#else
+    printf("%s\n", GECODE_VERSION);
+#endif
+}