APP := target/release/Leaf.app

.PHONY: build run test app install icon clean

build:
	cargo build --release

run:
	cargo run --release

test:
	cargo test

# A macOS app bundle, so leaf can live in /Applications and the Dock.
app: build
	rm -rf $(APP)
	mkdir -p $(APP)/Contents/MacOS $(APP)/Contents/Resources
	cp target/release/leaf $(APP)/Contents/MacOS/leaf
	cp target/release/leaf-settings $(APP)/Contents/MacOS/leaf-settings
	cp macos/Info.plist $(APP)/Contents/Info.plist
	cp macos/Leaf.icns $(APP)/Contents/Resources/Leaf.icns
	cp shell/leaf.zsh $(APP)/Contents/Resources/leaf.zsh

install: app
	rm -rf /Applications/Leaf.app
	cp -R $(APP) /Applications/Leaf.app
	touch /Applications/Leaf.app

# Regenerates macos/Leaf.icns from a font glyph, e.g.
#   make icon FONT=$$HOME/Downloads/Yarndings20-Regular.ttf GLYPH=h
GLYPH ?= h
icon:
	@test -n "$(FONT)" || (echo "usage: make icon FONT=path/to/font.ttf [GLYPH=h]" && exit 2)
	rm -rf target/Leaf.iconset
	swift macos/make-icon.swift "$(FONT)" "$(GLYPH)" target/Leaf.iconset
	iconutil -c icns target/Leaf.iconset -o macos/Leaf.icns

clean:
	cargo clean
