These notes are for OpenBSD 7.9

The supplied 'make' will not work: you need to use gmake (GNU make):

# pkg_add gmake

There is no nproc command (used by make.qm). Get it from coreutils
(it'll be called gnproc because OpenBSD renames all GNU commands that way):

# pkg_add coreutils

Patch qmake.qm:

--- a/make.qm
+++ make.qm
@@ -1,8 +1,8 @@
 # Macros of use when developing q
-# N.B. always run make clean before make install
+# N.B. always run gmake clean before gmake install

 # Make cc lines as short as we can
-n040 !make -j$(($(nproc)+1)) PREFIX= HELP_CMD=^J^NU
+n040 !gmake -j$(($(gnproc)+1)) PREFIX= HELP_CMD=^J^NU
 # n213 (^N^W^K) Insert static prototype at front
 n213 ^NC^N\^NM^<1577>^J^[^NF{g1^Jl Static' 'prototypes^J^NC^N\^[m-^J^Z^T^ND^N^<1577>;^Jg t{^J^NU
 # n214 (^N^W^L) replace all (void)write(1,... with fputs ... stderr

You can use the 'patch' command to apply the above and below patches:

YOU MUST DO THIS BEFORE INSTALLING
=== ==== == ==== ====== ==========

$ patch <INSTALL_OPENBSD

BEFORE RUNNING GMAKE
====== ======= =====

I found it easier to edit config.mak rather than supply extra args to gmake.
This patch puts the man pages where the man command can find them:

--- a/config.mak
+++ config.mak
@@ -13,7 +13,7 @@ BINDIR:=$(EPREFIX)/bin
 DATAROOTDIR:=$(PREFIX)/share
 DATADIR:=$(DATAROOTDIR)/q
 DOCDIR:=$(DATAROOTDIR)/doc/q
-MANDIR:=$(DATAROOTDIR)/man
+MANDIR:=/usr/local/man
 SYSCONFDIR:=$(PREFIX)/etc
 DESTDIR:=


Patch ggdb before installing, to give a working macro debugger:

--- a/q/ggdb
+++ q/ggdb
@@ -160,7 +160,7 @@ proc docmds {which} \
 }

 # start gdb, and put in some nice settings
-if {[info exists tty]} {spawn gdb -n -q --tty=$tty} {spawn gdb -n -q}
+if {[info exists tty]} {spawn egdb -n -q --tty=$tty} {spawn egdb -n -q}
 expect {(gdb) }
 if {$PID==0} \
 {

Patch Makefile not to build disowntty:
diff --git a/Makefile b/Makefile
index a00f9d5..83037cc 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ install_bin: q
 	mkdir -p $(DESTDIR)$(BINDIR) && \
 cp bin/qm q/q $(DESTDIR)$(BINDIR)
 
-install_debug: q/disowntty
+install_debug:
 	mkdir -p $(DESTDIR)$(DATADIR)/debug && \
 (cd q; for i in *.gdb disowntty ggdb macro_debug_sample pipe_demo.txt; do \
 cp $$i $(DESTDIR)$(DATADIR)/debug; done; \
@@ -53,6 +53,3 @@ rm -r $(DESTDIR)$(DOCDIR)/; \
 for i in etc/*; do rm $(DESTDIR)$(ETC_DIR)/$$(basename $$i); done; \
 for i in man/man*; do j=$(DESTDIR)$(MANDIR)/$$(basename $$i); \
 for k in $$i/*.?;do rm $$j/$$(basename $$k); done; done
-
-q/disowntty:
-	cd disowntty && $(MAKE)

Now you can run:

# gmake clean; CFLAGS=-O0 gmake install

Be wary of substituting e.g. -O2 for -O0. The installed compiler (Clang)
ignores the GCC pragma that turns off optimising in workfile.c.
The pragma is there because I've had trouble with optimising that code at some
GCC versions.

Clang warns it doesn't recognise this pragma and also bleats about sprintf(),
strcpy() and strcat(). I have found no way to suppress these warnings
(clang ignores -Wno-unknown-pragmas).

BEFORE RUNNING THE MACRO DEBUGGER
====== ======= === ===== ========

The gdb that comes with OpenBSD 7.9 fails to load Q's symbol table.
Get a newer one by:

# pkg_add gdb

The new gdb is called egdb. The above patch took care of the name change.
ggdb is copied from command_line_tools. Even if you have installed
command_line_tools, you may like to:

$ ln -s /usr/local/share/q/debug/ggdb ~/bin/

or patch the copy in command_line_tools.

ggdb uses expect:

# pkg_add expect
