.PHONY: all build clean install uninstall rebuild run

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

all: build

$(BUILD_DIR)/Makefile:
	@mkdir -p $(BUILD_DIR)
	cd $(BUILD_DIR) && cmake .. -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)

build: $(BUILD_DIR)/Makefile
	cmake --build $(BUILD_DIR) -j $(JOBS)

clean:
	rm -rf $(BUILD_DIR)

reinstall: clean build

uninstall:
	rm -rf ~/Library/Audio/Plug-Ins/VST3/Saftpumpe.vst3
	rm -rf ~/Library/Audio/Plug-Ins/Components/Saftpumpe.component

install: build

run: build
	open "$(BUILD_DIR)/Saftpumpe_artefacts/Release/Standalone/Saftpumpe.app"

debug:
	cmake --build $(BUILD_DIR) -j $(JOBS) 2>&1 | head -100

help:
	@echo "Saftpumpe - Bus Compressor Plugin"
	@echo ""
	@echo "Targets:"
	@echo "  make          - Build the plugin"
	@echo "  make clean    - Remove build directory"
	@echo "  make reinstall - Clean and rebuild"
	@echo "  make uninstall - Remove installed plugins"
	@echo "  make run      - Launch standalone app"
	@echo "  make debug    - Build with verbose output"
	@echo ""
	@echo "Formats: VST3, AU, Standalone"
	@echo "Install paths:"
	@echo "  VST3: ~/Library/Audio/Plug-Ins/VST3/"
	@echo "  AU:   ~/Library/Audio/Plug-Ins/Components/"
