# Makefile da library python (embedding CPython)
# Constroi build/libtinyblocks-python.so (soname unico p/ um so interpretador)
CC     := gcc
BUILD  := build

PYTHON_CFLAGS := $(shell python3-config --cflags --embed 2>/dev/null || python3-config --cflags)
PYTHON_LIBS   := $(shell python3-config --ldflags --embed 2>/dev/null || python3-config --ldflags)

CFLAGS := -std=c11 -O2 -Wall -Wextra -pedantic -fvisibility=hidden \
          -I../../include -Iinclude $(PYTHON_CFLAGS)

OBJ    := $(BUILD)/tb_python_lib.o
LIB_SO := $(BUILD)/libtinyblocks-python.so

.PHONY: all shared clean
all: shared
shared: $(LIB_SO)

$(OBJ): src/tb_python.c include/tinyblocks-python/tb_python.h
	@mkdir -p $(BUILD)
	$(CC) $(CFLAGS) -fPIC -c $< -o $@

$(LIB_SO): $(OBJ)
	$(CC) -shared -Wl,-soname,libtinyblocks-python.so -o $@ $^ $(PYTHON_LIBS)

clean:
	$(RM) -r $(BUILD)
