.DEFAULT_GOAL := build
.PHONY: build docs fmt lint cli test clean coverage sloc


VERSION := $(shell grep -o 'const Version = "[^"]*' internal/version/version.go | cut -d '"' -f 2)


build:
	CGO_ENABLED="1" go build -o lib/libeduvpn_common-${VERSION}.so -buildmode=c-shared ./exports

fmt:
	gofumpt -w .

lint:
	golangci-lint run -E staticcheck,revive,gocritic ./...

gen:
	go generate ./...

update:
	GOPROXY=direct go get -u ./...
	go mod tidy

cli:
	go build ./cmd/eduvpn-cli

docs:
	mkdocs build -f docs/mkdocs.yml

docs-mermaid:
	 find docs/md -iname "*.mmd" -exec mmdc -t neutral -b transparent -i {} -o {}.svg \;

test:
	go test -tags=cgotesting -race -v ./...

clean:
	rm -rf lib
	go clean

coverage:
	go test -tags=cgotesting -v -coverpkg=./... -coverprofile=common.cov ./...
	go tool cover -func common.cov

sloc:
	tokei --exclude "*_test.go" -t=Go . || cloc --include-ext=go --not-match-f='_test.go' .
