From 60e8b9d7fb2c17b52b4903bddcaa0fdae0c30096 Mon Sep 17 00:00:00 2001
From: Chris PeBenito <pebenito@ieee.org>
Date: Fri, 11 Nov 2016 18:21:48 -0500
Subject: [PATCH] setup.py: Support locally-built libsepol.

Set the SEPOL_SRC env. variable to the path to the compiled libsepol
source tree.

Closes #138
---
 setup.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index 0549e5e..309e956 100644
--- a/setup.py
+++ b/setup.py
@@ -77,6 +77,15 @@ class BuildExtCommand(build_ext):
         build_ext.run(self)
 
 
+base_lib_dirs = ['.', '/usr/lib64', '/usr/lib']
+include_dirs = ['libqpol', 'libqpol/include']
+
+try:
+    base_lib_dirs.insert(0, os.environ["SEPOL_SRC"] + "/src")
+    include_dirs.append(os.environ["SEPOL_SRC"] + "/include")
+except KeyError:
+    pass
+
 try:
     static_sepol = os.environ['SEPOL']
 except KeyError:
@@ -84,7 +93,7 @@ except KeyError:
     # chooses dynamic libraries over static ones, so
     # this assumes that the static lib is in the same directory
     # as the dynamic lib.
-    dynamic_sepol = UnixCCompiler().find_library_file(['.', '/usr/lib64', '/usr/lib'], 'sepol')
+    dynamic_sepol = UnixCCompiler().find_library_file(base_lib_dirs, 'sepol')
 
     if dynamic_sepol is None:
         print('Unable to find a libsepol.so on your system!')
@@ -135,7 +144,7 @@ ext_py_mods = [Extension('setools.policyrep._qpol',
                           'libqpol/policy_parse.c',
                           'libqpol/policy_scan.c',
                           'libqpol/xen_query.c'],
-                         include_dirs=['libqpol', 'libqpol/include'],
+                         include_dirs=include_dirs,
                          extra_compile_args=['-Werror', '-Wextra',
                                              '-Waggregate-return',
                                              '-Wcast-align',