PYTHON := $(shell scripts/find_tk_python.sh)
VENV := .venv
PY := $(VENV)/bin/python
PIP := $(VENV)/bin/pip
APP := Proxy God.app

.PHONY: setup run app test clean swift-build

setup:
	@if [ -x "$(PY)" ] && ! "$(PY)" -c "import tkinter" >/dev/null 2>&1; then rm -rf "$(VENV)"; fi
	$(PYTHON) -m venv $(VENV)
	$(PIP) install --upgrade pip
	$(PIP) install -r requirements.txt

run: setup
	$(PY) run.py

app:
	chmod +x scripts/run_proxy_god.sh
	mkdir -p "$(APP)/Contents/MacOS" "$(APP)/Contents/Resources"
	cp Bundle/ProxyGodInfo.plist "$(APP)/Contents/Info.plist"
	cp scripts/app_launcher.sh "$(APP)/Contents/MacOS/ProxyGod"
	chmod +x "$(APP)/Contents/MacOS/ProxyGod"

test: setup
	$(PY) -m unittest discover -s tests -v

clean:
	rm -rf "$(VENV)" "$(APP)" .build dist build
