Makefile in git
BIN(7)             FreeBSD Miscellaneous Information Manual             BIN(7)

     bin – various utilities

     Various tools primarily targeting Darwin, FreeBSD and NetBSD.  Some tools
     target Linux.

     aes(1)      fullwidth output
     beef(1)     Befunge-93 interpreter
     bit(1)      calculator
     bri(1)      backlight brightness control
     brot(1)     Mandelbrot renderer
     dtch(1)     detached sessions
     fbatt(1)    framebuffer battery indicator
     fbclock(1)  framebuffer clock
     gfxx(1)     graphics data explorer
     glitch(1)   PNG glitcher
     hi(1)       syntax highlighter
     hnel(1)     PTY input remapper
     modem(1)    fixed baud rate wrapper
     order(1)    operator precedence
     pbd(1)      macOS pasteboard daemon
     pngo(1)     PNG optimizer
     psf2png(1)  PSF2 to PNG renderer
     psfed(1)    PSF2 font editor
     ptee(1)     tee for PTYs
     relay(1)    IRC relay
     scheme(1)   color scheme
     shotty(1)   terminal capture
     ttpre(1)    man output to HTML
     up(1)       upload file
     wake(1)     wake-on-LAN
     wat(1)      watch files
     when(1)     date calculator
     xx(1)       hexdump

     One piece of reused code.

     png(3)  basic PNG output

Causal Agency                    July 24, 2019                   Causal Agency
GFX = cocoa
LIBRESSL_PREFIX = /usr/local

PREFIX = ~/.local
MANDIR = ${PREFIX}/share/man

CFLAGS += -Wall -Wextra -Wpedantic
LDLIBS = -lm -lutil -lz

LDLIBS_tls = ${LDLIBS} -ltls

GFX_OBJ = gfx-${GFX}.o
LDLIBS_cocoa = ${LDLIBS} -framework Cocoa
LDLIBS_x11 = ${LDLIBS} -lX11


BINS_ANY += aes
BINS_ANY += bit
BINS_ANY += dtch
BINS_ANY += glitch
BINS_ANY += hi
BINS_ANY += hnel
BINS_ANY += modem
BINS_ANY += order
BINS_ANY += pbd
BINS_ANY += pngo
BINS_ANY += psf2png
BINS_ANY += ptee
BINS_ANY += scheme
BINS_ANY += setopt
BINS_ANY += shotty
BINS_ANY += ttpre
BINS_ANY += up
BINS_ANY += wake
BINS_ANY += when
BINS_ANY += xx

LINKS_ANY += open
LINKS_ANY += pbcopy
LINKS_ANY += pbpaste

BINS_BSD += beef
BINS_BSD += wat

BINS_GFX += brot
BINS_GFX += gfxx

BINS_LINUX += fbatt
BINS_LINUX += fbclock
BINS_LINUX += psfed

BINS_TLS += relay

MANS = ${BINS:%=man1/%.1}

# Groups

any: meta ${BINS_ANY} ${LINKS_ANY}

bsd: meta ${BINS_BSD}

gfx: meta ${BINS_GFX}

linux: meta ${BINS_LINUX}

tls: meta ${BINS_TLS}

meta: tags .gitignore

# Binaries

brot: brot.o ${GFX_OBJ}
	${CC} ${LDFLAGS} $@.o ${GFX_OBJ} ${LDLIBS_${GFX}} -o $@

gfxx: gfxx.o ${GFX_OBJ}
	${CC} ${LDFLAGS} $@.o ${GFX_OBJ} ${LDLIBS_${GFX}} -o $@

hi: hi.c
	${CC} ${CFLAGS} ${LDFLAGS} hi.c ${LDLIBS} -o $@
	./hi -c

open pbcopy pbpaste: pbd
	ln -f pbd $@

relay: relay.c
	${CC} ${CFLAGS_tls} ${LDFLAGS_tls} $@.c ${LDLIBS_tls} -o $@

# Headers

brot.o gfxx.o gfx-cocoa.o gfx-fb.o gfx-x11.o: gfx.h

fbatt.o fbclock.o: scheme.h

gfxx.o psf2png.o scheme.o: png.h

scheme.h: scheme
	./scheme -c > scheme.h

	${CC} ${LDFLAGS} $< ${LDLIBS} -o $@


HTMLS = index.html ${BINS:%=%.html} png.html
WEBROOT = /usr/local/www/

html: ${HTMLS}

${HTMLS}: hi ttpre

.SUFFIXES: .html

	sh $< man1/${<:.c=.1} > $@

	sh $< man3/${<:.h=.3} > $@

	sh $< man1/${<} > $@

	sh $< man1/${<:.y=.1} > $@

index.html: Makefile bin.7
	sh Makefile bin.7 \
		| sed -E 's,([a-z0-9-]+)[(][1-9][)],<a href="\1.html">&</a>,' \
		> index.html

# Meta

README: bin.7
	mandoc bin.7 | col -bx > README

scheme.png: scheme
	./scheme -gt > scheme.png

tags: *.h *.c
	ctags -w *.h *.c

IGNORE = '*.o' '*.html' scheme.h scheme.png tags ${BINS} ${LINKS}

.gitignore: Makefile
	echo ${IGNORE} | tr ' ' '\n' | sort > .gitignore

	rm -f ${IGNORE}

# Install

	install -d ${PREFIX}/bin ${MANDIR}/man1
	ln -fs ${BINS:%=${PWD}/%} ${LINKS:%=${PWD}/%} ${PREFIX}/bin
	ln -fs ${MANS:%=${PWD}/%} ${MANDIR}/man1

	rm -f ${BINS:%=${PREFIX}/bin/%} ${LINKS:%=${PREFIX}/bin/%}
	rm -f ${MANS:%=${MANDIR}/%}

install-html: ${HTMLS}
	install -d ${WEBROOT}/bin
	install -C -m 644 ${HTMLS} ${WEBROOT}/bin

setuid: bri
	chown root bri
	chmod u+s bri