export SHELL=bash

.PHONY: help
# HELP: print out this help message
help:
	@if [ -z "$$(which perl 2>/dev/null)" ] ; then \
	  $(CONTAINER_FGRUN) .:/mnt 'debian:12.5' '/mnt/utils/makehelp.pl' '/mnt/Makefile' ; \
	else \
	  utils/makehelp.pl Makefile ; \
	fi

.PHONY: clean
# HELP: stop all running containers and remove all compilation results in the directory (but leave images including dependencies unharmed)
clean:
	-rm -rf frontend/node_modules .npm .cache frontend/assets/icons frontend/assets/favicons frontend/static well-known config/manifest.json frontend/src/env.sass
	-rm -rf .stack-work .stack-work.lock
	-rm -rf bin .Dockerfile develop
	-$(CONTAINER_COMMAND) container prune --force
.PHONY: clean-images
# HELP: stop all running containers and clean all images from local repositories
clean-images:
	rm -rf develop
	sleep 5
	-$(CONTAINER_COMMAND) system prune --all --force --volumes
	-$(CONTAINER_COMMAND) image prune --all --force
	-$(CONTAINER_COMMAND) volume prune --force
.PHONY: clean-all
# HELP: like clean but with full container, image, and volume prune
clean-all: clean
	-rm -rf .stack
	$(CONTAINER_COMMAND) system reset --force

.PHONY: release
# HELP: create, commit and push a new release
# TODO: only release when build and tests are passing!!!
release:
	VERSION=`./utils/version.pl -changelog CHANGELOG.md -v` ; \
	git add CHANGELOG.md ; \
	git commit -m "chore(release): $${VERSION}" ; \
	git push ; \
	git tag $${VERSION} ; \
	git push origin $${VERSION}

.PHONY: compile
# HELP: perform full compilation (frontend and backend)
compile: compile-frontend compile-backend ;
.PHONY: compile-%
compile-%:
	docker compose run --remove-orphans --build --no-deps $* make compile

.PHONY: start
# HELP: start complete development environment with a fresh test database
start: start-postgres start-maildev start-memcached start-minio start-backend
	docker compose run backend make start
.PHONY: start-%
start-%:
	docker compose up -d --build $*

.PHONY: stop
stop:
	docker compose down
.PHONY: stop-%
stop-%:
	docker compose down $*
.PHONY: kill-%
kill-%:
	docker compose kill $*

.PHONY: status
status:
	docker compose ps
.PHONY: top
top:
	docker compose stats

.PHONY: log-%
log-%:
	docker compose logs --follow --timestamps $*

.PHONY: --%
.SUFFIXES: # Delete all default suffixes
