# The Cryn Programming Language - bootstrap compiler build
#
#   make            build the cryn compiler
#   make test       run the test suite
#   make clean      remove build artifacts

CC      ?= cc
CFLAGS  ?= -O2 -std=c11 -Wall -Wextra -Wno-unused-parameter
BIN     = cryn

SRCS = src/main.c src/util.c src/diag.c src/lex.c src/parse.c src/types.c src/be_x64.c \
       src/check.c src/opt.c src/be_c.c
HDRS = src/util.h src/diag.h src/lex.h src/ast.h src/parse.h src/types.h src/be_x64.h \
       src/ir.h src/check.h src/opt.h src/be_c.h src/rt_src.h

all: $(BIN)

tools/embed: tools/embed.c
	$(CC) $(CFLAGS) -o $@ $<

src/rt_src.h: tools/embed src/rt/cryn_rt.h src/rt/cryn_rt.c
	./tools/embed src/rt/cryn_rt.h cr_rt_h_src src/rt/cryn_rt.c cr_rt_c_src > $@

$(BIN): $(SRCS) $(HDRS)
	$(CC) $(CFLAGS) -o $(BIN) $(SRCS)

test: $(BIN)
	sh tests/run.sh

test-release: $(BIN)
	CRYN_ARGS=--release sh tests/run.sh

test-native: $(BIN)
	CRYN_ARGS=--native sh tests/run.sh

clean:
	rm -f $(BIN) tools/embed src/rt_src.h

.PHONY: all test test-release test-native clean
