MESAC ?= mesac
TARGET ?= native64
MESAFLAGS ?= -O
MESALDFLAGS ?=
THREADS ?= 4
LOG2 ?= $(if $(filter mesa16,$(TARGET)),11,18)
ROUNDS ?= 10
SOURCES := $(wildcard *.mesa)

all: fft

fft: fft.cmesa $(SOURCES) FORCE
	$(MESAC) $< --target=$(TARGET) $(MESAFLAGS) $(MESALDFLAGS) -o $@

run: fft
	./fft $(THREADS) $(LOG2) $(ROUNDS)

# Wall time is the relevant comparison; CPU time sums work across all threads.
time: fft
	time ./fft $(THREADS) $(LOG2) $(ROUNDS)

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

FORCE:
.PHONY: all run time clean FORCE
