11SHELL := /usr/bin/env bash
22APP := structlint
33BIN := bin/$(APP )
4- PKG := github.com/youngestaxe/structlint
4+ PKG := github.com/AxeForging/structlint
5+ DIST_DIR := dist
6+
7+ # Cross-compilation targets
8+ GOOS_ARCH := linux/amd64 linux/arm64 linux/386 linux/arm darwin/amd64 darwin/arm64 windows/amd64 windows/arm64 windows/386
9+
10+ # Version information - can be overridden by environment variable
11+ ifeq ($(origin VERSION ) , environment)
12+ # VERSION is set from environment
13+ else
14+ VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
15+ endif
16+
17+ BUILD_TIME := $(shell date -u '+% Y-% m-% dT% H:% M:% SZ')
18+ GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
19+ BUILT_BY := $(shell whoami)
20+
21+ # Build flags
522LDFLAGS := -s -w \
6- -X $(PKG ) /internal/build.Version=$$( git describe --tags --always --dirty ) \
7- -X $(PKG ) /internal/build.Commit=$$( git rev-parse --short HEAD ) \
8- -X $(PKG ) /internal/build.Date=$$( date -u +%Y-%m-%dT%H:%M:%SZ ) \
9- -X $(PKG ) /internal/build.BuiltBy=$$( whoami )
23+ -X $(PKG ) /internal/build.Version=$( VERSION ) \
24+ -X $(PKG ) /internal/build.Commit=$( GIT_COMMIT ) \
25+ -X $(PKG ) /internal/build.Date=$( BUILD_TIME ) \
26+ -X $(PKG ) /internal/build.BuiltBy=$( BUILT_BY )
1027
11- .PHONY : all build run test test-self lint tidy clean completion validate-self
28+ .PHONY : all build build-all run test test-self lint tidy clean completion validate-self fmt format check ci version tag release-check
1229
1330all : build
1431
32+ # Build for current platform
1533build :
1634 @mkdir -p bin
17- GOFLAGS=" -trimpath" CGO_ENABLED=0 go build -ldflags " $( LDFLAGS) " -o $(BIN ) ./cmd/$(APP )
35+ CGO_ENABLED=0 go build -trimpath -ldflags " $( LDFLAGS) " -o $(BIN ) ./cmd/$(APP )
36+ @echo " Built $( BIN) ($( VERSION) )"
37+
38+ # Build for all platforms
39+ build-all :
40+ @echo " Building binaries for all platforms..."
41+ @echo " Version: $( VERSION) "
42+ @echo " Build time: $( BUILD_TIME) "
43+ @echo " Git commit: $( GIT_COMMIT) "
44+ @mkdir -p $(DIST_DIR )
45+ @for t in $(GOOS_ARCH ) ; do \
46+ os=$$ {t%/* }; arch=$$ {t#* /}; \
47+ bin_name=$(APP ) -$$ {os}-$$ {arch}; \
48+ if [ " $$ os" = " windows" ]; then bin_name=" $$ {bin_name}.exe" ; fi ; \
49+ bin_path=$(DIST_DIR ) /$$ bin_name; \
50+ echo " Building for $$ os/$$ arch..." ; \
51+ CGO_ENABLED=0 GOOS=$$ os GOARCH=$$ arch go build -trimpath -ldflags " $( LDFLAGS) " -o $$ bin_path ./cmd/$(APP ) ; \
52+ done
53+ @echo " Build complete. Binaries in $( DIST_DIR) /"
1854
1955run : build
2056 @$(BIN ) $(ARGS )
2157
2258test :
23- go test ./...
59+ go test ./... -v
2460
2561test-self : build
26- @echo " 🔍 Validating our own project structure..."
62+ @echo " Validating our own project structure..."
2763 @$(BIN ) validate --config .structlint.yaml --json-output validation-report.json
28- @echo " 📊 Validation report saved to validation-report.json"
64+ @echo " Validation report saved to validation-report.json"
2965
3066lint :
3167 golangci-lint run --timeout=5m
@@ -34,25 +70,49 @@ tidy:
3470 go mod tidy
3571
3672clean :
37- rm -rf bin validation-report.json
73+ rm -rf bin $( DIST_DIR ) validation-report.json * .json
3874
39- completion :
40- @mkdir -p dist/completion
41- @$(BIN ) completion bash > dist/completion/$(APP ) .bash
42- @$(BIN ) completion zsh > dist/completion/_$(APP )
43- @$(BIN ) completion fish > dist/completion/$(APP ) .fish
75+ completion : build
76+ @mkdir -p $(DIST_DIR ) /completion
77+ @$(BIN ) completion bash > $(DIST_DIR ) /completion/$(APP ) .bash
78+ @$(BIN ) completion zsh > $(DIST_DIR ) /completion/_$(APP )
79+ @$(BIN ) completion fish > $(DIST_DIR ) /completion/$(APP ) .fish
80+ @echo " Shell completions generated in $( DIST_DIR) /completion/"
4481
4582validate-self : test-self
4683
4784# Development helpers
4885fmt :
4986 go fmt ./...
50- goimports -w .
5187
5288format : fmt
53- gofumpt -w .
89+ @command -v gofumpt > /dev/null 2>&1 && gofumpt -w . || echo " gofumpt not installed, skipping"
90+ @command -v goimports > /dev/null 2>&1 && goimports -w . || echo " goimports not installed, skipping"
5491
5592check : lint test
5693
5794# CI/CD helpers
5895ci : tidy check build test-self
96+
97+ # Version information
98+ version :
99+ @echo " Version: $( VERSION) "
100+ @echo " Build time: $( BUILD_TIME) "
101+ @echo " Git commit: $( GIT_COMMIT) "
102+ @echo " Built by: $( BUILT_BY) "
103+
104+ # Create a git tag for release
105+ tag :
106+ @if [ " $( VERSION) " = " dev" ]; then \
107+ echo " Error: Cannot tag dev version. Set VERSION env var (e.g., VERSION=v1.0.0 make tag)" ; \
108+ exit 1; \
109+ fi
110+ @echo " Creating git tag: $( VERSION) "
111+ git tag -a $(VERSION ) -m " Release $( VERSION) "
112+ @echo " Tag created. Push with: git push origin $( VERSION) "
113+
114+ # Build and test before release
115+ release-check : build-all
116+ @echo " Running tests..."
117+ go test ./... -v
118+ @echo " All tests passed. Ready for release $( VERSION) "
0 commit comments