EL_ROOT ?= $(HOME)/Development/neuron-technologies/foundation/el
EL_LIB  ?= $(EL_ROOT)/el-compiler/runtime
ELC     ?= $(EL_ROOT)/dist/platform/elc
CC      ?= cc
# -DHAVE_CURL: the el-compiler runtime guards its libcurl client behind this
# macro, so a build without it links fine and then answers every http_get /
# http_post_json with {"error":"not built with HAVE_CURL"} — forge is entirely
# HTTP, so it fails at the first engram call. The SDK release runtime CI pulls
# has no such guard; defining it is a no-op there.
CFLAGS  := -std=c11 -O2 -DHAVE_CURL -I$(EL_LIB)

.PHONY: build clean install

dist/:
	mkdir -p dist

dist/forge.c: src/forge.el | dist/
	$(ELC) src/forge.el > dist/forge.c

dist/forge: dist/forge.c
	$(CC) $(CFLAGS) -o dist/forge dist/forge.c $(EL_LIB)/el_runtime.c -lcurl -lpthread

build: dist/forge

install: dist/forge
	install -m 755 dist/forge /usr/local/bin/forge

clean:
	rm -rf dist/forge dist/forge.c
