Commits

Jakub Wilk committed 017c919

setup: handle lack of pkg-config (or missing *.pc files) gracefully.

Comments (0)

Files changed (1)

 PKG_CONFIG_FLAG_MAP = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'}
 
 def pkg_config(*packages, **kwargs):
+    libdjvulibre = 'djvulibre'
+    if os.name == 'nt':
+        libdjvulibre = 'libdjvulibre'
+    fallback = dict(
+        libraries=[libdjvulibre],
+    )
     try:
         pkgconfig = ipc.Popen(
             ['pkg-config', '--libs', '--cflags'] + list(packages),
         )
     except OSError:
         _, ex, _ = sys.exc_info()
-        ex.strerror = 'pkg-config: ' + ex.strerror
-        raise
+        distutils.log.warn('cannot execute pkg-config: ' + str(ex))
+        return fallback
     stdout, stderr = pkgconfig.communicate()
     stdout = stdout.decode('ASCII', 'replace')
     stderr = stderr.decode('ASCII', 'replace')
     if pkgconfig.returncode:
-        raise IOError('[pkg-config] ' + stderr.strip())
+        distutils.log.warn('pkg-config failed: ' + stderr.strip())
+        return fallback
     kwargs.setdefault('extra_link_args', [])
     kwargs.setdefault('extra_compile_args', ['-Wno-uninitialized'])
     for argument in stdout.split():
             kwargs['extra_compile_args'].append(argument)
     return kwargs
 
-if mingw32cross:
-
-    def pkg_config(*packages, **kwargs):
-        return dict(
-            libraries=['libdjvulibre'],
-        )
-        return kwargs
-
 __version__ = get_version()
 
 # Work-around for <http://bugs.python.org/issue969718>:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.