64 lines
1.7 KiB
Makefile
64 lines
1.7 KiB
Makefile
# 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 -rf debian/.debhelper debian/.gocache debian/go debian/$(BINARY_NAME) debian/files debian/*.substvars debian/debhelper-build-stamp
|
|
rm -f ../$(BINARY_NAME)_*.deb ../$(BINARY_NAME)_*.changes ../$(BINARY_NAME)_*.buildinfo
|
|
rm -f $(BUILD_DIR)/$(BINARY_NAME)
|
|
|
|
# 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
|
|
|
|
# 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 " help - Show this help message"
|