MESAC ?= mesac
TARGET ?= native64
BUILD_DIR ?= .
MESAFLAGS ?=
MESALDFLAGS ?=
SOURCES := $(wildcard *.mesa)
PROGRAMS := $(BUILD_DIR)/TestBinaryTree

all: $(PROGRAMS)

$(BUILD_DIR)/TestBinaryTree: tree.cmesa $(SOURCES) FORCE
	mkdir -p $(@D)
	$(MESAC) $< --target=$(TARGET) $(MESAFLAGS) $(MESALDFLAGS) -o $@

clean:
	rm -f $(PROGRAMS:=.c) $(SOURCES:.mesa=.c)
	rm -rf build
	rm -f $(PROGRAMS) $(PROGRAMS:=.mesabuild) $(SOURCES:.mesa=.o) $(SOURCES:.mesa=.mesai)
	rm -f $(SOURCES:.mesa=.o.mesabuild) $(SOURCES:.mesa=.mesai.mesabuild)

# The compiler's configuration builder tracks target/option changes and sources.
FORCE:
.PHONY: all clean FORCE
