From 805dca93106e52e9d6a147ce4ebe324913223776 Mon Sep 17 00:00:00 2001 From: Travis Vasceannie Date: Sun, 18 Jan 2026 20:59:11 -0500 Subject: [PATCH] Add Makefile with target to add git submodules and usage instructions --- Makefile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6b2fc2a --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +.PHONY: add-submodule help + +help: + @echo "Available targets:" + @echo " add-submodule - Add a git submodule" + @echo " Usage: make add-submodule [directory-name]" + +%: + @: + +add-submodule: + @ARGS="$(filter-out $@,$(MAKECMDGOALS))"; \ + URL=$$(echo $$ARGS | awk '{print $$1}'); \ + DIR=$$(echo $$ARGS | awk '{print $$2}'); \ + if [ -z "$$URL" ]; then \ + echo "Error: URL is required. Usage: make add-submodule [directory-name]"; \ + exit 1; \ + fi; \ + if [ -z "$$DIR" ]; then \ + REPO_NAME=$$(echo $$URL | awk -F'/' '{print $$NF}' | sed 's/\.git$$//'); \ + SUBMODULE_DIR=$$REPO_NAME; \ + else \ + SUBMODULE_DIR=$$DIR; \ + fi; \ + ADD_OUTPUT=$$(git submodule add $$URL $$SUBMODULE_DIR 2>&1); \ + ADD_EXIT=$$?; \ + if [ $$ADD_EXIT -ne 0 ]; then \ + if echo "$$ADD_OUTPUT" | grep -q "A git directory for.*is found locally"; then \ + echo "Warning: Submodule directory already exists. Using --force to reuse it."; \ + git submodule add --force $$URL $$SUBMODULE_DIR 2>&1 || { \ + echo "Error: Failed to add submodule with --force"; \ + exit 1; \ + }; \ + else \ + echo "$$ADD_OUTPUT"; \ + exit $$ADD_EXIT; \ + fi; \ + fi; \ + UPDATE_OUTPUT=$$(git submodule update --init --recursive $$SUBMODULE_DIR 2>&1); \ + UPDATE_EXIT=$$?; \ + if [ $$UPDATE_EXIT -ne 0 ]; then \ + if echo "$$UPDATE_OUTPUT" | grep -q "empty repository\|yet to be born"; then \ + echo "Warning: Empty repository detected. Submodule added but not checked out."; \ + else \ + echo "$$UPDATE_OUTPUT"; \ + exit $$UPDATE_EXIT; \ + fi; \ + fi