BUILD_DATE = $(shell date +%F-%Z/%T)
TAG=$(shell git describe --tags --abbrev=0)
GO_VERSION=$(shell go version)
GO_VERS := $(shell echo "${GO_VERSION}" | sed -e 's/ /_/g')
build:
	clear
	mkdir -p ./bin/web/static
	mkdir -p ./bin/web/tmpl
	cp -r ./web ./bin
	# cp ./util/store.so ./bin/store.so
	go fmt ./...
	go build -ldflags "-w -s -X main.GoVersion=$(GO_VERS) -X main.Version=${TAG} -X main.Date=${BUILD_DATE}" -o ./bin/server ./cmd/server/main.go
	strip -s ./bin/server
	upx -f ./bin/server
prod2:
	clear
	mkdir -p ./bin2/web/static
	mkdir -p ./bin2/web/tmpl
	cp -r ./web ./bin2
	# cp ./util/store.so ./bin2/store.so
	go fmt ./...
	go build -ldflags "-X main.GoVersion=${GO_VERS} -X main.Version=${TAG} -X main.Date=${BUILD_DATE}" -o ./bin2/server2 ./cmd/server/main.go
	strip -s ./bin2/server2
	upx -f ./bin2/server2
dev.run:
	clear
	rm -rdf ./bin_dev
	mkdir -p ./bin_dev/web/static
	mkdir -p ./bin_dev/web/tmpl
	cp -r ./web ./bin_dev
	go fmt ./...
	# go build -race -o ./bin_dev/wartank_dev ./cmd/server/main.go
	go build -ldflags "-w -s -X main.GoVersion=$(GO_VERS) -X main.Version=${TAG} -X main.Date=${BUILD_DATE}" -o ./bin_dev/wartank_dev ./cmd/server/main.go
	./run_dev.sh
debug.run:
	clear
	cp -r ./web ./bin_dev
	go fmt ./...
	# go build -race -o ./bin_dev/wartank_dev ./cmd/server/main.go
	go build -ldflags "-w -s -X main.GoVersion=$(GO_VERS) -X main.Version=${TAG} -X main.Date=${BUILD_DATE}" -o ./bin_dev/wartank_dev ./cmd/server/main.go
	./debug.sh
prod.run:
	clear
	go fmt ./...
	go build -o ./bin/wartank ./cmd/server/main.go
	./run_prod.sh
test.run:
	clear
	go fmt ./...
	go test -shuffle=on -vet=all -race -timeout 30s -coverprofile cover.out ./...
	go tool cover -func=cover.out
mod:
	clear
	go get -u ./...
	go mod tidy -compat=1.22.4
	go mod vendor
	go fmt ./...
lint:
	clear
	go fmt ./...
	golangci-lint run ./cmd/server/...
	golangci-lint run ./pkg/...
	golangci-lint run ./server/...
