debian: Link against libfreebsd-glue on kfreebsd

cpuset_getaffinity() is available on kfreebsd but not in libc but in
libfreebsd-glue. This code adds the library if kfreebsd is detected so
cpuset_getaffinity() can be used.

Without this, tuklib_cpucores will detect `cpuset' because the compile
test succeeds and later it fails at link phase.

[jrnieder@gmail.com: imported from uploaded NMU]
diff --git a/configure.ac b/configure.ac
index d17629e..9697fbd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,6 +39,13 @@
 esac
 AM_CONDITIONAL([COND_W32], [test "$is_w32" = yes])
 
+# We need -lfreebsd-glue on kfreebsd
+case $host_os in
+	kfreebsd*-gnu* ) is_kfreebsd=yes ;;
+	*)               is_kfreebsd=no ;;
+esac
+AM_CONDITIONAL([COND_NEED_FREEBSD_GLUE], [test "$is_kfreebsd" = yes])
+
 # We need to use $EXEEXT with $(LN_S) when creating symlinks to
 # executables. Cygwin is an exception to this, since it is recommended
 # that symlinks don't have the .exe suffix. To make this work, we
diff --git a/debian/.git-dpm b/debian/.git-dpm
index 6dcce22..9c1d147 100644
--- a/debian/.git-dpm
+++ b/debian/.git-dpm
@@ -1,6 +1,6 @@
 # see git-dpm(1) from git-dpm package
-e284cfe27457239e932038fb90084c91f4229c36
-e284cfe27457239e932038fb90084c91f4229c36
+c49e1b3c33488a05467d754dc574b284578533ed
+c49e1b3c33488a05467d754dc574b284578533ed
 141d36d7861b6e8522c213194d5fba1e47af63e9
 141d36d7861b6e8522c213194d5fba1e47af63e9
 xz-utils_5.2.2.orig.tar.xz
diff --git a/debian/changelog b/debian/changelog
index 15e6f53..06a85b5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+xz-utils (5.2.2-1.2) unstable; urgency=medium
+
+  * Non-maintainer upload.
+  * link against libfreebsd-glue on kfreebsd-* (Closes: #840063)
+
+ -- Sebastian Andrzej Siewior <sebastian@breakpoint.cc>  Sat, 08 Oct 2016 15:11:19 +0200
+
 xz-utils (5.2.2-1.1) unstable; urgency=medium
 
   * Non-maintainer upload.
diff --git a/debian/control b/debian/control
index a7da7ac..7e91b73 100644
--- a/debian/control
+++ b/debian/control
@@ -5,7 +5,7 @@
 Uploaders: Mohammed Adnène Trojette <adn+deb@diwi.org>
 Build-Depends: debhelper (>= 8.9.0), dpkg-dev (>= 1.16.2),
  autoconf (>= 2.64~), automake, libtool (>= 2.2),
- gettext, autopoint | gettext (<< 0.18-1), autopoint | cvs
+ gettext, autopoint | gettext (<< 0.18-1), autopoint | cvs, freebsd-glue [kfreebsd-any]
 Build-Depends-Indep: doxygen
 Build-Conflicts: automake1.4
 Standards-Version: 3.9.3
diff --git a/debian/patches/kfreebsd-link-against-libfreebsd-glue.patch b/debian/patches/kfreebsd-link-against-libfreebsd-glue.patch
new file mode 100644
index 0000000..0733b3d
--- /dev/null
+++ b/debian/patches/kfreebsd-link-against-libfreebsd-glue.patch
@@ -0,0 +1,51 @@
+From c49e1b3c33488a05467d754dc574b284578533ed Mon Sep 17 00:00:00 2001
+From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
+Date: Sat, 8 Oct 2016 14:55:42 +0200
+Subject: kfreebsd: link against libfreebsd-glue
+
+cpuset_getaffinity() is available on kfreebsd but not in libc but in
+libfreebsd-glue. This code adds the library if kfreebsd is detected so
+cpuset_getaffinity() can be used.
+Without it tuklib_cpucores will detect `cpuset' because the compile test
+succeeds and later it fails at link phase.
+
+Patch-Name: kfreebsd-link-against-libfreebsd-glue.patch
+Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
+---
+ configure.ac            | 7 +++++++
+ src/liblzma/Makefile.am | 4 ++++
+ 2 files changed, 11 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index d17629e0e7f6..9697fbd9ab7b 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -39,6 +39,13 @@ case $host_os in
+ esac
+ AM_CONDITIONAL([COND_W32], [test "$is_w32" = yes])
+ 
++# We need -lfreebsd-glue on kfreebsd
++case $host_os in
++	kfreebsd*-gnu* ) is_kfreebsd=yes ;;
++	*)               is_kfreebsd=no ;;
++esac
++AM_CONDITIONAL([COND_NEED_FREEBSD_GLUE], [test "$is_kfreebsd" = yes])
++
+ # We need to use $EXEEXT with $(LN_S) when creating symlinks to
+ # executables. Cygwin is an exception to this, since it is recommended
+ # that symlinks don't have the .exe suffix. To make this work, we
+diff --git a/src/liblzma/Makefile.am b/src/liblzma/Makefile.am
+index 24d9c261233e..13624d08798c 100644
+--- a/src/liblzma/Makefile.am
++++ b/src/liblzma/Makefile.am
+@@ -32,6 +32,10 @@ liblzma_la_LDFLAGS += \
+ 	-Wl,--version-script=$(top_srcdir)/src/liblzma/liblzma.map
+ endif
+ 
++if COND_NEED_FREEBSD_GLUE
++liblzma_la_LDFLAGS += -lfreebsd-glue
++endif
++
+ liblzma_la_SOURCES += ../common/tuklib_physmem.c
+ 
+ if COND_THREADS
diff --git a/debian/patches/series b/debian/patches/series
index b37018b..2236e2a 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,3 @@
 liblzma-skip-ABI-incompatible-check-when-liblzma.so.patch
 liblzma-make-dlopen-based-liblzma2-compatibility-opt.patch
+kfreebsd-link-against-libfreebsd-glue.patch
diff --git a/src/liblzma/Makefile.am b/src/liblzma/Makefile.am
index 24d9c26..13624d0 100644
--- a/src/liblzma/Makefile.am
+++ b/src/liblzma/Makefile.am
@@ -32,6 +32,10 @@
 	-Wl,--version-script=$(top_srcdir)/src/liblzma/liblzma.map
 endif
 
+if COND_NEED_FREEBSD_GLUE
+liblzma_la_LDFLAGS += -lfreebsd-glue
+endif
+
 liblzma_la_SOURCES += ../common/tuklib_physmem.c
 
 if COND_THREADS