From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Date: Wed, 15 Apr 2020 17:19:09 -0400
Subject: Avoid trying to compile on debian 5.5 kernels (Closes: #956241)

zx2c4 and Unit193 and i discussed this at length in IRC and couldn't
find a better way to express to DKMS that building the kernel is not
needed for debian's 5.5.0 kernel, since it has wireguard backported.

Note that the detection trick that we're using (looking for
wireguard.h in /lib/modules/5.5*) is still fairly crude.

We want to ensure that people running other distributed kernels
(e.g. raspberry pi? liquorix?) can still use debian's wireguard-dkms
to install wireguard.ko on their particular flavor of 5.5.  But if
they are building for the debian 5.5.0-1-* kernels, they won't need
it.

This is a bit sloppy because it means if you have both 5.5 from some
non-stock line *and* the headers for debian's stock 5.5.0-1-amd64 (for
example) installed, it will probably cause dkms to avoid building
wireguard.ko on the custom kernel.  But we decided that corner case is
too obscure to make it worth making the test logic here more complex
and fiddly.

Suggestions welcome for making this tweak more accurate as long as it
doesn't become more fragile.
---
 src/dkms.conf | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/dkms.conf b/src/dkms.conf
index ce85da8..74ba498 100644
--- a/src/dkms.conf
+++ b/src/dkms.conf
@@ -5,5 +5,11 @@ AUTOINSTALL=yes
 BUILT_MODULE_NAME="wireguard"
 DEST_MODULE_LOCATION="/kernel/net"
 
-# requires kernel 3.10 - 5.5, inclusive:
-BUILD_EXCLUSIVE_KERNEL="^((5\.[0-5]($|[.-]))|(4\.)|(3\.1[0-9]))"
+
+if ls /lib/modules/5.5*/source/include/uapi/linux/wireguard.h >/dev/null 2>&1 ; then
+    # debian backported wireguard into the 5.5 release:
+    BUILD_EXCLUSIVE_KERNEL="^((5\.[0-4]($|[.-]))|(4\.)|(3\.1[0-9]))"
+else
+    # upstream requires kernel 3.10 - 5.5, inclusive:
+    BUILD_EXCLUSIVE_KERNEL="^((5\.[0-5]($|[.-]))|(4\.)|(3\.1[0-9]))"
+fi
