<commit_before>CASHIER_CMD := ./cmd/cashier
CASHIERD_CMD := ./cmd/cashierd
SRC_FILES = $(shell find * -type f -name '*.go' -not -path 'vendor/*' -not -name 'a_*-packr.go')
VERSION_PKG := github.com/nsheridan/cashier/lib.Version
VERSION := $(shell git describe --tags --always --dirty)

GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
CGO_ENABLED ?= $(shell go env CGO_ENABLED)

ifeq ($(GOOS), linux)
LINKER_FLAGS ?= -linkmode external -w -extldflags -static
endif

DOCKER_ARCHS := amd64 arm64 arm
BUILD_DOCKER_ARCHS = $(addprefix docker-,$(DOCKER_ARCHS))
TAG_DOCKER_ARCHS = $(addprefix docker-tag-latest-,$(DOCKER_ARCHS))

DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))

.PHONY: all
all: build

.PHONY: test
test:
	go test -coverprofile=coverage.txt -covermode=count ./...
	go install -race $(CASHIER_CMD) $(CASHIERD_CMD)

.PHONY: lint
lint: dep
	go vet ./...
	go list ./... |xargs -L1 golint -set_exit_status
	gofmt -s -d -l -e $(SRC_FILES)
	$(MAKE) generate
	@[ -z "`git status --porcelain`" ] || (echo "unexpected files: `git status --porcelain`" && exit 1)

.PHONY: build install
build: cashier cashierd
install: install-cashierd install-cashier

.PHONY: generate
generate:
	go generate ./...

%-bin:
	CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) go build -ldflags="-X $(VERSION_PKG)=$(VERSION) $(LINKER_FLAGS)" ./cmd/$*

install-%: generate
	CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) go install -ldflags="-X $(VERSION_PKG)=$(VERSION) $(LINKER_FLAGS)" ./cmd/$*

.PHONY: docker-all-images $(BUILD_DOCKER_ARCHS)
docker-all-images: $(BUILD_DOCKER_ARCHS)
$(BUILD_DOCKER_ARCHS): docker-%:
	docker build --platform linux/$* -t linux-$*:$(DOCKER_IMAGE_TAG) .

.PHONY: docker-tag-all-latest $(TAG_DOCKER_ARCHS)
docker-tag-all-latest: $(TAG_DOCKER_ARCHS)
$(TAG_DOCKER_ARCHS): docker-tag-latest-%:
	docker tag "linux-$*:$(DOCKER_IMAGE_TAG)" "linux-$*:latest"

.PHONY: clean
clean:
	rm -f cashier cashierd

.PHONY: migration
# usage: make migration name=whatever
migration:
	go run ./generate/migration/migration.go $(name)

.PHONY: dep
dep:
	go install golang.org/x/lint/golint@latest

.PHONY: version
version:
	@echo $(VERSION)

.PHONY: cashier cashierd
cashier: cashier-bin
cashierd: cashierd-bin

.PHONY: list-targets
list-targets:
	@LC_ALL=C $(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'<commit_msg>Update Makefile<commit_after>CASHIER_CMD := ./cmd/cashier
CASHIERD_CMD := ./cmd/cashierd
SRC_FILES = $(shell find * -type f -name '*.go' -not -path 'vendor/*' -not -name 'a_*-packr.go')
VERSION_PKG := github.com/nsheridan/cashier/lib.Version
VERSION := $(shell git describe --tags --always --dirty)

GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
CGO_ENABLED ?= $(shell go env CGO_ENABLED)

ifeq ($(GOOS), linux)
LINKER_FLAGS ?= -linkmode external -w -extldflags -static
endif

DOCKER_ARCHS := amd64 arm64 arm
BUILD_DOCKER_ARCHS = $(addprefix docker-,$(DOCKER_ARCHS))
TAG_DOCKER_ARCHS = $(addprefix docker-tag-latest-,$(DOCKER_ARCHS))

DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))

.PHONY: all
all: build

.PHONY: test
test:
	go test -coverprofile=coverage.txt -covermode=count ./...
	go install -race $(CASHIER_CMD) $(CASHIERD_CMD)

.PHONY: lint
lint: dep
	go vet ./...
	go list ./... |xargs -L1 golint -set_exit_status
	gofmt -s -d -l -e $(SRC_FILES)
	$(MAKE) generate
	@[ -z "`git status --porcelain`" ] || (echo "unexpected files: `git status --porcelain`" && exit 1)

.PHONY: build install
build: cashier cashierd
install: install-cashierd install-cashier

.PHONY: generate
generate:
	go generate ./...

%-bin:
	CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) go build -ldflags="-X $(VERSION_PKG)=$(VERSION) $(LINKER_FLAGS)" ./cmd/$*

install-%: generate
	CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) go install -ldflags="-X $(VERSION_PKG)=$(VERSION) $(LINKER_FLAGS)" ./cmd/$*

.PHONY: docker-all-images $(BUILD_DOCKER_ARCHS)
docker-all-images: $(BUILD_DOCKER_ARCHS)
$(BUILD_DOCKER_ARCHS): docker-%:
	docker build --platform linux/$* -t linux-$*:$(DOCKER_IMAGE_TAG) .

.PHONY: docker-tag-all-latest $(TAG_DOCKER_ARCHS)
docker-tag-all-latest: $(TAG_DOCKER_ARCHS)
$(TAG_DOCKER_ARCHS): docker-tag-latest-%:
	docker tag "linux-$*:$(DOCKER_IMAGE_TAG)" "linux-$*:latest"

.PHONY: clean
clean:
	rm -f cashier cashierd

.PHONY: migration
# usage: make migration name=whatever
migration:
	go run ./generate/migration/migration.go $(name)

.PHONY: dep
dep:
	go get -u golang.org/x/lint/golint

.PHONY: version
version:
	@echo $(VERSION)

.PHONY: cashier cashierd
cashier: cashier-bin
cashierd: cashierd-bin

.PHONY: list-targets
list-targets:
	@LC_ALL=C $(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'
{'fraction_non_alphanumeric': 0.1856120826709062, 'fraction_numerical': 0.003577106518282989, 'mean_word_length': 4.446969696969697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2285421', 'n_tokens_mistral': 2103, 'n_tokens_neox': 2030, 'n_words': 482}