GO      ?= go
BIN     := bin
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)

.PHONY: all build test race vet fmt check run e2e clean

all: check build

build:
	$(GO) build -trimpath -ldflags "-s -w" -o $(BIN)/core ./cmd/core

test:
	$(GO) test ./...

race:
	$(GO) test -race -count=1 ./...

vet:
	$(GO) vet ./...

fmt:
	@out="$$(gofmt -l .)"; if [ -n "$$out" ]; then echo "gofmt needed on:"; echo "$$out"; exit 1; fi

# Everything CI runs.
check: fmt vet race

run: build
	./$(BIN)/core

# End-to-end test with the real yt-dlp and ffmpeg. Needs network access.
e2e:
	DLBOT_E2E_YTDLP=$${YTDLP_PATH:-$$(command -v yt-dlp)} $(GO) test -count=1 -v -run TestRealYtDlp ./internal/app

clean:
	rm -rf $(BIN)
