2.3 KiB
2.3 KiB
Generalizing Makefiles for All Occasions
- Rules are bad,
- standards are good,
- habits are better.
General Standards
make helpmake checksudo make install
NB: we separate make from make install so that the files are not build with the user root as the owner.
Service Standards
make backup.tgzmake install
Service Backups in Two Files
configs: configuration files, all tracked in git.store: passwords and binary files, not tracked in git.
New Abilities Unlocked
- Open Access Administration.
- Sharing admin configs with hacker spaces.
BEHOLD: The Everything Makefile
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
Example: Soft Serve Makefile
The `configs` file:
/etc/soft-serve.conf
/var/lib/soft-serve/data/config.yaml
/var/lib/soft-serve/data/file
/etc/nginx/sites-enabled/soft.dmz.rs
/etc/nginx/sites-available/soft.dmz.rs
The `store` file:
/var/lib/soft-serve/data/lfs
/var/lib/soft-serve/data/repo
/var/lib/soft-serve/data/soft
/etc/letsencrypt/archive/soft
/etc/letsencrypt/live/soft.dm
/var/lib/soft-serve/data/ssh/
Other Build Systems
"*What if I want to use this other thing, instead of a makefile?"
Other Build Systems (Sans Heresy)
"*What if I want to use this other thing, instead of a makefile?"
- Easy: just use a Makefile.
[ ... ]
public/: src/
python build_pages.py