$OpenBSD$

Index: kernel/yosys.cc
--- kernel/yosys.cc.orig
+++ kernel/yosys.cc
@@ -46,6 +46,10 @@
 #  include <glob.h>
 #endif
 
+#ifdef __OpenBSD__
+#  include <sys/wait.h>
+#endif
+
 #include <limits.h>
 #include <errno.h>
 
@@ -655,6 +659,21 @@ std::string proc_self_dirname()
 	if (buflen < 0) {
 		log_error("readlink(\"/proc/self/exe\") failed: %s\n", strerror(errno));
 	}
+	while (buflen > 0 && path[buflen-1] != '/')
+		buflen--;
+	return std::string(path, buflen);
+}
+#elif defined(__OpenBSD__)
+std::string proc_self_dirname()
+{
+        // No direct way to get the process executable base path in OpenBSD
+	char path[PATH_MAX];
+	ssize_t buflen = sizeof(path);
+        char *res = realpath(getenv("_"), path);
+	if (!res) {
+		log_error("getenv(\"_\") failed: %s\n", strerror(errno));
+	}
+        *(strrchr(path, '/')+1) = '\0';
 	while (buflen > 0 && path[buflen-1] != '/')
 		buflen--;
 	return std::string(path, buflen);
