setup.py: skip inotify if there's no inotify_add_watch
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Thu, 13 Mar 2008 19:50:03 -0300
changeset 6245 0d0939b2d272
parent 6244 b36774d0fce1
child 6246 35bf9c23e17a
setup.py: skip inotify if there's no inotify_add_watch Debian Etch doesn't include a sys/inotify.h header, which makes it impossible to compile _inotify.c, making hg uninstallable. The cc.has_function() method is implemented by trying to compile a simple C program. Since there's no redirection involved all error messages are sent to the terminal. This is not particularly pretty but at least it allows the installation to complete.
setup.py
--- a/setup.py	Thu Mar 13 17:39:30 2008 +0100
+++ b/setup.py	Thu Mar 13 19:50:03 2008 -0300
@@ -12,6 +12,7 @@
 import os
 from distutils.core import setup, Extension
 from distutils.command.install_data import install_data
+from distutils.ccompiler import new_compiler
 
 import mercurial.version
 
@@ -66,10 +67,13 @@
     ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
 
     if sys.platform == 'linux2' and os.uname()[2] > '2.6':
-        # the inotify extension is only usable with Linux 2.6 kernels
-        ext_modules.append(Extension('hgext.inotify.linux._inotify',
-                                     ['hgext/inotify/linux/_inotify.c']))
-        packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
+        # The inotify extension is only usable with Linux 2.6 kernels.
+        # You also need a reasonably recent C library.
+        cc = new_compiler()
+        if cc.has_function('inotify_add_watch'):
+            ext_modules.append(Extension('hgext.inotify.linux._inotify',
+                                         ['hgext/inotify/linux/_inotify.c']))
+            packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
 except ImportError:
     pass