diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b745a24 --- /dev/null +++ b/Makefile @@ -0,0 +1,93 @@ +SHELL := /bin/bash +.ONESHELL: +.SHELLFLAGS := -euo pipefail -c + +ROOT_DIR := $(CURDIR) +TOOLS_TXT := tools.txt +AGENTS_TXT := agents.txt +BIN_DIR := bin +TOOLS_DIR := tools +SCRIPTS_DIR := scripts + +.PHONY: all build fix-links fix-bin-links fix-tools-links check clean rebuild + +all: build fix-links + +build: + @if ! command -v argc >/dev/null 2>&1; then \ + echo "ERROR: argc not found. Install it first (e.g. cargo install --locked argc)"; \ + exit 1; \ + fi + @echo "[1/2] argc build" + argc build + +fix-links: fix-bin-links fix-tools-links + @echo "[OK] links fixed" + +fix-bin-links: + @echo "[2/2] fixing bin/ symlinks to relative targets" + @mkdir -p "$(BIN_DIR)" + @chmod +x "$(SCRIPTS_DIR)/run-tool.sh" "$(SCRIPTS_DIR)/run-agent.sh" 2>/dev/null || true + + @if [[ -f "$(TOOLS_TXT)" ]]; then \ + while IFS= read -r line || [[ -n "$$line" ]]; do \ + line="$${line%%#*}"; \ + line="$$(printf "%s" "$$line" | sed -E 's/^[[:space:]]+|[[:space:]]+$$//g')"; \ + [[ -z "$$line" ]] && continue; \ + name="$${line%.sh}"; \ + ln -sfn "../$(SCRIPTS_DIR)/run-tool.sh" "$(BIN_DIR)/$$name"; \ + done < "$(TOOLS_TXT)"; \ + else \ + echo "WARN: $(TOOLS_TXT) not found; skipping tool links"; \ + fi + + @if [[ -f "$(AGENTS_TXT)" ]]; then \ + while IFS= read -r line || [[ -n "$$line" ]]; do \ + line="$${line%%#*}"; \ + line="$$(printf "%s" "$$line" | sed -E 's/^[[:space:]]+|[[:space:]]+$$//g')"; \ + [[ -z "$$line" ]] && continue; \ + name="$${line%.sh}"; \ + ln -sfn "../$(SCRIPTS_DIR)/run-agent.sh" "$(BIN_DIR)/$$name"; \ + done < "$(AGENTS_TXT)"; \ + else \ + echo "WARN: $(AGENTS_TXT) not found; skipping agent links"; \ + fi + + @abs="$$(find "$(BIN_DIR)" -maxdepth 1 -type l -print0 2>/dev/null | \ + xargs -0 -I{} bash -lc 't=$$(readlink "{}"); [[ "$$t" == /* ]] && echo "{} -> $$t" || true' || true)"; \ + if [[ -n "$$abs" ]]; then \ + echo "WARN: absolute symlinks still present:"; \ + echo "$$abs"; \ + fi + +fix-tools-links: + @if [[ -d "$(TOOLS_DIR)" ]]; then \ + while IFS= read -r -d '' lnk; do \ + tgt="$$(readlink "$$lnk" || true)"; \ + [[ -z "$$tgt" ]] && continue; \ + if [[ "$$tgt" == /* ]]; then \ + base="$$(basename "$$tgt")"; \ + if [[ -f "$(TOOLS_DIR)/$$base" ]]; then \ + ln -sfn "$$base" "$$lnk"; \ + fi; \ + fi; \ + done < <(find "$(TOOLS_DIR)" -maxdepth 1 -type l -print0 2>/dev/null); \ + fi + +check: + @echo "functions.json:" + @ls -l functions.json + @echo + @echo "bin/:" + @ls -la "$(BIN_DIR)" || true + @echo + @echo "Any absolute symlinks left?" + @find "$(BIN_DIR)" -maxdepth 1 -type l -print0 2>/dev/null | \ + xargs -0 -I{} bash -lc 't=$$(readlink "{}"); [[ "$$t" == /* ]] && echo "{} -> $$t" || true' || true + +clean: + @rm -rf "$(BIN_DIR)" functions.json cache 2>/dev/null || true + @echo "cleaned" + +rebuild: clean all + |
