CC = gcc
CFLAGS = -std=c99 -Wall -Wextra -Wpedantic -O2 -D_POSIX_C_SOURCE=200809L

SRC_DIR = src
TARGET = didactyl

SRCS = \
	$(SRC_DIR)/main.c \
	$(SRC_DIR)/config.c \
	$(SRC_DIR)/context.c \
	$(SRC_DIR)/llm.c \
	$(SRC_DIR)/nostr_handler.c \
	$(SRC_DIR)/agent.c \
	$(SRC_DIR)/secp_compat.c

INCLUDES = \
	-I$(SRC_DIR) \
	-I../nostr_core_lib \
	-I../nostr_core_lib/cjson \
	-I../nostr_core_lib/nostr_core

NOSTR_LIB = $(firstword $(wildcard ../nostr_core_lib/libnostr_core_*.a))

LDFLAGS = -lcurl -lssl -lcrypto -lm -lpthread -ldl -lz -lsecp256k1

all: deps $(TARGET)

$(TARGET): $(SRCS)
	@if [ -z "$(NOSTR_LIB)" ]; then echo "nostr_core_lib static library not found; run 'make deps'"; exit 1; fi
	$(CC) $(CFLAGS) $(INCLUDES) -o $@ $(SRCS) $(NOSTR_LIB) $(LDFLAGS)

deps:
	cd ../nostr_core_lib && ./build.sh --nips=all

clean:
	rm -f $(TARGET)

.PHONY: all deps clean
