.PHONY: all test build docker install clean proto check_protoc CMD_NAME := go-server-with-otel VERSION ?= development API_DIR := api/ SCHEMA_DIR := contrib/ PROTO_DIRS := $(wildcard proto/demo/app/*) # TODO: Update path (probably not demo) PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 OUTPUT_DIR := bin VER_PKG := gitea.libretechconsulting.com/rmcguire/go-app/pkg/config.Version GIT_REPO := gitea.libretechconsulting.com/rmcguire/go-server-with-otel all: proto test build docker proto: check_protoc $(API_DIR) protoc --proto_path=proto --proto_path=proto/google \ --go_out=$(API_DIR) --go_opt=paths=source_relative \ --go-grpc_out=$(API_DIR) --go-grpc_opt=paths=source_relative \ --grpc-gateway_out=$(API_DIR) --grpc-gateway_opt=paths=source_relative \ --openapiv2_out=$(SCHEMA_DIR) \ --openapiv2_opt allow_merge=true \ --openapiv2_opt merge_file_name=$(CMD_NAME) \ $(foreach dir, $(PROTO_DIRS), $(wildcard $(dir)/*.proto)) test: go test -v ./... build: test @echo "Building for platforms: $(PLATFORMS)" @for platform in $(PLATFORMS); do \ OS=$$(echo $$platform | cut -d/ -f1); \ ARCH=$$(echo $$platform | cut -d/ -f2); \ OUTPUT="$(OUTPUT_DIR)/$(CMD_NAME)-$$OS-$$ARCH"; \ mkdir -vp $(OUTPUT_DIR); \ echo "Building for $$platform into $$OUTPUT"; \ GOOS=$$OS GOARCH=$$ARCH go build -ldflags "-X $(VER_PKG)=$(VERSION)" -o $$OUTPUT .; \ echo "Built $$OUTPUT"; \ done go build -ldflags "-X $(VER_PKG)=$(VERSION)" -o bin/${CMD_NAME} schema: go run . -schema > contrib/schema.json docker: @echo "Building Docker image $(GIT_REPO):$(VERSION)" docker build \ --build-arg VER_PKG=$(VER_PKG) \ --build-arg VERSION=$(VERSION) \ --build-arg APP_NAME=$(CMD_NAME) \ -t $(GIT_REPO):$(VERSION) . docker push $(GIT_REPO):$(VERSION) install: go install -v -ldflags "-X $(VER_PKG)=$(VERSION)" . clean: rm -rf bin/${CMD_NAME} check_protoc: @if ! command -v protoc-gen-go > /dev/null; then \ echo "Error: protoc-gen-go not found in PATH"; \ exit 1; \ fi @if ! command -v protoc-gen-go-grpc > /dev/null; then \ echo "Error: protoc-gen-go-grpc not found in PATH"; \ exit 1; \ fi rename: @echo "Current module path: $(GIT_REPO)" @echo "Usage: make rename NAME=your/new/module/name" @if [ -z "$(NAME)" ]; then \ echo "No name provided. Aborting."; \ exit 1; \ fi @echo "New name: $(NAME)" @echo "Are you sure you want to proceed? (y/N): " && read CONFIRM && if [ "$$CONFIRM" != "y" ] && [ "$$CONFIRM" != "Y" ]; then \ echo "Aborted."; \ exit 1; \ fi @find . -type f -a \ \( -name '*.go' -o -name 'go.mod' \ -o -name 'go.sum' -o -name '*.proto' \ -o -name 'Makefile' \ -o -name '*.yml' -o -name '*.yaml' \ \) \ -not -path './.git' -not -path './.git/*' \ -exec sed -i "s|$(GIT_REPO)|$(NAME)|g" {} + @echo "Project renamed to $(NAME)"