-
Notifications
You must be signed in to change notification settings - Fork 1
/
GNUmakefile
301 lines (247 loc) · 9.1 KB
/
GNUmakefile
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#
# GNU Make based .file manager
# Copyright © 2018-2024 Matheus Afonso Martins Moreira <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Disable built-in make variables and rules
MAKEFLAGS += --no-builtin-variables --no-builtin-rules
makefile := $(abspath $(lastword $(MAKEFILE_LIST)))
dotfiles := $(abspath $(dir $(makefile)))
~ := $(abspath $(dotfiles)/~)
# Commands to use for directory and symbolic link creation.
mkdir ?= mkdir -p $(1)
ln ?= ln -snf $(1) $(2)
# Determines whether the given path exists and is a directory.
# Only existing directories contain a "." entry.
directory? = $(wildcard $(1)/.)
# Generates a command that creates the given directory.
# Generates the empty string if the directory already exists.
ensure_directory_exists = $(if $(call directory?,$(1)),,$(call mkdir,$(1)))
# Generates a command to link $(1) to $(2).
link = $(call ln,$(2),$(1))
# Template for the definition of symbolic link creation rules.
# The recipe links all targets in $(1) to their counterparts in $(2).
# The targets are always updated. The target's directory is created if needed.
#
# $(1) = Prefix of the symbolic link
# $(2) = Prefix of the symbolic link's target
#
# Rules generated:
#
# $(1)/% : $(2)/%
#
define rule.template
$(1)/% : $(2)/% force
$$(call ensure_directory_exists,$$(@D))
$$(call link,$$@,$$<)
endef
# Defines a rule that links all targets in $(1) to their counterparts in $(2).
rule.define = $(eval $(call rule.template,$(1),$(2)))
# Converts the list of paths specified in $(3) from paths prefixed by $(1)
# to paths prefixed by $(2).
convert_prefix = $(patsubst $(1)/%,$(2)/%,$(3))
# Template for the definition of prefix conversion functions
# that convert between the user's home directory and dotfiles repository.
#
# $(1) = Type of prefix conversion
# $(2) = Home directory prefix
# $(3) = Dotfiles repository prefix
#
# Functions generated:
#
# $(1).to_dotfiles Converts paths to files in $(2) to paths in $(3).
# $(1).to_user Converts paths to files in $(3) to paths in $(2).
# $(1).user_to_dotfiles Converts paths relative to $(2) to absolute paths in $(3).
# $(1).dotfiles_to_user Converts paths relative to $(3) to absolute paths in $(2).
#
define prefix_conversion_functions.template
$(1).to_dotfiles = $$(call convert_prefix,$(2),$(3),$$(1))
$(1).to_user = $$(call convert_prefix,$(3),$(2),$$(1))
$(1).user_to_dotfiles = $$(call $(1).to_dotfiles,$$(wildcard $$(addprefix $(2)/,$$(1))))
$(1).dotfiles_to_user = $$(call $(1).to_user,$$(wildcard $$(addprefix $(3)/,$$(1))))
endef
# Defines path conversion functions for the given type, home directory prefix and dotfiles repository prefix.
prefix_conversion_functions.define = $(eval $(call prefix_conversion_functions.template,$(1),$(2),$(3)))
# Create symbolic links in $(HOME) pointing at their counterparts in $(~).
$(call rule.define,$(HOME),$(~))
# ~.to_dotfiles
# ~.to_user
# ~.user_to_dotfiles
# ~.dotfiles_to_user
$(call prefix_conversion_functions.define,~,$$(HOME),$$(~))
# XDG Base Directory Specification
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
#
# Files in the repository are stored in the default directories.
# Links in $(HOME) take the XDG variables into account.
# Template for the definition of rules, variables and path conversion functions
# for the user's XDG directories.
#
# $(1) = Type of XDG directory
# $(2) = Default directory, used if XDG variable not set
#
# Rules generated:
#
# $(XDG_$(1)_HOME)/% : $(XDG_$(1)_HOME.dotfiles)/%
#
# Variables generated:
#
# XDG_$(1)_HOME Directory set by user or the default directory
# XDG_$(1)_HOME.default Default XDG_$(1)_HOME directory
# XDG_$(1)_HOME.dotfiles The XDG_$(1)_HOME directory in the dotfiles repository
#
# Functions generated:
#
# $(1).to_dotfiles Converts paths to files in $(XDG_$(1)_HOME)
# to paths in $(XDG_$(1)_HOME.dotfiles).
# $(1).to_user Converts paths to files in $(XDG_$(1)_HOME.dotfiles)
# to paths in $(XDG_$(1)_HOME).
# $(1).user_to_dotfiles Converts paths relative to $(XDG_$(1)_HOME)
# to absolute paths in $(XDG_$(1)_HOME.dotfiles).
# $(1).dotfiles_to_user Converts paths relative to $(XDG_$(1)_HOME.dotfiles)
# to absolute paths in $(XDG_$(1)_HOME).
#
define XDG.template
XDG_$(1)_HOME.default := $$(HOME)/$(2)
XDG_$(1)_HOME.dotfiles := $$(call ~.to_dotfiles,$$(XDG_$(1)_HOME.default))
XDG_$(1)_HOME ?= $$(XDG_$(1)_HOME.default)
$(call prefix_conversion_functions.template,$(1),$$(XDG_$(1)_HOME),$$(XDG_$(1)_HOME.dotfiles))
$(call rule.template,$$(XDG_$(1)_HOME),$$(XDG_$(1)_HOME.dotfiles))
endef
# Defines XDG rules, variables and functions for the given type and default directory.
XDG.define = $(eval $(call XDG.template,$(1),$(2)))
# $(XDG_DATA_HOME)/% : $(XDG_DATA_HOME.dotfiles)/%
#
# XDG_DATA_HOME
# XDG_DATA_HOME.default
# XDG_DATA_HOME.dotfiles
#
# DATA.to_dotfiles
# DATA.to_user
# DATA.user_to_dotfiles
# DATA.dotfiles_to_user
$(call XDG.define,DATA,.local/share)
# $(XDG_CONFIG_HOME)/% : $(XDG_CONFIG_HOME.dotfiles)/%
#
# XDG_CONFIG_HOME
# XDG_CONFIG_HOME.default
# XDG_CONFIG_HOME.dotfiles
#
# CONFIG.to_dotfiles
# CONFIG.to_user
# CONFIG.user_to_dotfiles
# CONFIG.dotfiles_to_user
$(call XDG.define,CONFIG,.config)
# Some directories are not part of the XDG specification
# but are widely used in practice.
#
# $ systemd-path user-binaries
# ~/.local/bin
# $(XDG_BIN_HOME)/% : $(XDG_BIN_HOME.dotfiles)/%
#
# XDG_BIN_HOME
# XDG_BIN_HOME.default
# XDG_BIN_HOME.dotfiles
#
# BIN.to_dotfiles
# BIN.to_user
# BIN.user_to_dotfiles
# BIN.dotfiles_to_user
$(call XDG.define,BIN,.local/bin)
# GNU Privacy Guard
# https://www.gnupg.org/documentation/manuals/gnupg/
#
# Files in the repository are stored in the default directories.
# Links in $(GNUPGHOME) take the environment variable into account.
# GNUPGHOME
# GNUPGHOME.default
# GNUPGHOME.dotfiles
GNUPGHOME.default := $(HOME)/.gnupg
GNUPGHOME.dotfiles := $(call ~.to_dotfiles,$(GNUPGHOME.default))
GNUPGHOME ?= $(GNUPGHOME.default)
# GNUPGHOME.to_dotfiles
# GNUPGHOME.to_user
# GNUPGHOME.user_to_dotfiles
# GNUPGHOME.dotfiles_to_user
$(call prefix_conversion_functions.define,GNUPGHOME,$(GNUPGHOME),$(GNUPGHOME.dotfiles))
# $(GNUPGHOME)/% : $(GNUPGHOME.dotfiles)/%
$(call rule.define,$(GNUPGHOME),$(GNUPGHOME.dotfiles))
# Phony targets
user_binaries := $(call BIN.dotfiles_to_user,*)
phony += bin
bin : $(user_binaries)
phony += bash
bash : ~/.bash_profile ~/.bashrc
phony += git
git : $(call CONFIG.dotfiles_to_user,git/config)
phony += ssh
ssh : ~/.ssh/config
phony += vim
vim : ~/.vimrc
phony += nano
nano : $(call CONFIG.dotfiles_to_user,nano/nanorc)
phony += gpg
gpg : $(call GNUPGHOME.dotfiles_to_user,*.conf)
phony += gdb
gdb : $(call CONFIG.dotfiles_to_user,gdb/*)
phony += shellcheck
shellcheck : $(call CONFIG.dotfiles_to_user,shellcheckrc)
phony += tidy
tidy : ~/.tidyrc
sublime_text_3_user_preferences := $(call CONFIG.dotfiles_to_user,sublime-text-3/Packages/User/*.sublime-settings)
phony += sublime-text-3
sublime-text-3 : $(sublime_text_3_user_preferences)
.Xresources.d := $(call ~.dotfiles_to_user,.Xresources.d/*)
phony += Xresources
~/.Xresources : $(.Xresources.d)
Xresources: ~/.Xresources
phony += xinitrc
xinitrc : ~/.xinitrc
phony += X
X : Xresources xinitrc
phony += urxvt
urxvt : Xresources
phony += terminals kitty foot
terminals : kitty foot
foot : $(call CONFIG.dotfiles_to_user,foot/foot.ini)
kitty_conf := $(call CONFIG.dotfiles_to_user,kitty/*.conf)
kitty_themes := $(call CONFIG.dotfiles_to_user,kitty/themes/*.conf)
kitty_fonts := $(call CONFIG.dotfiles_to_user,kitty/fonts/*.conf)
kitty_performance := $(call CONFIG.dotfiles_to_user,kitty/performance/*.conf)
kitty : $(kitty_conf) $(kitty_themes) $(kitty_fonts) $(kitty_performance)
phony += i3
i3 : $(call CONFIG.dotfiles_to_user,i3/config i3status/config) $(call BIN.dotfiles_to_user,nvidia-smi.py)
phony += sway
sway : $(call CONFIG.dotfiles_to_user,sway/config)
sway : $(call CONFIG.dotfiles_to_user,swaylock/config)
sway : $(call CONFIG.dotfiles_to_user,swayidle/config)
phony += mpv
mpv : $(call CONFIG.dotfiles_to_user,mpv/mpv.conf)
phony += termux
termux : ~/.termux/termux.properties
phony += irc irssi
irc : irssi
irssi : ~/.irssi/config
phony += email msmtp
email : msmtp
msmtp : ~/.msmtprc
phony += basic
basic : bash git ssh vim nano
phony += arch-linux
arch-linux:
rsync --verbose --recursive --existing --no-perms $(dotfiles)/etc/ /etc
force:
.PHONY: $(phony)
.DEFAULT_GOAL := basic