BRLS:=$(wildcard brl-*.c)
TARGETS:=$(BRLS:.c=.psf)
PROGS:=$(BRLS:.c=)
TESTPROGS:=$(BRLS:.c=.test)
TESTS:=$(BRLS:.c=.txt)

UNAME=$(shell uname)

all: $(TARGETS) brl.uni gen-psf-block

test: $(TESTS)

ifeq ($(UNAME),Linux)
all: setbrlkeys
endif

brl-%: brl-%.o psf.o
	$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS)

gen-psf-block: gen-psf-block.o psf.o

%.test.o: %.c do.h
	$(CC) $(CFLAGS) $(CPPFLAGS) -DTEST -c -o $@ $<

.INTERMEDIATE: $(PROGS) $(TESTPROGS) uni

$(TARGETS): %.psf: %
	./$< > $@

$(TESTS): %.txt: %.test
	./$< > $@

brl.uni: uni
	./$< 0 > $@

clean:
	rm -f $(PROGS) $(TESTPROGS) psf.o $(BRLS:.c=.o) gen-psf-block.o $(TARGETS) $(TESTS) brl.uni uni setbrlkeys gen-psf-block
