Files
BackTunnel/Makefile

102 lines
4.1 KiB
Makefile

# BackTunnel convenience Makefile (for first-time users and simple installs)
PREFIX ?= /usr
BINDIR := $(PREFIX)/bin
MANDIR := $(PREFIX)/share/man
KIO_SM := $(PREFIX)/share/kio/servicemenus
KSVC5 := $(PREFIX)/share/kservices5/ServiceMenus
APPDIR := $(PREFIX)/share/applications
BCOMP := $(PREFIX)/share/bash-completion/completions
# Config paths for user init
XDG_CONFIG_HOME ?= $(HOME)/.config
BT_CFG_DIR := $(XDG_CONFIG_HOME)/backtunnel
BT_CFG_FILE := $(BT_CFG_DIR)/profiles.ini
BT_CFG_EXAMPLE := docs/profiles.ini.example
.PHONY: all init install uninstall refresh man check shellcheck help
all: help
help:
@echo "BackTunnel Makefile"
@echo " make init # Copy example profiles.ini for current user (first run)"
@echo " make install # Install scripts, man page, service menus (root)"
@echo " make uninstall # Remove installed files (root)"
@echo " make refresh # Refresh KDE/desktop caches (root)"
@echo " make man # View man page locally (man ./man/backtunnel.1)"
@echo " make check # Basic bash syntax check"
@echo " make shellcheck # ShellCheck (if installed)"
# --- First-time user init (no root needed) ---
init:
@mkdir -p "$(BT_CFG_DIR)"
@if [ -f "$(BT_CFG_FILE)" ]; then \
echo "profiles.ini already exists at $(BT_CFG_FILE) — skipping."; \
else \
if [ -f "$(BT_CFG_EXAMPLE)" ]; then \
cp "$(BT_CFG_EXAMPLE)" "$(BT_CFG_FILE)"; \
echo "Created $(BT_CFG_FILE) from $(BT_CFG_EXAMPLE)."; \
else \
echo "Example file $(BT_CFG_EXAMPLE) not found."; exit 1; \
fi \
fi
# --- Install/uninstall (root or DESTDIR) ---
install:
@install -Dm755 scripts/backtunnel-share "$(DESTDIR)$(BINDIR)/backtunnel-share"
@install -Dm755 scripts/backtunnel-access "$(DESTDIR)$(BINDIR)/backtunnel-access"
@install -Dm755 scripts/backtunnel-share-gui "$(DESTDIR)$(BINDIR)/backtunnel-share-gui"
@install -Dm644 man/backtunnel.1 "$(DESTDIR)$(MANDIR)/man1/backtunnel.1"
@install -Dm644 completions/backtunnel.bash "$(DESTDIR)$(BCOMP)/backtunnel-share"
@install -Dm644 completions/backtunnel.bash "$(DESTDIR)$(BCOMP)/backtunnel-access"
@install -Dm644 servicemenus/backtunnel_share.desktop "$(DESTDIR)$(KIO_SM)/backtunnel_share.desktop"
@install -Dm644 servicemenus/backtunnel_access.desktop "$(DESTDIR)$(KIO_SM)/backtunnel_access.desktop"
# Plasma 5 legacy path (harmless if unused)
@install -Dm644 servicemenus/backtunnel_share.desktop "$(DESTDIR)$(KSVC5)/backtunnel_share.desktop"
@install -Dm644 servicemenus/backtunnel_access.desktop "$(DESTDIR)$(KSVC5)/backtunnel_access.desktop"
# Optional desktop launcher if present
@if [ -f desktop/backtunnel.desktop ]; then \
install -Dm644 desktop/backtunnel.desktop "$(DESTDIR)$(APPDIR)/backtunnel.desktop"; \
fi
@$(MAKE) refresh
uninstall:
@rm -f "$(DESTDIR)$(BINDIR)/backtunnel-share" \
"$(DESTDIR)$(BINDIR)/backtunnel-access" \
"$(DESTDIR)$(BINDIR)/backtunnel-share-gui"
@rm -f "$(DESTDIR)$(MANDIR)/man1/backtunnel.1"
@rm -f "$(DESTDIR)$(BCOMP)/backtunnel-share" \
"$(DESTDIR)$(BCOMP)/backtunnel-access"
@rm -f "$(DESTDIR)$(KIO_SM)/backtunnel_share.desktop" \
"$(DESTDIR)$(KIO_SM)/backtunnel_access.desktop"
@rm -f "$(DESTDIR)$(KSVC5)/backtunnel_share.desktop" \
"$(DESTDIR)$(KSVC5)/backtunnel_access.desktop"
@rm -f "$(DESTDIR)$(APPDIR)/backtunnel.desktop" || true
@$(MAKE) refresh
# --- Cache refreshers (no-op if tools missing) ---
refresh:
@command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database -q || true
@if command -v kbuildsycoca6 >/dev/null 2>&1; then \
kbuildsycoca6 --noincremental >/dev/null 2>&1 || true; \
elif command -v kbuildsycoca5 >/dev/null 2>&1; then \
kbuildsycoca5 --noincremental >/dev/null 2>&1 || true; \
fi
# --- Dev helpers ---
man:
@man ./man/backtunnel.1
check:
@bash -n scripts/backtunnel-share
@bash -n scripts/backtunnel-access
@bash -n scripts/backtunnel-share-gui
@echo "bash -n OK."
shellcheck:
@command -v shellcheck >/dev/null 2>&1 || { echo "ShellCheck not installed"; exit 1; }
@shellcheck scripts/backtunnel-share
@shellcheck scripts/backtunnel-access
@shellcheck scripts/backtunnel-share-gui