all: build
install: push

.PHONY: rebuild build push start stop restart bash logs

build: Dockerfile
	podman build --cap-add=CAP_SYS_PTRACE --tag chsa/distcc:latest .

rebuild: Dockerfile
	podman build --no-cache --cap-add=CAP_SYS_PTRACE --tag chsa/distcc:latest .

push: build
	podman push chsa/distcc:latest

start: build
	if [ `podman ps | grep chsa/distcc | wc -l` -eq 0 ]; then \
	    if [ `podman ps -a | grep distccd | wc -l` -gt 0 ]; then \
	        echo "Removing the stalled copy..." ;\
	        podman rm distccd ;\
	    fi ;\
	    podman run -p 0.0.0.0:3632:3632 --name distccd -t -d chsa/distcc:latest ;\
	else \
	    echo "Already running..." ;\
	fi

stop:
	@if [ `podman ps | grep distccd | wc -l` -gt 0 ]; then \
	    podman stop distccd ;\
	    podman rm distccd ;\
	fi

restart:
	make stop
	make start

debug: build
	podman rm distccd ;\
	podman run -p 0.0.0.0:3632:3632 --name distccd -it chsa/distcc:latest /bin/bash

bash: build
	podman exec -it distccd /bin/bash

logs:
	podman logs distccd