Rework build system; cut release 1.3.1-1

Replace the dpkg-buildpackage / debhelper rig with the same pattern
used in vpp-maglev: 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 'govpp-snmp-agentx --version' is the source of
truth for which build is running. main.go's Version constant becomes
a var to make this work; the old sync-version make target is gone.

Removes the now-unused debian/{control,rules,postinst,prerm,*.debhelper}
files and adds build/ to .gitignore.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-06 18:42:58 +02:00
parent eeb827665a
commit b17396b1e5
14 changed files with 145 additions and 134 deletions
+40 -23
View File
@@ -1,29 +1,46 @@
PROG = govpp-snmp-agentx
PROG := govpp-snmp-agentx
MODULE := govpp-snmp-agentx
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)'
.PHONY: build test clean pkg-deb sync-version
# CGO_ENABLED=0 produces a fully static binary: the same .deb runs on
# any glibc/musl Linux of the matching arch, and govpp itself has no
# cgo dependency, so this is a no-op for VPP API compatibility.
export CGO_ENABLED := 0
# Build the binary
build:
cd src && go build -o ../$(PROG) .
.PHONY: help all build build-amd64 build-arm64 test pkg-deb clean
# Run all tests
test:
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)
cd src && go build -ldflags "$(LDFLAGS)" -o ../build/$(NATIVE_ARCH)/$(PROG) .
build-amd64: ## Cross-build the binary for linux/amd64
mkdir -p build/amd64
cd src && GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ../build/amd64/$(PROG) .
build-arm64: ## Cross-build the binary for linux/arm64
mkdir -p build/arm64
cd src && GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o ../build/arm64/$(PROG) .
test: ## Run all Go unit tests
cd src && go test ./...
# Clean build artifacts
clean:
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)
clean: ## Remove build artifacts
rm -rf build/
rm -f $(PROG)
[ -d debian/go ] && chmod -R +w debian/go || true
rm -rf debian/.debhelper debian/.gocache debian/go debian/$(PROG) debian/files debian/*.substvars debian/debhelper-build-stamp
rm -f ../$(PROG)_*.deb ../$(PROG)_*.changes ../$(PROG)_*.buildinfo
# Sync version from debian/changelog to main.go
sync-version:
@echo "Syncing version from debian/changelog to main.go..."
@VERSION=$$(head -1 debian/changelog | sed -n 's/.*(\([^)]*\)).*/\1/p'); \
sed -i 's/^const Version = ".*"/const Version = "'"$$VERSION"'"/' src/main.go; \
echo "Updated Version const to: $$VERSION"
# Build Debian package
pkg-deb: sync-version
fakeroot dpkg-buildpackage -us -uc -b