This repository was archived by the owner on Apr 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMakefile
More file actions
144 lines (126 loc) · 3.99 KB
/
Makefile
File metadata and controls
144 lines (126 loc) · 3.99 KB
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
.DEFAULT_GOAL := help
STOW_DIR := opencode
TARGET := $(HOME)/.config/opencode
STOW := $(shell command -v stow 2>/dev/null)
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Installation
.PHONY: check
check: ## Verify setup
@test -d $(STOW_DIR) || (echo "Error: $(STOW_DIR) directory not found" && exit 1)
ifdef STOW
@echo "✓ Using stow: $(STOW)"
@test -f .stowrc || (echo "Warning: .stowrc not found")
else
@echo "⚠ stow not found - will use ln -s instead"
endif
@echo "✓ Setup verified"
.PHONY: install
install: check ## Install opencode configuration
@mkdir -p $(TARGET)
ifdef STOW
@echo "Installing with stow..."
@stow */ || (echo "✗ Stow failed - check for conflicts" && exit 1)
else
@echo "Installing with ln -s..."
@$(MAKE) -s install-ln
endif
@echo "✓ Installation complete"
.PHONY: install-ln
install-ln: ## Install using ln -s (internal)
@mkdir -p $(TARGET)
@for dir in $(STOW_DIR)/*/; do \
package=$$(basename "$$dir"); \
target_link="$(TARGET)/$$package"; \
if [ -e "$$target_link" ] && [ ! -L "$$target_link" ]; then \
echo " ✗ $$package exists and is not a symlink - skipping"; \
else \
ln -sfn "$(CURDIR)/$$dir" "$$target_link"; \
echo " ✓ $$package"; \
fi; \
done
.PHONY: uninstall
uninstall: ## Uninstall opencode configuration
ifdef STOW
@echo "Uninstalling with stow..."
@stow -D */ 2>/dev/null || true
else
@echo "Removing symlinks..."
@$(MAKE) -s uninstall-ln
endif
@echo "✓ Uninstallation complete"
.PHONY: uninstall-ln
uninstall-ln: ## Uninstall using rm (internal)
@for dir in $(STOW_DIR)/*/; do \
package=$$(basename "$$dir"); \
target_link="$(TARGET)/$$package"; \
if [ -L "$$target_link" ]; then \
echo " Removing $$package..."; \
rm -f "$$target_link"; \
fi; \
done
.PHONY: restow
restow: ## Restow opencode configuration
ifdef STOW
@echo "Restowing with stow..."
@stow -R */ || (echo "✗ Restow failed - check for conflicts" && exit 1)
else
@echo "Refreshing symlinks..."
@$(MAKE) -s uninstall-ln install-ln
endif
@echo "✓ Restow complete"
##@ Utilities
.PHONY: status
status: ## Show installation status
@echo "Installation method: $(if $(STOW),stow,ln -s)"
@echo "Target: $(TARGET)"
@echo ""
@echo "Installed packages:"
@if [ -d "$(TARGET)" ]; then \
for link in $(TARGET)/*; do \
if [ -L "$$link" ]; then \
target=$$(readlink "$$link"); \
echo " ✓ $$(basename $$link) -> $$target"; \
elif [ -e "$$link" ]; then \
echo " ⚠ $$(basename $$link) (not a symlink)"; \
fi; \
done | sort; \
else \
echo " Not installed"; \
fi
.PHONY: list
list: ## List available packages
@echo "Available packages:"
@ls -d $(STOW_DIR)/*/ 2>/dev/null | sed 's|$(STOW_DIR)/||g; s|/$$||' | sed 's/^/ /' || echo " None found"
.PHONY: clean
clean: ## Remove broken symlinks in target
@echo "Cleaning broken symlinks in $(TARGET)..."
@find $(TARGET) -xtype l -delete 2>/dev/null || true
@echo "✓ Cleanup complete"
.PHONY: install-all
install-all: install ## Install everything
@echo ""
@echo "✓ Complete installation finished"
.PHONY: uninstall-all
uninstall-all: uninstall ## Uninstall everything
@echo ""
@echo "✓ Complete uninstallation finished"
##@ Pre-commit hooks
.PHONY: install-hooks
install-hooks: ## Install pre-commit hooks
@command -v pre-commit >/dev/null 2>&1 || \
(echo "❌ pre-commit not installed. Install with: pip install pre-commit" && exit 1)
@pre-commit install
@echo "✓ Pre-commit hooks installed"
.PHONY: uninstall-hooks
uninstall-hooks: ## Uninstall pre-commit hooks
@pre-commit uninstall
@echo "✓ Pre-commit hooks uninstalled"
.PHONY: run-hooks
run-hooks: ## Run pre-commit hooks manually
@pre-commit run --all-files
.PHONY: update-hooks
update-hooks: ## Update pre-commit hooks to latest versions
@pre-commit autoupdate
@echo "✓ Pre-commit hooks updated"