# Router Backup Tool Makefile # Variables BINARY_NAME=ipng-router-backup SOURCE_DIR=src BUILD_DIR=. GO_FILES=$(SOURCE_DIR)/main.go # Default target .PHONY: all all: build # Sync version from debian/changelog to Go source .PHONY: sync-version sync-version: @echo "Syncing version from debian/changelog..." @VERSION=$$(head -1 debian/changelog | sed 's/.*(\([^)]*\)).*/\1/'); \ sed -i "s/const Version = \".*\"/const Version = \"$$VERSION\"/" $(SOURCE_DIR)/main.go; \ echo "Version synced: $$VERSION" # Build the Go binary .PHONY: build build: sync-version @echo "Building $(BINARY_NAME)..." cd $(SOURCE_DIR) && go build -o ../$(BUILD_DIR)/$(BINARY_NAME) main.go @echo "Build complete: $(BINARY_NAME)" # Clean build artifacts .PHONY: clean clean: @echo "Cleaning build artifacts..." rm -f $(BUILD_DIR)/$(BINARY_NAME) @echo "Clean complete" # Run tests .PHONY: test test: @echo "Running tests..." cd $(SOURCE_DIR) && go test -v . # Format Go code .PHONY: fmt fmt: @echo "Formatting Go code..." cd $(SOURCE_DIR) && go fmt ./... # Build Debian package .PHONY: pkg-deb pkg-deb: sync-version build fakeroot dpkg-buildpackage -us -uc -b # Clean package artifacts .PHONY: clean-pkg clean-pkg: @echo "Cleaning package artifacts..." @rm -f *.deb @echo "Package cleanup complete" # Show help .PHONY: help help: @echo "Available targets:" @echo " build - Build the router_backup binary" @echo " clean - Remove build artifacts" @echo " test - Run tests" @echo " fmt - Format Go code" @echo " sync-version - Sync version from debian/changelog to Go source" @echo " pkg-deb - Create Debian package" @echo " clean-pkg - Remove package artifacts" @echo " help - Show this help message"