# Cross-compiles on Linux/macOS with mingw-w64:
#   sudo apt install mingw-w64        (Debian/Ubuntu)
#   make
#
# Natively on Windows with MSYS2 (mingw-w64 toolchain):
#   pacman -S mingw-w64-x86_64-gcc make
#   make CC=gcc
#
# Either way, produces dtmf_console.exe. Run it with the audio/ folder
# sitting next to the .exe (callsign station-ID clips live there).

CC ?= x86_64-w64-mingw32-gcc
WINDRES ?= x86_64-w64-mingw32-windres
CFLAGS = -std=c99 -Wall -Wextra -Wno-unknown-pragmas -Wno-unused-parameter -O2 -mwindows
LIBS = -lwinmm -lcomctl32 -lcomdlg32

SRCS = dtmf_core.c audio.c winclasses.c helpers.c rxpanel.c \
       tab_tx.c tab_imgenc.c tab_rx.c tab_imgdec.c tab_hex.c tab_ref.c tab_server.c \
       handlers.c main.c

OUT = dtmf_console.exe

all: $(OUT)

app_res.o: app.rc app.manifest icon.ico ids.h
	$(WINDRES) app.rc -O coff -o app_res.o

$(OUT): $(SRCS) *.h app_res.o
	$(CC) $(CFLAGS) $(SRCS) app_res.o -o $(OUT) $(LIBS)

# native-Linux build of just the portable core logic + its unit test
# (no Windows dependency; useful for quickly sanity-checking dtmf_core.c
# changes without needing mingw or a Windows machine at all)
test_core: dtmf_core.c dtmf_core.h test_core.c
	gcc -std=c99 -Wall -O2 -o test_core dtmf_core.c test_core.c -lm
	./test_core

clean:
	rm -f $(OUT) test_core app_res.o *.o

.PHONY: all clean test_core
