# Makefile for Mesk Repository Management # Configuration REPO_DIR ?= ./repo PACKAGES_DIR ?= ./packages MESK_BIN ?= ./target/release/mesk BUILD_DIR ?= ./build # Detect if mesk is available in PATH ifeq (, $(shell which mesk 2>/dev/null)) ifneq (, $(wildcard $(MESK_BIN))) MESK := $(MESK_BIN) else MESK := mesk_not_found endif else MESK := $(shell which mesk) endif .PHONY: all build clean validate info help # Default target all: build # Build the repository build: check-mesk @echo "Building repository in $(REPO_DIR) from packages in $(PACKAGES_DIR)" @mkdir -p $(REPO_DIR) $(PACKAGES_DIR) @# Find all .mesk files and copy them to repo @for pkg in $$(find $(PACKAGES_DIR) -name "*.mesk" 2>/dev/null); do \ echo "Processing package: $$pkg"; \ if [ -x "$(MESK)" ]; then \ if $(MESK) validate "$$pkg" 2>/dev/null; then \ cp "$$pkg" $(REPO_DIR)/; \ echo " - Validated and copied $$pkg"; \ else \ echo " - ERROR: $$pkg failed validation"; \ fi; \ else \ cp "$$pkg" $(REPO_DIR)/; \ echo " - Copied $$pkg (validation skipped - mesk not available)"; \ fi; \ done @echo "Generating repository index..." @if [ -x "$(MESK)" ]; then \ $(MESK) gen-index $(REPO_DIR); \ echo "Repository index generated successfully"; \ else \ echo "ERROR: Mesk binary not found. Cannot generate index."; \ exit 1; \ fi @echo "Repository built successfully in $(REPO_DIR)" # Check if mesk is available check-mesk: @if [ "$(MESK)" = "mesk_not_found" ]; then \ echo "ERROR: mesk binary not found in PATH or $(MESK_BIN)"; \ echo "Please build mesk first with: cargo build --release"; \ exit 1; \ fi @echo "Using mesk binary: $(MESK)" # Validate all packages in the source directory validate: check-mesk @echo "Validating all packages in $(PACKAGES_DIR)" @for pkg in $$(find $(PACKAGES_DIR) -name "*.mesk" 2>/dev/null); do \ echo "Validating: $$pkg"; \ if $(MESK) validate "$$pkg"; then \ echo " OK: $$pkg is valid"; \ else \ echo " ERROR: $$pkg is invalid"; \ fi; \ done # Clean the repository directory clean: @echo "Cleaning repository directory: $(REPO_DIR)" @rm -rf $(REPO_DIR)/* @mkdir -p $(REPO_DIR) @echo "Repository cleaned" # Clean everything including build artifacts distclean: clean @echo "Removing build artifacts" @rm -rf target/ # Build mesk if needed build-mesk: @if [ ! -x "$(MESK_BIN)" ]; then \ echo "Building mesk..."; \ cargo build --release; \ else \ echo "Mesk already built"; \ fi # Initialize a new repository structure init: build-mesk @echo "Initializing mesk repository structure..." @mkdir -p $(PACKAGES_DIR) $(REPO_DIR) @echo "Created directories: $(PACKAGES_DIR), $(REPO_DIR)" @touch $(PACKAGES_DIR)/.gitkeep $(REPO_DIR)/.gitkeep @echo "Repository structure initialized" # Show repository information info: check-mesk @echo "=== Repository Info ===" @echo "Repository directory: $(REPO_DIR)" @echo "Packages source: $(PACKAGES_DIR)" @echo "Mesk binary: $(MESK)" @echo "" @echo "Package count: $$(find $(PACKAGES_DIR) -name '*.mesk' 2>/dev/null | wc -l)" @if [ -f "$(REPO_DIR)/INDEX.toml" ]; then \ echo "Index exists with packages:"; \ grep -c "\[\[packages\]\]" $(REPO_DIR)/INDEX.toml 2>/dev/null || echo "0 packages"; \ else \ echo "Index does not exist"; \ fi @echo "" # Install packages to system (DANGEROUS - for testing only) # install: build # @echo "Installing repository packages (DANGEROUS - for testing only)" # @for pkg in $$(find $(REPO_DIR) -name "*.mesk"); do \ # echo "Installing: $$pkg"; \ # $(MESK) install "$$pkg" -p; \ # done help: @echo "Makefile for Mesk Repository Management" @echo "" @echo "Available targets:" @echo " all - Build repository (default)" @echo " build - Build repository from packages in PACKAGES_DIR" @echo " validate - Validate all packages in PACKAGES_DIR" @echo " clean - Clean repository directory" @echo " distclean - Clean everything including build artifacts" @echo " build-mesk - Build mesk binary if not present" @echo " init - Initialize repository structure" @echo " info - Show repository information" @echo " help - Show this help" @echo "" @echo "Variables:" @echo " REPO_DIR - Repository directory (default: ./repo)" @echo " PACKAGES_DIR - Directory with .mesk files (default: ./packages)" @echo " MESK_BIN - Path to mesk binary (default: ./target/release/mesk)" @echo "" @echo "Examples:" @echo " make init # Initialize repository structure" @echo " make # Build repository with defaults" @echo " make REPO_DIR=/tmp/myrepo # Build with custom repo directory" @echo " make validate # Validate all packages"