GO ?= go
BINARY ?= rsw
FUZZTIME ?= 10s

.PHONY: fmt vet test race cover build fuzz scale

fmt:
	$(GO) fmt ./...

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

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

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

cover:
	$(GO) test -coverprofile=coverage.out ./...
	$(GO) tool cover -func=coverage.out

build:
	CGO_ENABLED=0 $(GO) build -trimpath -ldflags='-s -w' -o $(BINARY) ./cmd/rsw

fuzz:
	$(GO) test ./internal/cartridge -run '^$$' -fuzz '^FuzzParsePNG$$' -fuzztime=$(FUZZTIME)
	$(GO) test ./internal/cartridge -run '^$$' -fuzz '^FuzzParseZIP$$' -fuzztime=$(FUZZTIME)
	$(GO) test ./internal/manifest -run '^$$' -fuzz '^FuzzParseManifest$$' -fuzztime=$(FUZZTIME)
	$(GO) test ./internal/uri -run '^$$' -fuzz '^FuzzParse$$' -fuzztime=$(FUZZTIME)
	$(GO) test ./internal/publishing -run '^$$' -fuzz '^FuzzParseIndex$$' -fuzztime=$(FUZZTIME)
	$(GO) test ./internal/renderer -run '^$$' -fuzz '^FuzzSanitizeCSS$$' -fuzztime=$(FUZZTIME)

scale:
	RSW_SCALE=1 $(GO) test ./internal/storage -run '^TestScaleMeasurements$$' -v
