# radio-ui: run from this directory.
#   make lib         panel core library for the application (./radio-ui)
#   make test        application tests: MPD client, rendering, simulated panel
#   make panel-test  the panel core's own tests (in $(PANEL_DIR))
#   make module      the DRM driver, against KDIR (for tests/hw_test.sh drm)
#
# PANEL_DIR is the s1d13700-tca repository, KEYBOARD_DIR radio-keyboard-tca
# (the key overlay the tests compare with): the submodules by default.

BUILD     := build
CC        ?= gcc
CFLAGS    ?= -O2 -g
CFLAGS    += -std=gnu11 -Wall -Wextra -MMD -MP
PANEL_DIR ?= panel
KEYBOARD_DIR ?= keyboard
CFLAGS    += -I$(PANEL_DIR)/driver -I$(PANEL_DIR)/sim
PYTHON    ?= python3
PANEL_LIB := $(BUILD)/libradiopanel.so

CORE := $(PANEL_DIR)/driver/s1d13700_core.c
SIM  := $(PANEL_DIR)/sim/s1d13700_sim.c

export PANEL_DIR KEYBOARD_DIR

.PHONY: all lib test pytest panel-test module clean
all: lib

lib: $(PANEL_LIB)

$(CORE) $(SIM):
	@echo "$@ missing: run 'git submodule update --init' or set PANEL_DIR" >&2; exit 1

$(PANEL_LIB): radio/libpanel.c $(CORE) $(SIM)
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) -fPIC -shared -o $@ radio/libpanel.c $(CORE) $(SIM)

test pytest: $(PANEL_LIB)
	$(PYTHON) -W 'ignore::DeprecationWarning:gi.events' -m unittest discover -s tests -p 'test_*.py' -v

panel-test:
	$(MAKE) -C $(PANEL_DIR) test

module:
	$(MAKE) -C $(PANEL_DIR) module

clean:
	rm -rf $(BUILD)

-include $(wildcard $(BUILD)/*.d)
