-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
897 lines (757 loc) · 22.6 KB
/
Makefile
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
MAKEFLAGS += -L
SHELL=/bin/bash -o pipefail
BUILD_DIR=build
SOURCE_DIR=src
UTILS_DIR=utils
CFLAGS=-Wall -Werror -O2
# Check that given variables are set and all have non-empty values,
# die with an error otherwise.
#
# Params:
# 1. Variable name(s) to test.
# 2. (optional) Error message to print.
#
# Source:
# https://stackoverflow.com/a/10858332 by Eldar Abusalimov
check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Undefined $1$(if $2, ($2))))
HOME_DIR := $(shell sed -n -e 's/^HOME=\(.*\)/\1/p' user.cfg)
$(call check_defined, HOME_DIR)
LOCAL_PREFIX := $(shell sed -n -e 's/^LOCAL_PREFIX=\(.*\)/\1/p' user.cfg)
$(call check_defined, LOCAL_PREFIX)
BIN_DIR := $(LOCAL_PREFIX)/bin
CONFIG_DIR := $(shell sed -n -e 's/^XDG_CONFIG_HOME=\(.*\)/\1/p' user.cfg)
$(call check_defined, CONFIG_DIR)
DATA_DIR := $(shell sed -n -e 's/^XDG_DATA_HOME=\(.*\)/\1/p' user.cfg)
$(call check_defined, DATA_DIR)
CACHE_DIR := $(shell sed -n -e 's/^XDG_CACHE_HOME=\(.*\)/\1/p' user.cfg)
$(call check_defined, CACHE_DIR)
SYSTEM_PREFIX := $(shell sed -n -e 's/^SYSTEM_PREFIX=\(.*\)/\1/p' user.cfg)
$(call check_defined, SYSTEM_PREFIX)
# Meant to be used by env/ scripts ONLY
# Echo to force ~ expansion
export HOME_DIR := $(shell echo $(HOME_DIR))
export LOCAL_PREFIX := $(shell echo $(LOCAL_PREFIX))
BIN_DIR := $(shell echo $(BIN_DIR))
export CONFIG_DIR := $(shell echo $(CONFIG_DIR))
export DATA_DIR := $(shell echo $(DATA_DIR))
export CACHE_DIR := $(shell echo $(CACHE_DIR))
export SYSTEM_PREFIX := $(shell echo $(SYSTEM_PREFIX))
I3BLOCKS_SCRIPT_DIR := $(CONFIG_DIR)/i3blocks/scripts
# Incomplete files can be created when pipes / scripts fail
# so delete the target when the rule fails.
.DELETE_ON_ERROR:
WARNING_PREFIX:=$(shell echo "$$(tput setaf 172)WARNING$$(tput sgr0):")
# The following variables need to be defined
# for each TYPE = bin | config | data | home | system
#
# <TYPE>_FIRST_BUILD
# - Names % where BUILD_DIR/<TYPE>/% does not depend on any other files in the
# same directory.
# <TYPE>_BUILD
# - Names % where BUILD_DIR/<TYPE>/% is required for install
# <TYPE>_INSTALL
# - Names % where <TYPE>_INSTALL_PREFIX/% is an install target
# <TYPE>_INSTALL_ONCE
# - Names % where <TYPE>_INSTALL_PREFIX/% is an install target that does not
# need to be updated once installed.
#
# These variables are used to define the make targets (build and install)
# and to create templated rules that depend on the target directory existing.
#
# Useful intermediate variables:
# <TYPE>_FBI (or a subset of FBI)
# - Intersections of <TYPE>_FIRST_BUILD, <TYPE>_BUILD, <TYPE>_INSTALL
# <TYPE>_LINKS
# - Names % where <TYPE>_INSTALL_PREFIX/% is a symbolic link to a file
# <TYPE>_DLINKS
# - Names % where <TYPE>_INSTALL_PREFIX/% is a symbolic link to a directory
# Files can be installed directly from SOURCE_DIR or from BUILD_DIR
# Files in BUILD_DIR can depend on other build files.
# Bin
# ---
BIN_FIRST_BUILD:=
BIN_BUILD:=
BIN_LINKS:=
BIN_DLINKS:=
BIN_INSTALL_ONCE:=$(BIN_LINKS) $(BIN_DLINKS)
BIN_INSTALL:=\
backtrace\
check-home\
clio\
combinediff-careful\
csv2yaml\
dblp-makebib\
decrypt-private\
dfix\
geolocate\
get-gitignore\
git-w\
gr\
low-battery-action\
mdlynx\
pip-deps\
pip-update-all\
plot\
pplayerctl\
print24bitcolours\
print256colours\
pyproject\
send-terminfo\
tmuxm\
xopen\
ifneq ($(strip $(shell command -v dwarffortress)),)
BIN_INSTALL+=dwarffortress
endif
# Config
# ------
CONFIG_FBI_SYSTEMD:=\
systemd/user/auto-suspend.service\
systemd/user/auto-suspend.timer\
systemd/user/duplicacy-backup.service\
systemd/user/duplicacy-backup.timer\
systemd/user/duplicacy-prune.service\
systemd/user/duplicacy-prune.timer\
systemd/user/low-battery.service\
systemd/user/low-battery.timer\
systemd/user/redshift.service\
systemd/user/ssh-agent.service\
systemd/user/xsession.target\
CONFIG_FBI_VIM:=\
vim/ftplugin/rust.vim\
vim/plugin/settings/airline.vim\
vim/plugin/settings/tmuxline.vim\
vim/plugin/settings/ultisnips.vim\
vim/vimrc\
CONFIG_I3BLOCKS_CONTRIB:=\
memory/memory\
nm-vpn/nm-vpn\
temperature/temperature\
volume-pulseaudio/volume-pulseaudio\
CONFIG_FBI:=\
$(CONFIG_FBI_SYSTEMD)\
$(CONFIG_FBI_VIM)\
$(addprefix i3blocks/scripts/,$(notdir $(CONFIG_I3BLOCKS_CONTRIB)))\
alacritty/alacritty.toml\
arduino/preferences.txt\
bash/aliases\
bash/bashrc\
bash/profile\
cargo/config.toml\
conda/condarc\
conky/default-popup.lua\
dircolors/database\
duplicacy-web/settings.json\
duplicacy/filters\
env_profile\
fish/completions/ros2.fish\
fish/completions/timetrace.fish\
fish/config.fish\
fish/functions/fish_prompt.fish\
fish/functions/hostname-icon.fish\
fish/functions/ip.fish\
fish/functions/R.fish\
fish/functions/tmux.fish\
fish/functions/torch-activate.fish\
flake8\
gem/config.yaml\
git/config\
git/ignore\
git/template/hooks/pre-commit\
gsimplecal/config\
gtk-3.0/settings.ini\
hg/hgrc\
htop/htoprc\
i3/config\
i3blocks/config\
i3blocks/scripts/cpu_usage2\
imwheel/config\
isort.cfg\
latexmk/latexmkrc\
locale.conf\
mimeapps.list\
npm/config\
pacman/makepkg.conf\
procps/toprc\
profile\
pylint/config\
redshift/redshift.conf\
security/pam_env.conf\
task/config\
terminator/config\
termite/config\
theano/config\
tmux/tmux.conf\
user-dirs.dirs\
wgetrc\
xbindkeys/config\
xinit/startx.fish\
xinit/startx.sh\
xinit/xinitrc\
xinit/Xmodmap\
xinit/Xresources\
xinit/xserverrc\
xprofile\
yapf/style\
yay/config.json\
CONFIG_LINKS:=
CONFIG_DLINKS:=\
chromium\
duplicacy-web/bin\
duplicacy-web/stats\
duplicacy/cache\
launcher-main\
libreoffice\
Slack\
CONFIG_INSTALL_ONCE:=$(CONFIG_LINKS) $(CONFIG_DLINKS)
CONFIG_FB:=\
$(addsuffix .link,$(CONFIG_LINKS))\
$(addsuffix .dlink,$(CONFIG_DLINKS))\
CONFIG_FIRST_BUILD:=\
$(CONFIG_FBI)\
$(CONFIG_FB)\
CONFIG_BUILD:=\
$(CONFIG_FBI)\
$(CONFIG_FB)\
CONFIG_INSTALL_FISH_BASS:=$(addprefix fish/plugins/bass/,\
functions/__bass.py\
functions/bass.fish\
LICENSE\
Makefile\
README.md\
)
CONFIG_INSTALL_VIM_DIRECT:=\
$(shell cd "$(SOURCE_DIR)/config" && find vim -type f -not -name '*.m4')
CONFIG_FONTS:=\
fontconfig/fonts.conf\
fontconfig/conf.d/10-powerline-symbols.conf\
CONFIG_INSTALL:=\
$(CONFIG_FONTS)\
$(CONFIG_INSTALL_FISH_BASS)\
$(CONFIG_INSTALL_VIM_DIRECT)\
$(CONFIG_FBI)\
gkrellm/user-config-cpu\
fish/functions/xcb.fish\
gkrellm/user-config-memory\
i3blocks/scripts/battery\
i3blocks/scripts/conky-toggle\
i3blocks/scripts/date-calendar\
i3blocks/scripts/gkrellm-toggle\
i3blocks/scripts/gpu-usage\
i3blocks/scripts/music\
i3blocks/scripts/ssid\
i3blocks/scripts/weather\
i3blocks/scripts/wifi\
keepassxc/keepassxc.ini\
playerctl/players\
pudb/pudb.cfg\
pyproject/templates/license/MIT.txt\
pyproject/templates/pyroot/__init__.py\
pyproject/templates/pyroot/version.py\
pyproject/templates/root/.gitignore\
pyproject/templates/root/.pre-commit-config.yaml\
pyproject/templates/root/MANIFEST.in\
pyproject/templates/root/pyproject.toml\
pyproject/templates/root/README.md\
pyproject/templates/root/setup.cfg\
pyproject/templates/root/setup.py\
python/startup.py\
simplescreenrecorder/.\
zathura/zathurarc\
# Data
# ----
DATA_LINKS:=\
arduino/preferences.txt\
cargo/config.toml\
DATA_DLINKS:=\
arduino/cache\
libreoffice/4/cache\
Slack/Cache\
Steam/appcache\
# These directories need to exist
# In some cases, if there is a environment variable telling the
# program to use this directory then the program expects it to exist.
DATA_DIRS:=\
arduino/sketchbook/.\
gnupg/.\
DATA_INSTALL_ONCE=$(DATA_LINKS) $(DATA_DLINKS) $(DATA_DIRS)
DATA_FB:=\
$(addsuffix .link,$(DATA_LINKS))\
$(addsuffix .dlink,$(DATA_DLINKS))\
# Custom for desktop files
SOURCE_SPOTIFY_DESKTOP:=/usr/share/applications/spotify.desktop
DATA_SPOTIFY_DESKTOP:=applications/spotify.desktop
SOURCE_STEAM_DESKTOP:=/usr/share/applications/steam.desktop
DATA_STEAM_DESKTOP:=applications/steam.desktop
DATA_FIRST_BUILD:=\
$(DATA_FB)\
$(DATA_SPOTIFY_DESKTOP).sed\
$(DATA_STEAM_DESKTOP).sed\
DATA_BI:=
ifneq ("$(wildcard $(SOURCE_SPOTIFY_DESKTOP))","")
DATA_BI+=$(DATA_SPOTIFY_DESKTOP)
endif
ifneq ("$(wildcard $(SOURCE_STEAM_DESKTOP))","")
DATA_BI+=$(DATA_STEAM_DESKTOP)
endif
DATA_BUILD:=\
$(DATA_FB)\
$(DATA_BI)\
DATA_FONTS:=\
fonts/PowerlineSymbols.otf\
DATA_VUNDLE_DIR:=vim/bundle/Vundle.vim
DATA_INSTALL:=\
$(DATA_FONTS)\
$(DATA_BI)\
$(DATA_VUNDLE_DIR)\
rust-analyzer-debug/rust-analyzer-debug\
tig/.\
wget/.\
# Home
# ----
HOME_FBI:=\
.ssh/config\
# To avoid putting files here, only include if the relevant program exists.
HOME_LINKS:=\
.bash_profile\
.bashrc\
.pam_environment\
.profile\
.xprofile\
HOME_DLINKS:=\
.pki\
ifneq ($(strip $(shell command -v arduino)),)
HOME_DLINKS += .arduino15 .jssc
endif
ifneq ($(strip $(shell command -v cmake)),)
HOME_DLINKS += .cmake
endif
ifneq ($(strip $(shell command -v duplicacy-web)),)
HOME_DLINKS += .duplicacy-web
endif
ifneq ($(strip $(shell command -v factorio)),)
HOME_DLINKS += .factorio
endif
ifneq ($(strip $(shell command -v gkrellm)),)
HOME_DLINKS += .gkrellm2
endif
ifneq ($(strip $(shell command -v imwheel)),)
HOME_LINKS += .imwheelrc
endif
ifneq ($(strip $(shell command -v firefox)),)
HOME_DLINKS += .mozilla
endif
ifneq ($(strip $(shell command -v steam)),)
HOME_DLINKS += .paradoxlauncher
endif
ifneq ($(strip $(shell command -v thunderbird)),)
HOME_DLINKS += .thunderbird
endif
ifneq ($(strip $(shell command -v lightdm || command -v gdm)),)
HOME_LINKS += .Xresources
endif
ifneq ($(strip $(shell command -v zotero)),)
HOME_DLINKS += .zotero
endif
HOME_INSTALL_ONCE=$(HOME_LINKS) $(HOME_DLINKS)
HOME_FB:=\
$(addsuffix .link,$(HOME_LINKS))\
$(addsuffix .dlink,$(HOME_DLINKS))\
HOME_FIRST_BUILD:=\
$(HOME_FBI)\
$(HOME_FB)\
HOME_BUILD:=\
$(HOME_FBI)\
$(HOME_FB)\
HOME_INSTALL:=\
$(HOME_FBI)\
$(HOME_INSTALL)\
# System
# ------
SYSTEM_FBI:=\
etc/systemd/system/[email protected]/override.conf\
etc/X11/xorg.conf.d/30-touchpad.conf\
etc/X11/xorg.conf.d/80-monitor.conf\
SYSTEM_FIRST_BUILD:=\
$(SYSTEM_FBI)\
SYSTEM_BUILD:=\
$(SYSTEM_FBI)\
SYSTEM_INSTALL:=\
$(SYSTEM_FBI)\
etc/udev/rules.d/90-backlight.rules\
etc/X11/xorg.conf.d/90-keyboard.conf\
# Environment
# -----------
ENV_FIRST_BUILD:=\
applications\
battery\
ccache\
colours\
cpu\
cuda\
display\
fonts\
git\
github_id\
go\
i3\
lock\
modules\
mujoco\
netuser\
nvidia-smi\
osx\
perl\
programs\
python\
root\
ruby\
rust\
sys-monitor\
tmux\
torch\
touchpad\
user\
virtualfish\
vpn\
wifi\
ENV_CONFIG_TARGETS=$(addsuffix .m4,\
$(addprefix $(BUILD_DIR)/env/,$(ENV_FIRST_BUILD)))
# Combined
# --------
FIRST_BUILD_TARGETS:=$(addprefix $(BUILD_DIR)/,\
$(addprefix bin/,$(BIN_FIRST_BUILD))\
$(addprefix config/,$(CONFIG_FIRST_BUILD))\
$(addprefix data/,$(DATA_FIRST_BUILD))\
$(addprefix env/,$(ENV_FIRST_BUILD))\
$(addprefix home/,$(HOME_FIRST_BUILD))\
$(addprefix system/,$(SYSTEM_FIRST_BUILD))\
)
BUILD_TARGETS:=$(addprefix $(BUILD_DIR)/,\
$(addprefix bin/,$(BIN_BUILD))\
$(addprefix config/,$(CONFIG_BUILD))\
$(addprefix data/,$(DATA_BUILD))\
$(addprefix home/,$(HOME_BUILD))\
$(addprefix system/,$(SYSTEM_BUILD))\
)
INSTALL_TARGETS:=\
$(addprefix $(BIN_DIR)/,$(BIN_INSTALL))\
$(addprefix $(CONFIG_DIR)/,$(CONFIG_INSTALL))\
$(addprefix $(DATA_DIR)/,$(DATA_INSTALL))\
$(addprefix $(HOME_DIR)/,$(HOME_INSTALL))\
INSTALL_ONCE_TARGETS:=\
$(addprefix $(BIN_DIR)/,$(BIN_INSTALL_ONCE))\
$(addprefix $(CONFIG_DIR)/,$(CONFIG_INSTALL_ONCE))\
$(addprefix $(DATA_DIR)/,$(DATA_INSTALL_ONCE))\
$(addprefix $(HOME_DIR)/,$(HOME_INSTALL_ONCE))\
INSTALL_SYSTEM_TARGETS:=$(addprefix $(SYSTEM_PREFIX)/,$(SYSTEM_INSTALL))
INSTALLED_SYSTEMD_CONFIGS:=$(addprefix $(CONFIG_DIR)/,$(CONFIG_FBI_SYSTEMD))
INSTALLED_FONT_FILES:=\
$(addprefix $(DATA_DIR)/,$(DATA_FONTS))\
$(addprefix $(CONFIG_DIR)/,$(CONFIG_FONTS))
############
# Commands #
############
.PHONY: build install install-user install-system clean help
build: $(BUILD_TARGETS)
install: install-user systemd-reload font-cache
install-user: $(INSTALL_TARGETS) | $(INSTALL_ONCE_TARGETS)
install-system: $(INSTALL_SYSTEM_TARGETS)
clean:
rm -rf $(BUILD_DIR)
define HELP_MESSAGE
Makefile Commands
=================
build [default] : Build the dotfiles into $(BUILD_DIR)/
install : Install user dotfiles.
Destinations are specified in user.cfg.
install-system : Install system dotfiles.
Likely requires root permissions.
clean : Remove build products.
help : Print this help message
show : Run most `show-*` commands.
show-dirs : Print the install directories.
show-config : Print the user and environment configuration.
show-wants : Print a list of desirable programs that are not
checked by the environment configuration (show-config).
show-links : Print information about files that should be links.
vim : Run all `vim-*` commands.
Uses the installed configurations so install first.
vim-vundle : Install the Vundle vim plugin.
vim-plugins : Install and update vim plugins.
vim-ycm : Compile YouCompleteMe for vim.
vim-tmuxline : Create the tmuxline configuration.
systemd-reload : Reload user systemd units if any changed.
font-cache : Create the font cache.
persistent-configs : Set persistent settings that are not file-based.
endef
help:
@: $(info $(HELP_MESSAGE))
################
## Build M4 ##
################
USER_CONFIG_PREFIX:=m4_user_config_
ENV_CONFIG_PREFIX:=m4_env_config_
# Hopefully unlikely to appear in the dotfiles.
QUOTE_START:={<<
QUOTE_END:=>>}
$(BUILD_DIR)/%: $(SOURCE_DIR)/%.m4 \
$(BUILD_DIR)/user_config.m4 $(BUILD_DIR)/env_config.m4
echo "m4_changecom()m4_changequote($(QUOTE_START),$(QUOTE_END))m4_dnl" | \
cat - "$<" | \
m4 --prefix-builtins -I "$(BUILD_DIR)" > "$@"
! grep m4_ "$@" || (echo "Undefined m4 variables" && rm "$@" && false)
define BUILD_WITH_LOCAL_TEMPLATE
ifneq ("$(wildcard $(SOURCE_DIR)/$1.local)","")
$(BUILD_DIR)/$1: $(SOURCE_DIR)/$1.local
endif
endef
$(eval $(call BUILD_WITH_LOCAL_TEMPLATE,config/i3/config))
$(eval $(call BUILD_WITH_LOCAL_TEMPLATE,home/.ssh/config))
##############################
## Build I3Blocks Contrib ##
##############################
define BUILD_I3BLOCKS_CONTRIB_TEMPLATE
$(BUILD_DIR)/config/i3blocks/scripts/$(notdir $1):\
$(SOURCE_DIR)/config/i3blocks/i3blocks-contrib/$1\
| $(BUILD_DIR)/config/i3blocks/scripts/.
cp -v "$$<" "$$@"
endef
$(foreach CONTRIB_SCRIPT,$(CONFIG_I3BLOCKS_CONTRIB),\
$(eval $(call BUILD_I3BLOCKS_CONTRIB_TEMPLATE,$(CONTRIB_SCRIPT))))
CPU_USAGE_PATCH:=$(SOURCE_DIR)/config/i3blocks/patches/cpu_usage2.c.patch
$(BUILD_DIR)/config/i3blocks/scripts/cpu_usage2.c: \
$(SOURCE_DIR)/config/i3blocks/i3blocks-contrib/cpu_usage2/cpu_usage2.c \
$(CPU_USAGE_PATCH) \
| $(BUILD_DIR)/config/i3blocks/scripts/.
patch -o "$@" "$<" "$(CPU_USAGE_PATCH)"
$(BUILD_DIR)/config/i3blocks/scripts/cpu_usage2: \
$(BUILD_DIR)/config/i3blocks/scripts/cpu_usage2.c
$(CC) $(CFLAGS) -o "$@" "$<"
###########################
## Build Desktop Files ##
###########################
$(BUILD_DIR)/data/$(DATA_SPOTIFY_DESKTOP):\
$(BUILD_DIR)/data/$(DATA_SPOTIFY_DESKTOP).sed\
$(SOURCE_SPOTIFY_DESKTOP)
sed -f "$<" "$(SOURCE_SPOTIFY_DESKTOP)" > "$@"
$(BUILD_DIR)/data/$(DATA_STEAM_DESKTOP):\
$(BUILD_DIR)/data/$(DATA_STEAM_DESKTOP).sed\
$(SOURCE_STEAM_DESKTOP)
sed -f "$<" "$(SOURCE_STEAM_DESKTOP)" > "$@"
#########################
## Build Environment ##
#########################
$(BUILD_DIR)/env/%.m4: $(SOURCE_DIR)/env/% \
$(SOURCE_DIR)/env/env_utils\
$(BUILD_DIR)/env/paths.sh\
$(UTILS_DIR)/config-replace.sh
source "$(BUILD_DIR)/env/paths.sh" && \
"$<" | \
$(UTILS_DIR)/config-replace.sh \
"$(ENV_CONFIG_PREFIX)" "$(QUOTE_START)" "$(QUOTE_END)" | \
(echo "m4_dnl $<" && cat) > "$@"
$(BUILD_DIR)/env/colours.m4: $(SOURCE_DIR)/env/colours.toml
$(BUILD_DIR)/user_config.m4: user.cfg\
$(UTILS_DIR)/config-replace.sh\
| $(BUILD_DIR)/.
sed -e 's/\s*#.*$$//' -e '/^\s*$$/d' $< | \
$(UTILS_DIR)/config-replace.sh \
"${USER_CONFIG_PREFIX}" "${QUOTE_START}" "${QUOTE_END}" > $@
$(BUILD_DIR)/env/paths.sh: user.cfg | $(BUILD_DIR)/env/.
grep -e '^ *[A-Z_]*\(HOME\|PREFIX\) *=' user.cfg | \
sed -e "s/^/export /" > "$@"
$(BUILD_DIR)/env/absolute_paths.m4: user.cfg\
$(UTILS_DIR)/config-replace.sh\
| $(BUILD_DIR)/env/.
# Will fail if $HOME contains | characters
sed user.cfg -n -e "s|=~|=$(HOME)|" -e "/\(HOME\|PREFIX\)=/p" |\
$(UTILS_DIR)/config-replace.sh \
"${ENV_CONFIG_PREFIX}" "${QUOTE_START}" "${QUOTE_END}" |\
(echo "m4_dnl $<" && cat) > "$@"
$(BUILD_DIR)/env_config.m4: $(ENV_CONFIG_TARGETS) \
$(BUILD_DIR)/env/absolute_paths.m4 |\
$(BUILD_DIR)/.
cat $^ > "$@"
########################
## Show Information ##
########################
.PHONY: show show-dirs show-config show-wants show-links
show: show-dirs show-config show-wants
show-dirs:
@echo "HOME_DIR: $(HOME_DIR)"
@echo "BIN_DIR: $(BIN_DIR)"
@echo "CONFIG_DIR: $(CONFIG_DIR)"
@echo "DATA_DIR: $(DATA_DIR)"
@echo "CACHE_DIR: $(CACHE_DIR)"
@echo "SYSTEM_PREFIX: $(SYSTEM_PREFIX)"
PYGMENTIZE:=$(shell command -v pygmentize)
ifdef PYGMENTIZE
# pygmentize does not apply the right colours for dark background on
# vim style so use a different style that does work.
COLORIZE_CONFIG:=pygmentize -l 'cfg' -O style=inkpot -f terminal256
else
COLORIZE_CONFIG:=cat
endif
ESCAPED_QUOTE_START=$(subst [,\[,$(subst ],\],$(QUOTE_START)))
ESCAPED_QUOTE_END=$(subst [,\[,$(subst ],\],$(QUOTE_END)))
show-config: user.cfg $(BUILD_DIR)/env_config.m4
ifndef PYGMENTIZE
@echo "Install pygmentize (python pygments) to view coloured output."
@echo
endif
@echo '# User Config' | cat - user.cfg | $(COLORIZE_CONFIG)
@echo
@echo '# Environment Config' | cat - $(BUILD_DIR)/env_config.m4 | \
sed -e "s/^m4_dnl/#/" \
-e "s/$(ESCAPED_QUOTE_START)//g" \
-e "s/$(ESCAPED_QUOTE_END)//g" \
-e "s/^m4_define(m4_env_config_//" \
-e "s/)m4_dnl$$//" \
-e "s/,/=/" | \
$(COLORIZE_CONFIG)
show-wants: $(SOURCE_DIR)/env/wants \
$(SOURCE_DIR)/env/env_utils \
$(SOURCE_DIR)/env/display
@"$<" | $(COLORIZE_CONFIG)
show-links: build $(UTILS_DIR)/check-links
@$(UTILS_DIR)/check-links
###############
## Install ##
###############
# Args: INSTALL_DIR SOURCE_TYPE
define INSTALL_TEMPLATE
$1/%: $(SOURCE_DIR)/$2/%
@if [ -x "$$<" ]; then \
install -v -m 755 "$$<" "$$@"; \
else \
install -v -m 644 "$$<" "$$@"; \
fi
$1/%: $(BUILD_DIR)/$2/%
@if [ -x "$$<" ]; then \
install -v -m 755 "$$<" "$$@"; \
else \
install -v -m 644 "$$<" "$$@"; \
fi
$1/%: | $(BUILD_DIR)/$2/%.link
DEST="$$$$(grep -m 1 "[^[:space:]]" "$$(patsubst $1/%,$(BUILD_DIR)/$2/%.link,$$@)")"; \
[ -n "$$$$DEST" ] && ! [ -d "$$@" ] && \
ln -s -f "$$$$DEST" "$$@"
$1/%: | $(BUILD_DIR)/$2/%.dlink
DEST="$$$$(grep -m 1 "[^[:space:]]" "$$(patsubst $1/%,$(BUILD_DIR)/$2/%.dlink,$$@)")"; \
[ -n "$$$$DEST" ] && ! [ -d "$$@" ] && \
ln -s -f "$$$$DEST" "$$@" && \
mkdir -p "$$$$DEST"
endef
$(eval $(call INSTALL_TEMPLATE,$(BIN_DIR),bin))
$(eval $(call INSTALL_TEMPLATE,$(CONFIG_DIR),config))
$(eval $(call INSTALL_TEMPLATE,$(DATA_DIR),data))
$(eval $(call INSTALL_TEMPLATE,$(HOME_DIR),home))
$(eval $(call INSTALL_TEMPLATE,$(SYSTEM_PREFIX),system))
###########
## Vim ##
###########
.PHONY: vim vim-vundle vim-plugins vim-ycm vim-tmuxline
vim: vim-vundle vim-plugins vim-ycm vim-tmuxline
VUNDLE_TARGET:=$(DATA_DIR)/$(DATA_VUNDLE_DIR)
vim-vundle: | $(VUNDLE_TARGET)
$(VUNDLE_TARGET): | $(dir $(VUNDLE_TARGET)).
cd $(dir $@) && git clone https://github.com/VundleVim/Vundle.vim.git
vim-plugins: $(BUILD_DIR)/config/vim/vimrc vim-vundle
vim -enN -i NONE -u "$<" +PluginInstall +PluginUpdate +qall
YCM_DIR:=$(DATA_DIR)/vim/bundle/YouCompleteMe
YCM_CORE:=$(YCM_DIR)/third_party/ycmd/ycm_core.so
YCM_GIT_CHECKOUT:=$(YCM_DIR)/.git/logs/HEAD
PYTHON := $(shell command -v python3 || command -v python)
vim-ycm: $(YCM_CORE)
$(YCM_CORE): $(YCM_GIT_CHECKOUT)
cd $(YCM_DIR) && \
$(PYTHON) ./install.py --clangd-completer \
$$(if [[ "$$(uname -r)" == *ARCH* ]]; then echo --system-libclang; fi)
TMUXLINE_CONFIG:=tmux/tmuxline.conf
TMUXLINE_TARGET:=$(CONFIG_DIR)/$(TMUXLINE_CONFIG)
RANDOM_ID:=$(shell echo $$RANDOM)
vim-tmuxline: $(TMUXLINE_TARGET)
$(TMUXLINE_TARGET): $(BUILD_DIR)/config/vim/vimrc \
| $(dir $(TMUXLINE_TARGET)).
# Start a new temporary tmux session and in that tmux session run vim
# and in vim call TmuxlineSnapshot to save the tmuxline configuration to
# tmuxline.conf
tmux new-session -d -s 'tmuxline-$(RANDOM_ID)' 'vim -enN -i NONE -u "$<" +"TmuxlineSnapshot! $@" +qall'
while tmux list-sessions 2>/dev/null | grep 'tmuxline-$(RANDOM_ID)' >/dev/null ; do \
sleep 0.05; \
done
@if [ ! -f "$@" ]; then \
echo "$(WARNING_PREFIX) Unable to generate tmuxline snapshot. Install tmuxline vim plugin and remake."; \
false; \
fi
#########################
## Persisent Configs ##
#########################
.PHONY: persistent-configs
persistent-configs: $(BUILD_DIR)/make/persistent-configs
$(BUILD_DIR)/make/persistent-configs: \
$(UTILS_DIR)/set-persistent-configs.sh \
$(INSTALLED_SYSTEMD_FILES) \
| $(BUILD_DIR)/make/
$(UTILS_DIR)/set-persistent-configs.sh
touch "$@"
######################
## Systemd Reload ##
######################
.PHONY: systemd-reload
systemd-reload: $(BUILD_DIR)/make/systemd-reload
SYSTEMCTL := $(shell command -v systemctl 2>/dev/null)
ifdef SYSTEMCTL
$(BUILD_DIR)/make/systemd-reload: \
$(INSTALLED_SYSTEMD_CONFIGS) \
| $(BUILD_DIR)/make/.
if systemctl --quiet --user is-system-running; then \
echo "Reloading systemd user configuration"; \
systemctl --user daemon-reload; \
fi
else
$(BUILD_DIR)/make/systemd-reload: | $(BUILD_DIR)/make/.
endif
touch "$@"
##################
## Font Cache ##
##################
.PHONY: font-cache
font-cache: $(BUILD_DIR)/make/font-cache
$(BUILD_DIR)/make/font-cache: $(INSTALLED_FONT_FILES) | $(BUILD_DIR)/make/.
fc-cache -v $(DATA_DIR)/fonts/
touch "$@"
########################
## Make Directories ##
########################
define MKDIR_DEPENDENCY_TEMPLATE
$1: | $(dir $1).
endef
# Targets that might be the first in their directory
ORIGINAL_TARGETS:=\
$(FIRST_BUILD_TARGETS)\
$(INSTALL_TARGETS)\
$(INSTALL_ONCE_TARGETS)\
$(INSTALL_SYSTEM_TARGETS)\
$(TMUXLINE_TARGET)\
$(BUILD_DIR)/.\
$(BUILD_DIR)/make/.\
# Exclude directories
ORIGINAL_FILE_TARGETS:=$(filter-out %/.,$(ORIGINAL_TARGETS))
$(foreach TARGET,$(ORIGINAL_FILE_TARGETS),\
$(eval $(call MKDIR_DEPENDENCY_TEMPLATE,$(TARGET))))
# Use a template so that this rule is preferred over the generic install copy
# rule.
.PRECIOUS: %/.
define MKDIR_TEMPLATE
$1.:
mkdir -p "$$@"
endef
$(foreach TARGET_DIR,\
$(sort $(BUILD_DIR)/ $(BUILD_DIR)/make/ $(dir $(ORIGINAL_TARGETS))),\
$(eval $(call MKDIR_TEMPLATE,$(TARGET_DIR))))