DOCKER_COMPOSE := $(shell which docker-compose)

ifeq (${DOCKER_COMPOSE},)
DOCKER_COMPOSE = docker compose
endif

VERSION    := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT     := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS    := -X github.com/beelzebub-labs/beelzebub/v3/cli.Version=$(VERSION) \
              -X github.com/beelzebub-labs/beelzebub/v3/cli.CommitSHA=$(COMMIT) \
              -X github.com/beelzebub-labs/beelzebub/v3/cli.BuildDate=$(BUILD_DATE)

.PHONY: build
build:
	go build -ldflags "$(LDFLAGS)" -o beelzebub .

.PHONY: beelzebub.start
beelzebub.start:
	${DOCKER_COMPOSE} build;
	${DOCKER_COMPOSE} up -d;

.PHONY: beelzebub.stop
beelzebub.stop:
	${DOCKER_COMPOSE} down;

.PHONY: test.unit
test.unit:
	go test ./...

.PHONY: test.unit.verbose
test.unit.verbose:
	go test ./... -v

.PHONY: test.dependencies.start
test.dependencies.start:
	${DOCKER_COMPOSE} -f ./integration_test/docker-compose.yml up -d

.PHONY:	test.dependencies.down
test.dependencies.down:
	${DOCKER_COMPOSE} -f ./integration_test/docker-compose.yml down

.PHONY: test.integration
test.integration:
	INTEGRATION=1 go test ./...

.PHONY: test.integration.verbose
test.integration.verbose:
	INTEGRATION=1 go test ./... -v
