summaryrefslogtreecommitdiff
path: root/Makefile
blob: c39a47cc220b87591e4cdac48040fcc272e7efc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# 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"