PROG = govpp-snmp-agentx

.PHONY: build test clean pkg-deb sync-version

# Build the binary
build:
	cd src && go build -o ../$(PROG) .

# Run all tests
test:
	cd src && go test ./...

# Clean build artifacts
clean:
	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
