$OpenBSD: patch-setup_extensions_py,v 1.8 2014/07/08 09:55:16 sthen Exp $

- fix various header search paths
- don't override compiler optimizer levels
- build with libmtp/libusb1 on OpenBSD (possibly useless as it looks like it
also wants /sys/ access to actually detect devices..)

if updating patches, watch out for X11BASE -> /usr/X11R6 in last chunk,
and don't allow an updated patch to change the python shebang line,
it's correct with "env" here (handled in infrastructure).

--- setup/extensions.py.orig	Fri Jul  4 05:05:26 2014
+++ setup/extensions.py	Tue Jul  8 10:36:28 2014
@@ -12,7 +12,7 @@ from multiprocessing import cpu_count
 
 from PyQt4.pyqtconfig import QtGuiModuleMakefile
 
-from setup import Command, islinux, isbsd, isosx, SRC, iswindows
+from setup import Command, islinux, isbsd, isosx, SRC, iswindows, isopenbsd
 from setup.build_environment import (chmlib_inc_dirs,
         podofo_inc, podofo_lib, podofo_error, pyqt, OSX_SDK, NMAKE, QMAKE,
         msvc, MT, win_inc, win_lib, win_ddk, magick_inc_dirs, magick_lib_dirs,
@@ -46,13 +46,6 @@ class Extension(object):
         self.ldflags = kwargs.get('ldflags', [])
         self.optional = kwargs.get('optional', False)
         self.needs_ddk = kwargs.get('needs_ddk', False)
-        of = kwargs.get('optimize_level', None)
-        if of is None:
-            of = '/Ox' if iswindows else '-O3'
-        else:
-            flag = '/O%d' if iswindows else '-O%d'
-            of = flag % of
-        self.cflags.insert(0, of)
 
     def preflight(self, obj_dir, compiler, linker, builder, cflags, ldflags):
         pass
@@ -289,9 +282,10 @@ if isosx:
                 ldflags=['-framework', 'CoreServices', '-framework', 'IOKit'])
             )
 
-if islinux or isosx:
+if islinux or isosx or isopenbsd:
     extensions.append(Extension('libusb',
         ['calibre/devices/libusb/libusb.c'],
+        inc_dirs=[os.path.join(sysconfig.PREFIX, 'include')],
         libraries=['usb-1.0']
     ))
 
@@ -305,6 +299,7 @@ if islinux or isosx:
         'calibre/devices/mtp/unix/upstream/music-players.h',
         'calibre/devices/mtp/unix/upstream/device-flags.h',
         ],
+        inc_dirs=[os.path.join(sysconfig.PREFIX, 'include')],
         libraries=['mtp']
     ))
 
@@ -332,9 +327,9 @@ if isbsd:
     cflags.append('-pthread')
     ldflags.append('-shared')
     cflags.append('-I'+sysconfig.get_python_inc())
+    ldflags.append('-L'+os.path.join(sysconfig.PREFIX))
     ldflags.append('-lpython'+sysconfig.get_python_version())
 
-
 if isosx:
     x, p = ('i386', 'x86_64')
     archs = ['-arch', x, '-arch', p, '-isysroot',
@@ -541,7 +536,7 @@ class Build(Command):
         DESTDIR = .
         TARGET = calibre
         QT *= svg
-        INCLUDEPATH *= {conf} {inc}
+        INCLUDEPATH *= "${X11BASE}/include" {conf} {inc}
         win32-msvc*:DEFINES *= _CRT_SECURE_NO_WARNINGS
 
         # Force C++ language
