BUILD_DIR := build

# Standard macOS user plugin folders.
AU_DIR    := $(HOME)/Library/Audio/Plug-Ins/Components
VST3_DIR  := $(HOME)/Library/Audio/Plug-Ins/VST3

PLUGIN    := "$(BUILD_DIR)/GelykEQ_artefacts/Release/AU/Gelyk EQ.component"
VST3PLUG  := "$(BUILD_DIR)/GelykEQ_artefacts/Release/VST3/Gelyk EQ.vst3"

J = $(shell sysctl -n hw.ncpu)

all: build

# Configure + build with CMake (default make).
build: cmake-configure
	cmake --build $(BUILD_DIR) --config Release -j$(J)

cmake-configure:
	cmake -S . -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=Release

# Fully install the plugin into the macOS user plugin folders, then
# refresh the system so the host (AudioUnit/VST3.scan) picks it up.
install: build
	rm -rf "$(AU_DIR)/Gelyk EQ.component" "$(VST3_DIR)/Gelyk EQ.vst3"
	mkdir -p "$(AU_DIR)" "$(VST3_DIR)"
	cp -R $(PLUGIN) "$(AU_DIR)/"
	cp -R $(VST3PLUG) "$(VST3_DIR)/"
	@# Ad-hoc codesign the plugins so macOS/DAWs accept them.
	@if command -v codesign >/dev/null; then \
		(codesign --force --deep --sign - "$(AU_DIR)/Gelyk EQ.component" 2>/dev/null || true); \
		(codesign --force --deep --sign - "$(VST3_DIR)/Gelyk EQ.vst3" 2>/dev/null || true); \
	fi
	@echo ""
	@echo "Installed:"
	@echo "  $(AU_DIR)/Gelyk EQ.component"
	@echo "  $(VST3_DIR)/Gelyk EQ.vst3"
	@touch ~/Library/Preferences/com.apple.audio.InfoHelper 2>/dev/null || true

clean:
	rm -rf $(BUILD_DIR)

.PHONY: all build cmake-configure install clean
