#######################################################################
#                            Main targets                             #
#######################################################################

## CASAnova on Wine in Docker

help: ## Show this help.
	@egrep -h '(\s##\s|^##\s)' $(MAKEFILE_LIST) | egrep -v '^--' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m  %-35s\033[0m %s\n", $$1, $$2}'

setup: ## Install CASAnova into ./config/wine (run once on the host).
	@echo "${green}Installing CASAnova...${no_color}"
	bash install.sh

build: ## Build the Docker image.
	@echo "${green}Building image...${no_color}"
	docker compose build

up: ## Start the container.
	@echo "${green}Starting container...${no_color}"
	docker compose up --detach

down: ## Stop and remove the container.
	@echo "${green}Stopping container...${no_color}"
	docker compose down

status: ## Show current container status.
	@docker compose ps --all | \
		sed "s/\b\(exited\)\b/${orange}\U\1\E${no_color}/gi" | \
		sed "s/\b\(up\)\b/${green}\U\1\E${no_color}/gi" | \
		sed "s/\b\(healthy\)\b/${green}\U\1\E${no_color}/gi" | \
		sed "s/\b\(unhealthy\)\b/${orange}\U\1\E${no_color}/gi" | tee /tmp/status
	@(grep -qi "UP" /tmp/status && echo "${green}UP!${no_color}") || echo "${red}DOWN!${no_color}"

logs: ## Follow container logs.
	@echo "${green}Showing logs...${no_color}"
	docker compose logs --follow

.PHONY: help setup build up down status logs

green=`tput setaf 2`
orange=`tput setaf 9`
red=`tput setaf 1`
no_color=`tput sgr0`
