legacy-dotfiles/dotfiles.mk
Tom Willemse 50c3f9ade9 Rename uninstall* to cleanup*
Since cleanup only removes that which will not be restored it makes no
sense to call it uninstall. Uninstall should remove everything
unconditionally.
2013-04-14 01:05:42 +02:00

108 lines
3.1 KiB
Makefile

LOAD_PATH=. /usr/share/emacs/site-lisp $(HOME)/.emacs.d/site-lisp
EMACS=emacs $(addprefix -L ,$(LOAD_PATH))
MODE=644
FG_BLU=\033[0;34m
FG_YEL=\033[0;33m
FG_GRE=\033[0;32m
FG_RED=\033[0;31m
CLR_RE=\033[0;00m
compile = $(EMACS) -Q -batch -eval "(byte-compile-file \"$(1)\")"
define newer =
$(shell if [ "$(1)" -nt "$(DESTDIR)/$(1)" ]; then echo "newer"; fi)
endef
define older =
$(shell if [ "$(1)" -ot "$(DESTDIR)/$(1)" ]; then echo "older"; fi)
endef
check-objects=$(addprefix check-,$(objects))
install-objects=$(addprefix install-,$(objects))
reverse-objects=$(addprefix reverse-,$(objects))
cleanup-objects=$(addprefix cleanup-,$(objects))
check-modules=$(addprefix check-,$(modules))
install-modules=$(addprefix install-,$(modules))
reverse-modules=$(addprefix reverse-,$(modules))
cleanup-modules=$(addprefix cleanup-,$(modules))
.PHONY: all install cleanup check cleanup $(modules) \
$(install-objects) $(cleanup-objects) $(check-objects) \
$(install-modules) $(cleanup-modules) $(check-modules) \
$(reverse) $(reverse-objects) $(reverse-modules)
all: $(modules) $(objects)
ifeq ($(MAKEROOT),y)
check: $(check-modules) $(check-objects)
install: cleanup $(install-modules) $(install-objects) Makefile.old
reverse: $(reverse-modules) $(reverse-objects)
ifeq ($(firstword $(MAKEFILE_LIST)),Makefile.old)
cleanup: $(cleanup-modules) $(cleanup-objects)
@rmdir --ignore-fail-on-non-empty $(DESTDIR) 2> /dev/null || true
else
cleanup: export NEWLIST = $(objects)
cleanup:
@$(MAKE) -s -f Makefile.old cleanup
Makefile.old: $(firstword $(MAKEFILE_LIST))
@cp "$^" "$@"
ifdef SUBDIR
DESTDIR:=$(DESTDIR)/$(SUBDIR)
endif
endif
else
check:
@$(MAKE) -s -C ../ check
install:
@$(MAKE) -s -C ../ install
reverse:
@$(MAKE) -s -C ../ reverse
cleanup:
@$(MAKE) -s -C ../ cleanup
endif
$(modules): %:
$(MAKE) -C $*
$(install-objects): install-%: %
@$(if $(call newer,$*), \
echo -e "$(FG_GRE)+ $(FG_YEL)$(MKDPREFIX)$* $(CLR_RE)to $(DESTDIR) as $(MODE)"; \
install -pDm $(MODE) "$*" "$(DESTDIR)/$*", \
$(if $(call older,$*) ,\
echo -e "$(FG_RED)- $(FG_YEL)$(MKDPREFIX)$*$(CLR_RE)"))
$(install-modules): install-%:
@$(MAKE) -s -C $* install MKDPREFIX=$(MKDPREFIX)$*/
$(reverse-objects): reverse-%:
@$(if $(call older,$*), \
echo -e "$(FG_GRE)+ $(FG_YEL)$(MKDPREFIX)$*$(CLR_RE)"; \
cp -a "$(DESTDIR)/$*" "$*", \
echo -e "$(FG_RED)- $(FG_YEL)$(MKDPREFIX)$*$(CLR_RE)")
$(reverse-modules): reverse-%:
@$(MAKE) -s -C $* reverse MKDPREFIX=$(MKDPREFIX)$*/
$(cleanup-objects): cleanup-%:
@$(if $(findstring $*,$(NEWLIST)),, \
@$(if $(call older,$*), \
echo -e "$(FG_RED)+ $(FG_YEL)$(MKDPREFIX)$*$(CLR_RE)", \
echo -e "$(FG_GRE)- $(FG_YEL)$(MKDPREFIX)$*$(CLR_RE)"; \
unlink "$(DESTDIR)/$*" || true))
$(cleanup-modules): cleanup-%:
@$(MAKE) -C $* cleanup MKDPREFIX=$(MKDPREFIX)$*/
$(check-objects): check-%:
@$(if $(call newer,$*), \
echo -e "$(FG_GRE)+ $(FG_YEL)$(MKDPREFIX)$*$(CLR_RE)", \
$(if $(call older,$*), \
echo -e "$(FG_RED)- $(FG_YEL)$(MKDPREFIX)$*$(CLR_RE)", \
echo -e "$(FG_BLU)= $(FG_YEL)$(MKDPREFIX)$*$(CLR_RE)"))
$(check-modules): check-%:
@$(MAKE) -s -C $* check MKDPREFIX=$(MKDPREFIX)$*/
$(filter %.elc,$(objects)): %.elc: %.el
$(call compile,$^)