Files
aigrammar/Makefile
2025-07-12 11:38:07 +08:00

48 lines
1.1 KiB
Makefile
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 设置变量
PROJECT_NAME := aigrammar
SRC_DIR := src
BIN_DIR := bin
CONF_DIR := conf
OUTPUT := $(BIN_DIR)/$(PROJECT_NAME)
# Go 编译参数
GO := go
GOFLAGS := -mod=readonly
GOFILES := $(shell find $(SRC_DIR) -name '*.go')
# 默认目标: 构建可执行文件
all: build
# 编译代码
build: $(GOFILES)
@mkdir -p $(BIN_DIR)
$(GO) build -o $(OUTPUT) ./$(SRC_DIR)/...
@echo "✅ Build complete: $(OUTPUT)"
# 运行程序
run: build
$(OUTPUT) --config=$(CONF_DIR)/config.toml
# 清理编译生成的二进制文件
clean:
rm -rf $(BIN_DIR)/$(PROJECT_NAME)
@echo "🗑 Cleaned up $(BIN_DIR)/$(PROJECT_NAME)"
# 格式化 Go 代码
fmt:
$(GO) fmt ./$(SRC_DIR)/...
# 整理 go.mod清理无用依赖
tidy:
$(GO) mod tidy
# 显示帮助信息
help:
@echo "Usage: make [target]"
@echo "Targets:"
@echo " all - 编译 (默认目标)"
@echo " build - 编译 Go 代码"
@echo " run - 运行编译后的程序"
@echo " clean - 删除 bin 目录下生成的可执行文件"
@echo " fmt - 格式化 Go 代码"
@echo " tidy - 整理 go.mod 依赖"