export SHELL := /bin/bash
export PATH := $(PWD)/bin:$(PWD):$(PATH)
export GOBIN := $(PWD)/bin
export GOPROXY := direct
export GOPRIVATE := *

DOCKER_TAG = privacy/pdms-schema
DOCKER_VOLUME = pdms-schema-cache
DOCKER_VOLUME_MOUNT = -v $(DOCKER_VOLUME):/.cache
DOCKER_LOCAL_MOUNT = -v $(shell pwd):$(shell pwd) -w $(shell pwd) -u $(shell id -u):$(shell id -g)
DOCKER_RUN = docker run --rm $(DOCKER_VOLUME_MOUNT) $(DOCKER_LOCAL_MOUNT) $(DOCKER_TAG)

default: build

docker-image:
	docker build -t $(DOCKER_TAG) .

docker-volume:
	docker volume create $(DOCKER_VOLUME)

build: docker-image docker-volume
	$(DOCKER_RUN) prototool generate datasets

fmt: docker-image docker-volume
	$(DOCKER_RUN) prototool format datasets --overwrite

lint: docker-image docker-volume
	$(DOCKER_RUN) prototool lint datasets
	$(DOCKER_RUN) prototool format datasets --lint

.PHONY: docker-image docker-volume build fmt lint