# ChromaFlock — Makefile wrapping CMake
# Usage:
#   make            — configure (if needed) + build Release
#   make debug      — configure + build Debug
#   make clean      — remove build directory
#   make rebuild    — clean + build Release
#   make install    — build + copy plugins to system dirs
#   make run        — build Standalone and launch

BUILD_DIR    := build
BUILD_TYPE   := Release
CMAKE_FLAGS  := -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
JOBS         := $(shell sysctl -n hw.ncpu 2>/dev/null || echo 4)

# Artefact paths
VST3  := $(BUILD_DIR)/ChromaFlock_artefacts/$(BUILD_TYPE)/VST3/ChromaFlock.vst3
AU    := $(BUILD_DIR)/ChromaFlock_artefacts/$(BUILD_TYPE)/au/ChromaFlock.component
APP   := $(BUILD_DIR)/ChromaFlock_artefacts/$(BUILD_TYPE)/Standalone/ChromaFlock.app

.PHONY: all debug release clean rebuild configure install run help

all: release

release: $(VST3)

debug:
	@cmake -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=Debug $(CMAKE_FLAGS)
	@cmake --build $(BUILD_DIR) --config Debug -j$(JOBS)

$(VST3):
	@cmake -B $(BUILD_DIR) $(CMAKE_FLAGS)
	@cmake --build $(BUILD_DIR) --config $(BUILD_TYPE) -j$(JOBS)

configure:
	@cmake -B $(BUILD_DIR) $(CMAKE_FLAGS)

clean:
	@rm -rf $(BUILD_DIR)

rebuild: clean all

install: all
	@echo "Plugins were copied to system folders by CMAKE_COPY_PLUGIN_AFTER_BUILD."
	@echo "VST3: ~/Library/Audio/Plug-Ins/VST3/"
	@echo "AU:   ~/Library/Audio/Plug-Ins/Components/"

run: $(APP)
	open $(APP)

help:
	@echo "ChromaFlock Makefile"
	@echo ""
	@echo "  make            — Build Release (VST3/AU/Standalone)"
	@echo "  make debug      — Build Debug"
	@echo "  make clean      — Remove build/"
	@echo "  make rebuild    — Clean + Build Release"
	@echo "  make configure  — Run CMake configure only"
	@echo "  make install    — Show plugin install paths"
	@echo "  make run        — Build and launch Standalone app"
	@echo "  make help       — This message"
