summaryrefslogtreecommitdiffstats
path: root/dotfiles.mk
blob: 41329926a1ffc115a42b6d5ff39f9a4c7da832ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
LOAD_PATH=. /usr/share/emacs/site-lisp $(HOME)/.emacs.d/site-lisp
EMACS=emacs $(addprefix -L ,$(LOAD_PATH))
MODE=644

ifeq ($(shell if [ "`tput colors`" -gt 0 ]; then echo -n "y"; fi),y)
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
else
FG_BLU=
FG_YEL=
FG_GRE=
FG_RED=
CLR_RE=
endif

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))
uninstall-objects=$(addprefix uninstall-,$(objects))

check-modules=$(addprefix check-,$(modules))
install-modules=$(addprefix install-,$(modules))
reverse-modules=$(addprefix reverse-,$(modules))
cleanup-modules=$(addprefix cleanup-,$(modules))
uninstall-modules=$(addprefix uninstall-,$(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) \
	$(uninstall-objects) $(uninstall-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)
uninstall: $(uninstall-modules) $(uninstall-objects)
	@rmdir --ignore-fail-on-non-empty $(DESTDIR) 2> /dev/null || true
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 NEWOBJS = $(objects)
cleanup: export NEWMODS = $(modules)
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
uninstall:
	@$(MAKE) -s -C ../ uninstall
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 $*,$(NEWOBJS)),, \
		@$(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-%:
	@$(if $(findstring $*,$(NEWMODS)), \
		@$(MAKE) -C $* cleanup MKDPREFIX=$(MKDPREFIX)$*/, \
		@$(MAKE) -C $* uninstall 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)$*/

$(uninstall-objects): uninstall-%:
	@$(if $(call older,$*), \
		echo -e "$(FG_RED)+ $(FG_YEL)$(MKDPREFIX)$*$(CLR_RE)", \
		echo -e "$(FG_GRE)- $(FG_YEL)$(MKDPREFIX)$*$(CLR_RE)"; \
		unlink "$(DESTDIR)/$*" || true)

$(uninstall-modules): uninstall-%:
	@$(MAKE) -s -C $* uninstall MKDPREFIX=$(MKDPREFIX)$*/

$(filter %.elc,$(objects)): %.elc: %.el
	$(call compile,$^)