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.
--- 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