Files
s3-genindex/Makefile
T
pim 312e9245f8 Rework build system
Replace the dpkg-buildpackage / debhelper rig with the same pattern
used in vpp-maglev and govpp-snmp-agentx: a Makefile that
cross-compiles CGO-free static binaries for amd64 and arm64, plus a
debian/build-deb.sh that stages the .deb directly with dpkg-deb. The
two arch packages drop into build/ and run on any glibc/musl Linux of
the matching arch.

VERSION is parsed once from debian/changelog and injected at link
time via -ldflags "-X 'main.Version=...' -X 'main.Commit=...' -X
'main.Date=...'", so 's3-genindex -version' is the source of truth
for which build is running. The Version constant in main.go becomes
a var to make this work; the old sync-version make target is gone.

Removes the now-unused debian/{control,rules,install,compat} files
and the matching debhelper artifact entries from .gitignore. build/
is added to .gitignore.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 20:11:55 +02:00

60 lines
2.2 KiB
Makefile

PROG := s3-genindex
MODULE := git.ipng.ch/ipng/s3-genindex
NATIVE_ARCH := $(shell go env GOARCH)
VERSION := ${shell head -1 debian/changelog | sed -n 's/.*(\([^)]*\)).*/\1/p'}
COMMIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w \
-X 'main.Version=$(VERSION)' \
-X 'main.Commit=$(COMMIT_HASH)' \
-X 'main.Date=$(DATE)'
# CGO_ENABLED=0 yields a fully static binary so the same .deb runs on
# any glibc/musl Linux of the matching arch. The AWS SDK and the rest
# of this codebase are pure Go, so this has no behavioural impact
# beyond switching net/dns to the pure-Go resolver.
export CGO_ENABLED := 0
.PHONY: help all build build-amd64 build-arm64 test pkg-deb fmt vet lint check clean
help: ## Show this help
@printf "Usage: make <target>\n\nTargets:\n"
@awk -F ':.*## ' '/^[A-Za-z][A-Za-z0-9_-]*:.*## / {printf " %-16s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
all: build ## Alias for build (native arch)
build: ## Build the binary for the host architecture
mkdir -p build/$(NATIVE_ARCH)
go build -ldflags "$(LDFLAGS)" -o build/$(NATIVE_ARCH)/$(PROG) ./cmd/$(PROG)
build-amd64: ## Cross-build the binary for linux/amd64
mkdir -p build/amd64
GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o build/amd64/$(PROG) ./cmd/$(PROG)
build-arm64: ## Cross-build the binary for linux/arm64
mkdir -p build/arm64
GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o build/arm64/$(PROG) ./cmd/$(PROG)
test: ## Run all Go unit tests
go test ./...
pkg-deb: build-amd64 build-arm64 ## Build .deb packages for amd64 and arm64
debian/build-deb.sh $(PROG) amd64 $(VERSION)
debian/build-deb.sh $(PROG) arm64 $(VERSION)
fmt: ## go fmt everything
go fmt ./...
vet: ## go vet everything
go vet ./...
lint: ## golangci-lint, if installed
@if command -v golangci-lint >/dev/null 2>&1; then golangci-lint run; else echo "golangci-lint not installed, skipping"; fi
check: fmt vet lint test ## Format, vet, lint, and test
clean: ## Remove build artifacts
rm -rf build/
rm -f $(PROG) coverage.out coverage.html
find . -name index.html -delete