From: Carlos Maddela <e7appew@gmail.com>
Date: Sun, 6 Aug 2017 10:37:18 +1000
Subject: Add better support for HURD and kFreeBSD systems.

Description: Add better support for HURD and kFreeBSD systems.
 Hurd still compiles without SCSI layer, however.
Author: Carlos Maddela <e7appew@gmail.com>
Last-Update: 2017-08-06
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
---
 cacheprobe.c                 | 16 +++++++++-------
 closure.c                    |  6 ++++--
 scripts/bash-based-configure | 18 ++++++++++++++++++
 scsi-freebsd.c               |  4 ++--
 scsi-layer.c                 | 10 ++++++----
 scsi-layer.h                 | 17 +++++++++--------
 scsi-unknown.c               |  4 ++--
 show-html.c                  | 15 ++++++++++-----
 8 files changed, 60 insertions(+), 30 deletions(-)

diff --git a/cacheprobe.c b/cacheprobe.c
index 545c690..9f754dd 100644
--- a/cacheprobe.c
+++ b/cacheprobe.c
@@ -22,7 +22,8 @@
 
 #include "dvdisaster.h"
 
-#ifdef SYS_LINUX
+#if defined(SYS_LINUX)
+
 int ProbeCacheLineSize()
 {  int cl_size = 0;
 
@@ -36,9 +37,9 @@ int ProbeCacheLineSize()
 
    return cl_size;
 }
-#endif
 
-#ifdef SYS_FREEBSD
+#elif defined(SYS_FREEBSD) || defined(SYS_KFREEBSD)
+
 #include <sys/param.h>
 
 int ProbeCacheLineSize()
@@ -52,9 +53,9 @@ int ProbeCacheLineSize()
 
    return cl_size;
 }
-#endif
 
-#ifdef SYS_NETBSD
+#elif defined(SYS_NETBSD)
+
 #include <sys/param.h>
 
 int ProbeCacheLineSize()
@@ -68,13 +69,14 @@ int ProbeCacheLineSize()
 
    return cl_size;
 }
-#endif
 
-#ifdef SYS_UNKNOWN
+#else /* SYS_UNKNOWN and others. */
+
 int ProbeCacheLineSize()
 {
   return 64;
 }
+
 #endif
 
 
diff --git a/closure.c b/closure.c
index 24c1e8c..26ee13b 100644
--- a/closure.c
+++ b/closure.c
@@ -50,7 +50,8 @@ static void get_base_dirs()
    /*** Otherwise try the installation directory. 
 	On Unices this is a hardcoded directory. */
 
-#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_NETBSD) || defined(SYS_UNKNOWN)
+#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_KFREEBSD) || \
+    defined(SYS_NETBSD) || defined(SYS_HURD) || defined(SYS_UNKNOWN)
    if(DirStat(BINDIR))
      Closure->binDir = g_strdup(BINDIR);
 
@@ -432,7 +433,8 @@ void InitClosure()
 
    /* Generate a more comprehensive version string */
 
-#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_NETBSD)
+#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_KFREEBSD) || \
+    defined(SYS_NETBSD) || defined(SYS_HURD)
   #ifdef HAVE_64BIT
     #define BITNESS_STRING " 64bit"
   #else
diff --git a/scripts/bash-based-configure b/scripts/bash-based-configure
index f1a8bd1..487a50b 100644
--- a/scripts/bash-based-configure
+++ b/scripts/bash-based-configure
@@ -136,6 +136,15 @@ case "$cfg_uname" in
 	}
 	;;
 
+  GNU/kFreeBSD*) cfg_system=kfreebsd
+	CFG_SYS_OPTIONS="-DSYS_KFREEBSD"
+	CFG_SYS_NAME="-DSYS_NAME=\\\"GNU/kFreeBSD\\\""
+	CFG_EXE_SUFFIX=""
+	function add_linker_flags()
+	{  lflags_return="-L$1 -Wl,-rpath,$1 $2"
+	}
+	;;
+
   NetBSD*) cfg_system=netbsd
         CFG_SYS_OPTIONS="-DSYS_NETBSD"
 	CFG_SYS_NAME="-DSYS_NAME=\\\"NetBSD\\\""
@@ -146,6 +155,15 @@ case "$cfg_uname" in
 	}
 	;;
 
+  GNU*) cfg_system=hurd
+	CFG_SYS_OPTIONS="-DSYS_HURD"
+	CFG_SYS_NAME="-DSYS_NAME=\\\"GNU/Hurd\\\""
+	CFG_EXE_SUFFIX=""
+	function add_linker_flags()
+	{  lflags_return="-L$1 -Wl,-rpath,$1 $2"
+	}
+	;;
+
   *) cfg_system=unknown-system
         CFG_SYS_OPTIONS="-DSYS_UNKNOWN"
 	CFG_SYS_NAME="-DSYS_NAME=\\\"Unknown\\\""
diff --git a/scsi-freebsd.c b/scsi-freebsd.c
index 0e3397a..bbfb913 100644
--- a/scsi-freebsd.c
+++ b/scsi-freebsd.c
@@ -25,7 +25,7 @@
 #include "scsi-layer.h"
 #include "udf.h"
 
-#ifdef SYS_FREEBSD
+#if defined(SYS_FREEBSD) || defined(SYS_KFREEBSD)
 
 /* SCSI wrappers for FreeBSD are still work in progress. */
 
@@ -241,4 +241,4 @@ int SendPacket(DeviceHandle *dh, unsigned char *cmd, int cdb_size, unsigned char
    return -1;
 }
 
-#endif /* SYS_FREEBSD */
+#endif /* defined(SYS_FREEBSD) || defined(SYS_KFREEBSD) */
diff --git a/scsi-layer.c b/scsi-layer.c
index 22e825d..eaecc5c 100644
--- a/scsi-layer.c
+++ b/scsi-layer.c
@@ -2005,12 +2005,13 @@ static gint64 query_size(Image *image)
  */
 
 gint64 CurrentMediumSize(int get_blank_size)
-{  Image *image;
+{
+#if defined(SYS_UNKNOWN) || defined(SYS_HURD)
+   return 0;
+#else
+   Image *image;
    gint64 size;
 
-#ifdef SYS_UNKNOWN
-   return 0;
-#endif
 
    image = OpenImageFromDevice(Closure->device);
    if(!image) return 0;
@@ -2051,6 +2052,7 @@ gint64 CurrentMediumSize(int get_blank_size)
    CloseImage(image);
 
    return size;
+#endif
 }
 
 /***
diff --git a/scsi-layer.h b/scsi-layer.h
index cb5c559..6169508 100644
--- a/scsi-layer.h
+++ b/scsi-layer.h
@@ -28,7 +28,7 @@
 #include <linux/cdrom.h>
 #endif
 
-#ifdef SYS_FREEBSD
+#if defined(SYS_FREEBSD) || defined(SYS_KFREEBSD)
 #include <camlib.h>
 #endif
 
@@ -49,19 +49,21 @@
  * Linux already has one 
  */
 
-#ifdef SYS_LINUX
+#if defined(SYS_LINUX)
+
 #define MAX_CDB_SIZE CDROM_PACKET_SIZE
 
 /* Now globally defined for all OSes here */
 //typedef struct request_sense Sense;
-#endif
 
-#ifdef SYS_FREEBSD
+#elif defined(SYS_FREEBSD) || defined(SYS_KFREEBSD)
+
 #define MAX_CDB_SIZE SCSI_MAX_CDBLEN
-#endif
 
-#if defined(SYS_UNKNOWN) || defined(SYS_NETBSD)
+#else /* SYS_UNKNOWN and others. */
+
 #define MAX_CDB_SIZE 16   /* longest possible SCSI command */
+
 #endif
 
 /* 
@@ -101,8 +103,7 @@ typedef struct _DeviceHandle
     */
 #if defined(SYS_LINUX) || defined(SYS_NETBSD)
    int fd;                    /* device file descriptor */
-#endif
-#ifdef SYS_FREEBSD
+#elif defined(SYS_FREEBSD) || defined(SYS_KFREEBSD)
    struct cam_device *camdev; /* camlib device handle */
    union ccb *ccb;
 #endif
diff --git a/scsi-unknown.c b/scsi-unknown.c
index f5f1072..7b2ccdb 100644
--- a/scsi-unknown.c
+++ b/scsi-unknown.c
@@ -25,7 +25,7 @@
 #include "scsi-layer.h"
 #include "udf.h"
 
-#ifdef SYS_UNKNOWN
+#if defined(SYS_UNKNOWN) || defined(SYS_HURD)
 
 /* Dummy routines so that we can compile on unknown architectures
    for which we don't have SCSI support yet. */
@@ -51,4 +51,4 @@ int SendPacket(DeviceHandle *dh, unsigned char *cmd, int cdb_size, unsigned char
    return -1;
 }
 
-#endif /* SYS_UNKNOWN */
+#endif /* defined(SYS_UNKNOWN) || defined(SYS_HURD) */
diff --git a/show-html.c b/show-html.c
index 608e8ec..20715f4 100644
--- a/show-html.c
+++ b/show-html.c
@@ -21,7 +21,8 @@
 
 #include "dvdisaster.h"
 
-#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_NETBSD)
+#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_KFREEBSD) || \
+    defined(SYS_NETBSD) || defined(SYS_HURD)
 #include <sys/wait.h>
 #endif
 
@@ -34,7 +35,8 @@
  *** Ask user to specify his browser
  ***/
 
-#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_NETBSD)
+#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_KFREEBSD) || \
+    defined(SYS_NETBSD) || defined(SYS_HURD)
 
 #define SEARCH_BUTTON 1
 
@@ -173,7 +175,8 @@ static void msg_destroy_cb(GtkWidget *widget, gpointer data)
    bi->msg = NULL; 
 }
 
-#if defined(SYS_LINUX) || defined(SYS_FREEBSD) ||  defined(SYS_NETBSD)
+#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_KFREEBSD) || \
+    defined(SYS_NETBSD) || defined(SYS_HURD)
 
 /* 
  * The following list of browsers and html wrappers
@@ -273,7 +276,8 @@ static gboolean browser_timeout_func(gpointer data)
  * Invoke the browser
  */
 
-#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_NETBSD)
+#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_KFREEBSD) || \
+    defined(SYS_NETBSD) || defined(SYS_HURD)
 static void try_browser(browser_info *bi)
 {  pid_t pid;
 
@@ -393,7 +397,8 @@ void ShowHTML(char *target)
    g_timeout_add(1000, browser_timeout_func, (gpointer)bi);
 #endif
 
-#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_NETBSD)
+#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_KFREEBSD) || \
+    defined(SYS_NETBSD) || defined(SYS_HURD)
    /* Try the first browser */
 
    browser_index = 0;
