.PHONY: build proxy test clean install

BINARY := rebreak-supervise-magic
PROXY := rebreak-usbmux-proxy
BIN_DIR := bin

build:
	@mkdir -p $(BIN_DIR)
	go build -o $(BIN_DIR)/$(BINARY) ./cmd/supervise

proxy:
	@mkdir -p $(BIN_DIR)
	go build -o $(BIN_DIR)/$(PROXY) ./cmd/usbmux-proxy

patcher:
	@mkdir -p $(BIN_DIR)
	go build -o $(BIN_DIR)/rebreak-tl-patcher ./cmd/tl-patcher

all: build proxy patcher

build-universal: build-arm64 build-amd64
	lipo -create -output $(BIN_DIR)/$(BINARY)-universal \
		$(BIN_DIR)/$(BINARY)-arm64 $(BIN_DIR)/$(BINARY)-amd64
	@echo "Universal binary at $(BIN_DIR)/$(BINARY)-universal"

build-arm64:
	@mkdir -p $(BIN_DIR)
	GOOS=darwin GOARCH=arm64 go build -o $(BIN_DIR)/$(BINARY)-arm64 ./cmd/supervise

build-amd64:
	@mkdir -p $(BIN_DIR)
	GOOS=darwin GOARCH=amd64 go build -o $(BIN_DIR)/$(BINARY)-amd64 ./cmd/supervise

test:
	go test ./...

clean:
	rm -rf $(BIN_DIR)

install: build
	cp $(BIN_DIR)/$(BINARY) $(HOME)/.local/bin/$(BINARY)
	@echo "Installed to $(HOME)/.local/bin/$(BINARY)"

tidy:
	go mod tidy
