CC = 9c
LD = 9l
CFLAGS = -std=c99 -Wall -Wextra -O2 -g -I.. -I../cutest
LIBS = -lthread -lbio

PROG = unit_test
TESTSRC = unit_test.c test_util.c str_test.c hash_test.c trie_test.c \
	ko_test.c vi_test.c engine_test.c dict_test.c ipc_test.c wayland_test.c \
	popup_test.c
TESTOBJ = $(TESTSRC:.c=.o)
PARENTSRC = str.c hash.c trie.c dict.c ko.c vi.c ipc.c wayland_state.c \
	popup_layout.c
PARENTOBJ = $(PARENTSRC:%.c=unit_%.o)
OBJS = $(TESTOBJ) $(PARENTOBJ)

all: $(PROG)

check test: $(PROG)
	./$(PROG) $(TESTARGS)

$(PROG): $(OBJS)
	$(LD) -o $@ $(OBJS) $(LIBS)

$(TESTOBJ): test.h ../dat.h ../fn.h ../ipc.h ../cutest/cutest.h
engine_test.o: ../strans.c

unit_%.o: ../%.c ../dat.h ../fn.h ../ipc.h
	$(CC) $(CFLAGS) -c -o $@ $<

%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<

clean:
	rm -f $(OBJS) $(PROG)

.PHONY: all check test clean
