From 17a0a2ee3eeb9df6e9fcf894d204911c7e6e4eef Mon Sep 17 00:00:00 2001
From: Andrew Murray <radarhere@users.noreply.github.com>
Date: Fri, 31 Mar 2023 06:14:35 +1100
Subject: [PATCH] Removed unnecessary silencing of stderr

---
 setup.py | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/setup.py b/setup.py
index 9f38170b564..07d6c66d655 100755
--- a/setup.py
+++ b/setup.py
@@ -273,9 +273,7 @@ def _pkg_config(name):
             )[::2][1:]
             cflags = re.split(
                 r"(^|\s+)-I",
-                subprocess.check_output(command_cflags, stderr=stderr)
-                .decode("utf8")
-                .strip(),
+                subprocess.check_output(command_cflags).decode("utf8").strip(),
             )[::2][1:]
             return libs, cflags
         except Exception:
From a0492f796876c2a9b8ba445d72c771b84eff93a5 Mon Sep 17 00:00:00 2001
From: Andrew Murray <radarhere@users.noreply.github.com>
Date: Sat, 28 Jan 2023 19:27:51 +1100
Subject: [PATCH] Ensure that pkg-config paths are split by spaces

---
 setup.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/setup.py b/setup.py
index b4ebbb9c26e..4382c1a97ab 100755
--- a/setup.py
+++ b/setup.py
@@ -264,19 +264,17 @@ def _pkg_config(name):
                 command_libs.append("--silence-errors")
                 command_cflags.append("--silence-errors")
             libs = re.split(
-                r"\s*-L",
+                r"(^|\s+)-L",
                 subprocess.check_output(command_libs, stderr=stderr)
                 .decode("utf8")
                 .strip(),
-            )
-            libs.remove("")
+            )[::2][1:]
             cflags = re.split(
-                r"\s*-I",
+                r"(^|\s+)-I",
                 subprocess.check_output(command_cflags, stderr=stderr)
                 .decode("utf8")
                 .strip(),
-            )
-            cflags.remove("")
+            )[::2][1:]
             return libs, cflags
         except Exception:
             pass
From 04cf5e2cfc5dc1676efd9f5c8d605ddfccb0f9ee Mon Sep 17 00:00:00 2001
From: Bas Couwenberg <sebastic@xs4all.nl>
Date: Sat, 14 Jan 2023 19:09:43 +0100
Subject: [PATCH] Handle more than one directory returned by pkg-config.

tiff (4.5.0-1) in Debian results in two include directories being returned:
```
-I/usr/include/x86_64-linux-gnu -I/usr/include
```
---
 setup.py | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/setup.py b/setup.py
index 24336568199..b4ebbb9c26e 100755
--- a/setup.py
+++ b/setup.py
@@ -263,18 +263,20 @@ def _pkg_config(name):
             if not DEBUG:
                 command_libs.append("--silence-errors")
                 command_cflags.append("--silence-errors")
-            libs = (
+            libs = re.split(
+                r"\s*-L",
                 subprocess.check_output(command_libs, stderr=stderr)
                 .decode("utf8")
-                .strip()
-                .replace("-L", "")
+                .strip(),
             )
-            cflags = (
-                subprocess.check_output(command_cflags)
+            libs.remove("")
+            cflags = re.split(
+                r"\s*-I",
+                subprocess.check_output(command_cflags, stderr=stderr)
                 .decode("utf8")
-                .strip()
-                .replace("-I", "")
+                .strip(),
             )
+            cflags.remove("")
             return libs, cflags
         except Exception:
             pass
@@ -473,8 +475,12 @@ def build_extensions(self):
             else:
                 lib_root = include_root = root
 
-            _add_directory(library_dirs, lib_root)
-            _add_directory(include_dirs, include_root)
+            if lib_root is not None:
+                for lib_dir in lib_root:
+                    _add_directory(library_dirs, lib_dir)
+            if include_root is not None:
+                for include_dir in include_root:
+                    _add_directory(include_dirs, include_dir)
 
         # respect CFLAGS/CPPFLAGS/LDFLAGS
         for k in ("CFLAGS", "CPPFLAGS", "LDFLAGS"):
