From 01be288b18ca993205166c363dd27d20e56f02ec Mon Sep 17 00:00:00 2001
From: Joerg Wunsch <j@uriah.heep.sax.de>
Date: Wed, 16 Nov 2022 21:21:51 +0100
Subject: [PATCH 1/3] Add fallback for EM_AVR

OpenBSD still lacks this definition, so provide our own for
them.
---
 src/fileio.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/fileio.c b/src/fileio.c
index e6d5c037..9c3313b2 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -37,6 +37,9 @@
 #ifndef EM_AVR32
 #  define EM_AVR32 0x18ad         /* unofficial */
 #endif
+#ifndef EM_AVR
+#  define EM_AVR 83               /* OpenBSD lacks it */
+#endif
 #endif
 
 #include "avrdude.h"

From 9df522a219c785f275a977574a8c983e78467ea5 Mon Sep 17 00:00:00 2001
From: Joerg Wunsch <j@uriah.heep.sax.de>
Date: Thu, 17 Nov 2022 14:14:22 +0100
Subject: [PATCH 2/3] Add <sys/select.h> where appropriate

Under Posix systems, this header is documented to be required
when using select().
---
 src/ser_posix.c | 1 +
 src/term.c      | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/src/ser_posix.c b/src/ser_posix.c
index 46f3aaa4..ecc25baf 100644
--- a/src/ser_posix.c
+++ b/src/ser_posix.c
@@ -36,6 +36,7 @@
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/time.h>
+#include <sys/select.h>
 #include <sys/socket.h>
 #include <netdb.h>
 
diff --git a/src/term.c b/src/term.c
index bd4e57b1..99f263c5 100644
--- a/src/term.c
+++ b/src/term.c
@@ -44,6 +44,8 @@
 
 #ifdef WIN32
 #include <windows.h>
+#else
+#include <sys/select.h>
 #endif
 #endif
 

From 908e6b15daedbd28b81a27d20d537a1e50dfec9a Mon Sep 17 00:00:00 2001
From: Joerg Wunsch <j@uriah.heep.sax.de>
Date: Thu, 17 Nov 2022 21:20:07 +0100
Subject: [PATCH 3/3] Add NetBSD and OpenBSD to the build script

---
 build.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/build.sh b/build.sh
index 08f0a7bf..110b6aa9 100755
--- a/build.sh
+++ b/build.sh
@@ -51,7 +51,7 @@ case "${ostype}" in
 	    build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/opt/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/opt/local/lib"
 	else
             # Apple M1 (may be new version of homebrew also)
-            if [ -d /opt/homebrew ]  
+            if [ -d /opt/homebrew ]
             then
                 build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/opt/homebrew/include -D CMAKE_EXE_LINKER_FLAGS=-L/opt/homebrew/Cellar -D HAVE_LIBREADLINE:FILEPATH=/opt/homebrew/opt/readline/lib/libreadline.dylib"
             else
@@ -60,7 +60,11 @@ case "${ostype}" in
 	fi
 	;;
 
-    freebsd)
+    netbsd)
+	build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/usr/pkg/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/pkg/lib"
+	;;
+
+    *bsd)
 	build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/usr/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/local/lib"
 	;;
 esac