# Copyright (C) 2026 Seth Hillbrand
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

VENV     := $(HOME)/.local/share/yolocam/venv
BIN      := $(HOME)/.local/bin
UV       := uv
COMMANDS := yolocam-ctl yolocam-gui

.PHONY: install install-gui-deps uninstall clean

install: $(VENV)/.installed

$(VENV)/.installed: yolocam-lib/pyproject.toml yolocam-ctl/pyproject.toml yolocam-gui/pyproject.toml
	$(UV) venv --system-site-packages $(VENV)
	VIRTUAL_ENV=$(VENV) $(UV) pip install -e yolocam-lib -e yolocam-ctl -e yolocam-gui
	mkdir -p $(BIN)
	ln -sf $(VENV)/bin/yolocam-ctl $(BIN)/yolocam-ctl
	ln -sf $(VENV)/bin/yolocam-gui $(BIN)/yolocam-gui
	touch $@
	@echo ""
	@echo "Installation complete. Commands available:"
	@echo "  yolocam-ctl  -- camera control CLI"
	@echo "  yolocam-gui  -- camera control GUI"
	@echo ""
	@echo "Ensure $(BIN) is on your PATH."

install-gui-deps:
	sudo apt install -y \
		python3-pyside6.qtcore \
		python3-pyside6.qtgui \
		python3-pyside6.qtwidgets \
		python3-opencv

uninstall:
	rm -f $(BIN)/yolocam-ctl $(BIN)/yolocam-gui
	rm -rf $(VENV)
	@echo "Uninstalled."

clean:
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
