# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2026 Francisco R. Ortega

APP := build/nuiClock.app
# Where `make install` puts the app. Use DEST=$(HOME)/Applications to install for one user.
DEST ?= /Applications

.PHONY: app universal test run install uninstall icon cities clean

# Build the app for this Mac.
app:
	scripts/build-app.sh

# Build the app for Apple silicon and Intel together.
universal:
	scripts/build-app.sh --universal

test:
	swift test

# Build and open the app from the build folder.
run: app
	open $(APP)

# Build, copy the app to DEST, and open it. A running nuiClock is quit first, and has ended before the new one opens.
install: app
	@if pgrep -x nuiClock >/dev/null; then pkill -x nuiClock; while pgrep -x nuiClock >/dev/null; do sleep 0.2; done; fi
	rm -rf "$(DEST)/nuiClock.app"
	ditto $(APP) "$(DEST)/nuiClock.app"
	open "$(DEST)/nuiClock.app"

# Quit the app and remove it from DEST. Settings stay; see the README to remove them too.
uninstall:
	-pkill -x nuiClock
	rm -rf "$(DEST)/nuiClock.app"

# Draw the app icon again from scripts/make-icon.swift.
icon:
	swift scripts/make-icon.swift

# Fetch the GeoNames city list again and rebuild Resources/cities.tsv.
cities:
	scripts/make-cities.sh

clean:
	rm -rf .build build
