workshops/slides/makefiles/PS/omni_makefile

35 lines
900 B
Plaintext
Raw Permalink Normal View History

2024-11-18 17:03:49 +00:00
CONFIGS = $(patsubst /%,%,$(shell cat configs))
STORE = $(patsubst /%,%,$(shell cat store))
CP = mkdir -p $(dir $@) && cp -a
IGNORE_FILE = $(shell test -d .git/info && echo .git/info/exclude || echo .gitignore)
GIT_COMMIT = git commit -m"add $@" --no-gpg-sign --no-signoff
SELECTOR != command -v sk || command -v fzy || command -f fzf
.PHONY: all
all: init backup.tgz $(IGNORE_FILE)
backup.tgz: $(CONFIGS) $(STORE)
tar czf $@ $^
$(IGNORE_FILE): store
echo $(STORE) backup.tgz | tr ' ' '\n' > $@
.PHONY: init
init: configs store
configs store:
while con="$$(find /var /etc/ /sys/ -maxdepth 2 -mindepth 1 -type f 2>/dev/null | $(SELECTOR) -p "Select files for $@\nPress Ctrl+d once done")"; do \
echo "$$con"; \
done > $@
$(CONFIGS): %: /%
$(CP) $< $@
git add $@
$(GIT_COMMIT)
$(info made git commit for $@)
$(STORE): %: /%
$(CP) $< $@
clean:
$(RM) -r $(CONFIGS) $(STORE) backup.tgz