robotfs/Makefile
2025-05-28 20:14:40 +08:00

57 lines
1.7 KiB
Makefile

VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
BUILD_TIME := $(shell date "+%Y-%m-%d %H:%M:%S")
LDFLAGS := -X 'gosvc.setVersionNumber=$(VERSION)' \
-X 'gosvc.setVersionRelease=$(BRANCH)' \
-X 'gosvc.setVersionBuildTime=$(BUILD_TIME)' \
-X 'gosvc.setVersionDescription=RobotFS Service (commit: $(COMMIT))'
UNAME_S := $(shell uname -s)
BINARY_NAME := robotfs
.PHONY: all
all: deps proto build
.PHONY: deps
deps:
@echo "Installing project dependencies..."
go mod tidy
.PHONY: proto
proto:
@echo "Generating protobuf files..."
protoc --go_out=. --go_opt=paths=source_relative pb/*.proto
.PHONY: build
build: deps proto
ifeq ($(UNAME_S),Darwin)
@echo "Building for MacOS..."
GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(BINARY_NAME) ./
else
@echo "Building for Linux..."
GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(BINARY_NAME) ./
endif
.PHONY: build-linux
build-linux: deps proto
@echo "Building for Linux..."
GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(BINARY_NAME) ./
.PHONY: clean
clean:
rm -f $(BINARY_NAME)
rm -f pb/*.pb.go
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Generate protobuf files and build for current platform (default)"
@echo " deps - Install project dependencies"
@echo " proto - Generate protobuf files"
@echo " build - Build for current platform"
@echo " build-linux - Build for linux platform"
@echo " clean - Remove built binaries and generated protobuf files"