# Host build for the ESP-IDF-free firmware logic units.
#
# Requires nothing but gcc and make. No ESP-IDF, no test framework, no
# package manager. `make check` builds and runs; `run_tests.sh` wraps this
# and is the entry point CI (and you) should call.

CC      ?= gcc
CFLAGS  ?= -std=c11 -O1 -g -Wall -Wextra -Werror
LDLIBS  ?= -lm

MAIN_DIR := ../main
BUILD    := build

# The pure units under test, moved out of their drivers precisely so they
# can be compiled here without a cross-toolchain.
UNITS := \
	$(MAIN_DIR)/rd03e_parse.c \
	$(MAIN_DIR)/bmp280_compensate.c \
	$(MAIN_DIR)/mems_level.c

TESTS := \
	test_main.c \
	test_rd03e_parse.c \
	test_bmp280_compensate.c \
	test_mems_level.c

BIN := $(BUILD)/firmware_tests

.PHONY: all check clean
all: $(BIN)

$(BIN): $(UNITS) $(TESTS) test_util.h $(MAIN_DIR)/rd03e_parse.h $(MAIN_DIR)/bmp280_compensate.h $(MAIN_DIR)/mems_level.h
	@mkdir -p $(BUILD)
	$(CC) $(CFLAGS) -o $@ $(UNITS) $(TESTS) $(LDLIBS)

check: $(BIN)
	./$(BIN)

clean:
	rm -rf $(BUILD)
