-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathMakefile
More file actions
165 lines (139 loc) · 5.32 KB
/
Copy pathMakefile
File metadata and controls
165 lines (139 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
MODULE_PATH := github.com/mozilla-ai/mcpd
# /usr/local/bin is a common default for user-installed binaries
INSTALL_DIR := /usr/local/bin
# Target platform for local Docker builds (matches Docker buildx platform format)
TARGET_PLATFORM := linux/amd64
# Get the version string dynamically
# This will be:
# - e.g., "v1.0.0" if on a tag
# - e.g., "v0.1.0-2-gabcdef123" if 2 commits past tag v0.1.0 (with hash abcdef123)
# - e.g., "abcdef123-dirty" if on a commit and dirty
# - e.g., "dev" if git is not available or no commits yet
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
# Get commit hash and date
COMMIT := $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Linker flags for injecting version and optimizations
# The path is MODULE_PATH/package.variableName
LDFLAGS := -s -w -X '$(MODULE_PATH)/internal/cmd.version=$(VERSION)' \
-X '$(MODULE_PATH)/internal/cmd.commit=$(COMMIT)' \
-X '$(MODULE_PATH)/internal/cmd.date=$(DATE)'
# Build flags for optimization
BUILDFLAGS := -trimpath
# The license types allowed to be imported by the project
ALLOWED_LICENSES := Apache-2.0,MIT,BSD-2-Clause,BSD-3-Clause,ZeroBSD,Unlicense
.PHONY: check-licenses
check-licenses:
@echo "Checking licenses..."
@go install github.com/google/go-licenses/v2@latest
@set -e; \
if go-licenses check ./... --ignore github.com/mozilla-ai/mcpd --allowed_licenses=$(ALLOWED_LICENSES); then \
echo "✓ All licenses are allowed."; \
else \
echo "License check failed: some dependencies have disallowed licenses."; \
exit 1; \
fi
.PHONY: check-notice
check-notice:
@echo "Checking NOTICE..."
@go install github.com/google/go-licenses/v2@latest
@tmp=$$(mktemp); \
trap "rm -f $$tmp" EXIT; \
go-licenses report ./... --ignore github.com/mozilla-ai/mcpd --template build/licenses/notice.tpl > $$tmp; \
if ! cmp -s NOTICE $$tmp; then \
echo "NOTICE is out of date. Regenerate it with 'make notice'"; \
exit 1; \
else \
echo "✓ NOTICE is up to date"; \
fi
.PHONY: notice
notice:
@echo "Generating NOTICE..."
@go install github.com/google/go-licenses/v2@latest
@go-licenses report ./... --ignore github.com/mozilla-ai/mcpd --template build/licenses/notice.tpl > NOTICE
@echo "✓ NOTICE generated"
.PHONY: lint
lint: check-notice
golangci-lint run --fix -v
.PHONY: test
test: lint
go test ./...
.PHONY: validate-registry
validate-registry:
@echo "Validating Mozilla AI registry against schema..."
@go run -tags=validate_registry ./tools/validate/registry.go \
internal/provider/mozilla_ai/data/schema.json \
internal/provider/mozilla_ai/data/registry.json
.PHONY: build
build: lint
@echo "building mcpd (version: $(VERSION), commit: $(COMMIT))..."
@go build $(BUILDFLAGS) -o mcpd -ldflags="$(LDFLAGS)" .
.PHONY: build-linux
build-linux:
@echo "building mcpd for amd64/linux (version: $(VERSION), commit: $(COMMIT))..."
@GOOS=linux GOARCH=amd64 go build $(BUILDFLAGS) -o mcpd -ldflags="$(LDFLAGS)" .
.PHONY: build-linux-arm64
build-linux-arm64:
@echo "building mcpd for arm64/linux (version: $(VERSION), commit: $(COMMIT))..."
@GOOS=linux GOARCH=arm64 go build $(BUILDFLAGS) -o mcpd -ldflags="$(LDFLAGS)" .
# For development builds without optimizations (for debugging)
.PHONY: build-dev
build-dev:
@echo "building mcpd for development (version: $(VERSION), commit: $(COMMIT))..."
@go build -o mcpd -ldflags="-X '$(MODULE_PATH)/internal/cmd.version=$(VERSION)' \
-X '$(MODULE_PATH)/internal/cmd.commit=$(COMMIT)' \
-X '$(MODULE_PATH)/internal/cmd.date=$(DATE)'" .
.PHONY: install
install: build
@# Copy the executable to the install directory
@# Requires sudo if INSTALL_DIR is a system path like /usr/local/bin
@echo "installing mcpd to $(INSTALL_DIR)..."
@cp mcpd $(INSTALL_DIR)/mcpd
@chmod +x $(INSTALL_DIR)/mcpd
.PHONY: clean
clean:
@# Remove the built executable and any temporary files
@echo "cleaning up local build artifacts..."
@rm -f mcpd # The executable itself
@rm -rf $(TARGET_PLATFORM) # Remove any orphaned Docker build directories
.PHONY: uninstall
uninstall:
@# Remove the installed executable from the system
@# Requires sudo if INSTALL_DIR is a system path
@echo "uninstalling mcpd from $(INSTALL_DIR)..."
@rm -f $(INSTALL_DIR)/mcpd
# Runs MkDocs locally
.PHONY: docs
docs: docs-nav docs-api
@uv venv && \
source .venv/bin/activate && \
uv pip install mkdocs mkdocs-material && \
uv run mkdocs serve
# Generates CLI markdown documentation
.PHONY: docs-cli
docs-cli:
@go run -tags=docsgen_cli ./tools/docsgen/cmds/main.go
@echo "mcpd CLI command documentation generated"
# Generates OpenAPI specification YAML
.PHONY: docs-api
docs-api:
@go run -tags=docsgen_api ./tools/docsgen/api/openapi.go
@echo "OpenAPI specification generated"
## Updates mkdocs.yaml nav to match generated CLI docs
.PHONY: docs-nav
docs-nav: docs-cli
@go run -tags=docsgen_nav ./tools/docsgen/nav/main.go
@echo "navigation updated for MkDocs site"
.PHONY: local-up
local-up: build-linux
@echo "organizing binary for docker build"
@mkdir -p $(TARGET_PLATFORM)
@cp mcpd $(TARGET_PLATFORM)/mcpd
@echo "starting mcpd container in detached state"
@TARGETPLATFORM=$(TARGET_PLATFORM) docker compose up -d --build
@echo "cleaning up temporary platform directory"
@rm -rf $(TARGET_PLATFORM)
.PHONY: local-down
local-down:
@echo "stopping mcpd container"
@docker compose down