CC      ?= cc
# -fPIC everywhere: the same .o files serve the binary and libpokereval.so (the
# shared library at the ctypes boundary, step 3). There is no extra cost on
# Linux/x86-64, and it avoids two sets of object files.
CFLAGS  ?= -O2 -std=c11 -Wall -Wextra -Werror -fPIC

OBJS    = eval.o census.o cache.o eval7.o main.o
LIBOBJS = eval.o cache.o eval7.o

pokereval: $(OBJS)
	$(CC) $(CFLAGS) -o $@ $(OBJS)

# The Python binding (`pokerlm.eval7_c`, ctypes) loads this .so: a single
# batched call `eval7_batch(hands, n, out)`, with no subprocess per call.
libpokereval.so: $(LIBOBJS)
	$(CC) $(CFLAGS) -shared -o $@ $(LIBOBJS)

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

check: pokereval libpokereval.so
	./pokereval census
	./pokereval cache
	./pokereval eval7-check

clean:
	rm -f pokereval libpokereval.so *.o

.PHONY: check clean
