deps = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
.PHONY: test
test:
	go test ./...

.PHONY: test-golangci
test-golangci: $(deps-go)
	# https://www.jvt.me/posts/2024/09/30/go-tools-module/
	go run -mod=mod -modfile=tools/go.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint run ./...

.PHONY: test-pre-commit
test-pre-commit: test test-golangci
	go mod tidy -diff

.PHONY: build
build: staticomm
staticomm: $(deps)
	go build ./cmd/staticomm/

ifdef SYSTEM
PREFIX := $(DESTDIR)/usr
else ifdef USER_LOCAL
PREFIX := $(DESTDIR)$(HOME)/.local
else
PREFIX := $(DESTDIR)/usr/local
endif

BIN_DIR := $(PREFIX)/bin

.PHONY: install
install: staticomm
	install -vDm 0755 staticomm -t $(BIN_DIR)

.PHONY: uninstall
uninstall:
	rm -vf $(BIN_DIR)/staticomm

.PHONY: link
link:
	ln -sf $(CURDIR)/staticomm $(BIN_DIR)/staticomm

.PHONY: release
release:
	./bin/generate_release_notes
	sh -c "git tag $$(./bin/generate_release_notes | head -n1) --annotate --sign --file <(./bin/generate_release_notes)"
	./bin/generate_obs_changes > ~/code/home:jcgl/staticomm/staticomm.changes
