-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
borg.mk
192 lines (157 loc) · 5.55 KB
/
borg.mk
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Copyright (C) 2016-2024 Jonas Bernoulli
#
# Author: Jonas Bernoulli <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
BORG_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
BORG_CLEAN_ELN := true
help::
-include etc/borg/config.mk
ifeq ($(V),1)
Q=
else
Q=@
endif
ifeq "$(BORG_SECONDARY_P)" "true"
DRONES_DIR ?= $(shell git config "borg.drones-directory" || echo "elpa")
BORG_ARGUMENTS = -L $(BORG_DIR) --load borg-elpa \
--funcall borg-elpa-initialize
else
DRONES_DIR ?= $(shell git config "borg.drones-directory" || echo "lib")
BORG_ARGUMENTS = -L $(BORG_DIR) --load borg \
--funcall borg-initialize
endif
EMACS ?= emacs
EMACS_ARGUMENTS ?= -Q --batch
EMACS_EXTRA ?=
.PHONY: help helpall clean build native quick-clean quick-build quick \
init-clean init-build bootstrap bootstrap-borg
.FORCE:
SILENCIO += --eval "(progn (require 'gv) (put 'buffer-substring 'byte-obsolete-generalized-variable nil))"
SILENCIO += --eval "(progn \
(put 'if-let 'byte-obsolete-info nil) \
(put 'when-let 'byte-obsolete-info nil))"
SILENCIO += --eval "(define-advice message (:around (fn format &rest args) silencio)\
(unless (or (equal format \"Not registering prefix \\\"%s\\\" from %s. Affects: %S\")\
(ignore-errors (string-match-p \"Scraping files for\" (car args))))\
(apply fn format args)))"
## Help
help helpall::
$(info )
$(info Getting help)
$(info ------------)
$(info make help = show brief help)
$(info make helpall = show extended help)
$(info )
$(info Batch targets)
$(info -------------)
$(info make clean = remove all byte-code and native files)
helpall::
$(info make clean-force = remove all byte-code files using find)
help helpall::
$(info make build = byte-compile all drones and init files)
$(info make native = byte+native-compile drones and byte-compile init files)
helpall::
$(info make quick-clean = clean most drones and init files)
$(info make quick-build = byte-compile most drones and init files)
help helpall::
$(info make quick = clean and byte-compile most drones and init files)
$(info )
$(info Drone targets)
$(info -------------)
$(info make build/DRONE = byte-compile DRONE)
$(info make native/DRONE = byte+native-compile DRONE)
helpall::
$(info )
$(info Init file targets)
$(info -----------------)
$(info make init-clean = remove byte-code init files)
$(info make init-tangle = recreate init.el from init.org)
$(info make init-build = byte-compile init files)
help helpall::
$(info )
$(info Bootstrapping)
$(info -------------)
$(info make bootstrap = bootstrap collective or new drones)
@printf "\n"
## Batch
clean:
ifeq "$(BORG_CLEAN_ELN)" "true"
$(Q)rm -f init.elc $(INIT_FILES:.el=.elc)
$(Q)$(EMACS) $(EMACS_ARGUMENTS) $(EMACS_EXTRA) $(SILENCIO) \
$(BORG_ARGUMENTS) \
--funcall borg--batch-clean 2>&1
else
$(Q)find . -name '*.elc' -printf 'removed %p\n' -delete
$(Q)find . -name '*-autoloads.el' -printf 'removed %p\n' -delete
endif
clean-force:
$(Q)find . -name '*.elc' -printf 'removed %p\n' -delete
$(Q)find . -name '*-autoloads.el' -printf 'removed %p\n' -delete
build: init-clean
$(Q)$(EMACS) $(EMACS_ARGUMENTS) $(EMACS_EXTRA) $(SILENCIO) \
$(BORG_ARGUMENTS) \
--funcall borg-batch-rebuild $(INIT_FILES) 2>&1
native: init-clean
$(Q)$(EMACS) $(EMACS_ARGUMENTS) $(EMACS_EXTRA) $(SILENCIO) \
$(BORG_ARGUMENTS) \
--eval "(borg-batch-rebuild nil t)" $(INIT_FILES) 2>&1
## Batch Quick
quick-clean: init-clean
$(Q)$(EMACS) $(EMACS_ARGUMENTS) $(EMACS_EXTRA) $(SILENCIO) \
$(BORG_ARGUMENTS) \
--eval '(borg--batch-clean t)' 2>&1
quick-build:
$(Q)$(EMACS) $(EMACS_ARGUMENTS) $(EMACS_EXTRA) $(SILENCIO) \
$(BORG_ARGUMENTS) \
--eval '(borg-batch-rebuild t)' $(INIT_FILES) 2>&1
quick: quick-clean quick-build
## Per-Clone
clean/%: .FORCE
$(Q)$(EMACS) $(EMACS_ARGUMENTS) $(EMACS_EXTRA) $(SILENCIO) \
$(BORG_ARGUMENTS) \
--eval '(borg-clean "$*")' 2>&1
# Make tries to rebuild included files. Since the next rule
# would be used in this case, we need a no-op rule to prevent that.
# https://github.com/magit/magit/issues/3318#issuecomment-357548808
$(DRONES_DIR)/borg/borg.mk: ;
$(DRONES_DIR)/% : .FORCE
$(Q)$(EMACS) $(EMACS_ARGUMENTS) $(EMACS_EXTRA) $(SILENCIO) \
$(BORG_ARGUMENTS) \
--eval '(borg-build "$*")' 2>&1
# Define the "aliases" separately to avoid warnings about "peer
# targets" not being updated.
build/%: .FORCE
$(Q)$(EMACS) $(EMACS_ARGUMENTS) $(EMACS_EXTRA) $(SILENCIO) \
$(BORG_ARGUMENTS) \
--eval '(borg-build "$*")' 2>&1
native/%: .FORCE
$(Q)$(EMACS) $(EMACS_ARGUMENTS) $(EMACS_EXTRA) $(SILENCIO) \
$(BORG_ARGUMENTS) \
--eval '(borg-build "$*" nil t)' 2>&1
## Init Files
init-clean:
$(Q)rm -f init.elc $(INIT_FILES:.el=.elc)
init-tangle: init.org
@printf "%s\n" "--- [init.org] ---"
$(Q)$(EMACS) $(EMACS_ARGUMENTS) $(EMACS_EXTRA) \
--load org \
--eval '(org-babel-tangle-file "init.org")' 2>&1
init-build: init-clean
$(Q)$(EMACS) $(EMACS_ARGUMENTS) $(EMACS_EXTRA) \
$(BORG_ARGUMENTS) \
--funcall borg-batch-rebuild-init $(INIT_FILES) 2>&1
ifeq ($(wildcard init.org), init.org)
init-build: init-tangle
endif
## Bootstrap
bootstrap:
$(Q)printf "\n=== Running 'git submodule init' ===\n\n"
$(Q)git submodule init
$(Q)printf "\n=== Running '$(BORG_DIR)borg.sh clone' ===\n"
$(Q)$(BORG_DIR)borg.sh clone
$(Q)printf "\n=== Running '$(BORG_DIR)borg.sh checkout' ===\n"
$(Q)$(BORG_DIR)borg.sh checkout --reset-hard
$(Q)printf "\n=== Running 'make build' ===\n\n"
$(Q)$(MAKE) build
$(Q)printf "\n=== Bootstrapping finished ===\n\n"
$(Q)git submodule status