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
     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
     relay(1)    IRC relay
     scheme(1)   color scheme
     ttpre(1)    man output to HTML
     up(1)       upload file
     wake(1)     wake-on-LAN
     wat(1)      watch files
     xx(1)       hexdump

     To build graphical tools, set one of:


Causal Agency                     May 4, 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

LDLIBS_cocoa = $(LDLIBS) -framework Cocoa
LDLIBS_x11 = $(LDLIBS) -lX11


BINS += aes
BINS += dtch
BINS += glitch
BINS += hi
BINS += hnel
BINS += modem
BINS += order
BINS += pbd
BINS += pngo
BINS += psf2png
BINS += scheme
BINS += setopt
BINS += ttpre
BINS += up
BINS += wake
BINS += xx

LINKS += atch
LINKS += open
LINKS += pbcopy
LINKS += 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

MAN1_ALL = $(BINS_ALL:%=man1/%.1)

any: .gitignore tags $(BINS) $(LINKS)

bsd: $(BINS_BSD)

gfx: $(BINS_GFX)

linux: $(BINS_LINUX)

tls: $(BINS_TLS)

	$(CC) $(LDFLAGS) $< $(LDLIBS) -o $@

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

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

GFX_OBJ = gfx-$(GFX).o

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

relay: relay.c
	$(CC) $(CFLAGS_tls) $(LDFLAGS_tls) relay.c $(LDLIBS_tls) -o $@

atch: dtch
	ln -f dtch atch

open pbcopy pbpaste: pbd
	ln -f pbd $@

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

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

IGNORE = '*.o' '*.html' tags scheme.h scheme.png $(BINS_ALL) $(LINKS)

.gitignore: Makefile
	echo $(IGNORE) | tr ' ' '\n' | sort > .gitignore

HTMLS = $(BINS_ALL:%=%.html)
HTMLS += Makefile.html
HTMLS += gfx-fb.html
HTMLS += gfx-x11.html
HTMLS += gfx.html
HTMLS += html.html
HTMLS += png.html
WEBROOT = /usr/local/www/

html: $(HTMLS)

$(HTMLS): ttpre hi

.SUFFIXES: .html

	sh $< man1/$(<:.c=.1) > $@

	sh $< man1/$(<:.y=.1) > $@

	sh $< man1/$(< > $@

	sh $< > $@

Makefile.html: Makefile bin.7
	sh Makefile bin.7 > Makefile.html

	rm -f $(BINS_ALL) $(LINKS) tags scheme.h scheme.png *.o *.html

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

setuid: bri
	chown root bri
	chmod u+s bri

	install -d $(PREFIX)/bin $(MANDIR)/man1
	ln -fs $(BINS_ALL:%=$(PWD)/%) $(LINKS:%=$(PWD)/%) $(PREFIX)/bin
	ln -fs $(MAN1_ALL:%=$(PWD)/%) $(MANDIR)/man1

	rm -f $(BINS_ALL:%=$(PREFIX)/bin/%) $(LINKS:%=$(PREFIX)/bin/%)
	rm -f $(MAN1_ALL:%=$(MANDIR)/%)

install-html: $(HTMLS)
	install -d $(WEBROOT)/bin
	install -C -m 644 $(HTMLS) $(WEBROOT)/bin