-include build/base.Makefile
-include build/docker.Makefile


help::
	@echo "$(APP_NAME) targets:"
	@echo "    init.dev        - init development environment"
	@echo "    lint            - verify code style"
	@echo "    spell           - check spelling of text"
	@echo "    test            - run test suite"
	@echo "    log             - tail log file"
	@echo "    syslog          - tail syslog file"
	@echo "    run             - start app"
	@echo "    run.debug       - start app in debug mode"
	$(call docker_help)


# Settings

AURA_ENGINE_CORE_SOCKET := "aura_engine_socket"
AURA_ENGINE_CORE_CONFIG := ${CURDIR}/config/engine-core.docker.ini
AURA_AUDIO_STORE_SOURCE := ${CURDIR}/audio/source
AURA_AUDIO_STORE_PLAYLIST := ${CURDIR}/audio/playlist
AURA_AUDIO_STORE_FALLBACK := ${CURDIR}/audio/fallback
AURA_LOGS := ${CURDIR}/logs
TIMEZONE := "Europe/Vienna"

DOCKER_RUN = @docker run \
		--name $(APP_NAME) \
		--network="host" \
		--mount type=tmpfs,destination=/tmp \
		--device /dev/snd \
		--group-add audio \
		-e TZ=$(TIMEZONE) \
		-v "$(AURA_ENGINE_CORE_SOCKET)":"/srv/socket" \
		-v "$(AURA_ENGINE_CORE_CONFIG)":"/etc/aura/engine-core.ini":ro \
		-v "$(AURA_AUDIO_STORE_SOURCE)":"/var/audio/source":ro \
		-v "$(AURA_AUDIO_STORE_PLAYLIST)":"/var/audio/playlist":ro \
		-v "$(AURA_AUDIO_STORE_FALLBACK)":"/var/audio/fallback":ro \
		-u $(UID):$(GID) \
		$(DOCKER_ENTRY_POINT) \
		autoradio/$(APP_NAME)

# Targets

lint::
	liquidsoap --check src/engine.liq

spell:: SPELL_PATHS := $(wildcard *.md) docs src tests config contrib
spell:: SPELL_PATHS_SKIP := src/archive
spell:: SPELL_IGNORE_FILE := .codespellignore
spell::
	codespell --ignore-words "$(SPELL_IGNORE_FILE)" --skip "$(SPELL_PATHS_SKIP)" $(SPELL_PATHS)

init.dev::
	sudo apt install -y
		codespell

test::
	(cd tests && liquidsoap engine_test_suite.liq)

log::
	tail -f logs/$(APP_NAME).log

run::
	(cd src && liquidsoap ./engine.liq)

run.debug::
	(cd src && liquidsoap --verbose --debug ./engine.liq)

docker.init::
	@echo "Creating Docker Volume for Engine Socket at '$(AURA_ENGINE_CORE_SOCKET)'"
	docker volume create aura_engine_socket