aboutsummaryrefslogtreecommitdiff
path: root/Makefile.m4
blob: 171cef5b4d52de2ae19c3b32f3d495e6d9226414 (plain) (blame)
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
CONFIG_FILE := config
M4 := m4
M4_OPTS := -P
M4_SYSFILE := system.m4
M4_COMMON_DEPS = $(M4_SYSFILE)
SRC_DIR := DT_DOTFILES_DIR
HOME_DIR := DT_HOME_DIRECTORY

.PHONY: install_packages update_packages

define M4_EXEC
	echo "`m4_include'(\``system.m4'')`m4_dnl'" | cat - $< | ${M4} ${M4_OPTS} > $@
endef

define create_symlink
@if [ ! -L "$(2)" ]; then \
    echo "Creating new symlink $(2) -> $(1)"; \
    ln -isf $(1) $(2); \
elif [ "$$(readlink $(2))" != "$(1)" ]; then \
    echo "Symlink exists but points to a different source. Updating symlink $(2) -> $(1)"; \
    ln -sf $(1) $(2); \
fi
endef

define create_dotfile_symlink
	$(call create_symlink,${SRC_DIR}/$(1),${HOME_DIR}/$(2))
endef

all: system.m4 install_packages m4_dnl
m4_ifelse(DT_OTHER_SYMLINKS, `yes', `$(HOME_DIR)/.vimrc') m4_dnl
m4_ifelse(DT_OTHER_SYMLINKS, `yes', `$(HOME_DIR)/.vim') m4_dnl
m4_ifelse(DT_OTHER_SYMLINKS, `yes', `$(HOME_DIR)/.config/rofi') m4_dnl
m4_ifelse(DT_OTHER_SYMLINKS, `yes', `$(HOME_DIR)/.config/deadd') m4_dnl
m4_ifelse(DT_OTHER_SYMLINKS, `yes', `$(HOME_DIR)/.config/waybar') m4_dnl
m4_ifelse(DT_OTHER_SYMLINKS, `yes', `$(HOME_DIR)/.config/foot') m4_dnl
m4_ifelse(DT_OTHER_SYMLINKS, `yes', `$(HOME_DIR)/.config/alacritty') m4_dnl
m4_ifelse(DT_OTHER_SYMLINKS, `yes', `$(HOME_DIR)/.config/powerline') m4_dnl
m4_ifelse(DT_OTHER_SYMLINKS, `yes', `$(HOME_DIR)/.config/sxhkd') m4_dnl
m4_ifelse(DT_OTHER_SYMLINKS, `yes', `$(HOME_DIR)/.config/bspwm') m4_dnl
m4_ifelse(DT_HOMEBIN, `yes', `$(HOME_DIR)/bin') m4_dnl
m4_ifelse(DT_ZSH, `yes', `$(HOME_DIR)/.zshrc') m4_dnl
m4_ifelse(DT_ZSH, `yes', `$(HOME_DIR)/.p10k.zsh') m4_dnl
m4_ifelse(DT_BASH, `yes', `$(HOME_DIR)/.bashrc') m4_dnl
m4_ifelse(DT_TMUX, `yes', `$(HOME_DIR)/.tmux.conf') m4_dnl
m4_ifelse(DT_QTILE, `yes', `$(HOME_DIR)/.config/qtile/config.py') m4_dnl
m4_ifelse(DT_SWAY, `yes', `$(HOME_DIR)/.config/sway/config') m4_dnl
m4_ifelse(DT_SWAY, `yes', `$(HOME_DIR)/.config/sway/hid') m4_dnl
m4_ifelse(DT_SWAY, `yes', `$(HOME_DIR)/.config/sway/autostart') m4_dnl
m4_ifelse(DT_NEOVIM, `yes', `$(HOME_DIR)/.config/nvim') m4_dnl


$(M4_SYSFILE): $(CONFIG_FILE)
	@echo "Generating $(M4_SYSFILE) from $(CONFIG_FILE)"
	@> $(M4_SYSFILE)
	@while IFS='=' read -r key value; do \
		echo "`m4_define'(\``$$key'', \``$$value'')`m4_dnl'" >> $(M4_SYSFILE); \
	done < $(CONFIG_FILE)

m4_ifelse(DT_OTHER_SYMLINKS, `yes', `m4_dnl
$(HOME_DIR)/.vimrc: Common/vimrc
	$(call create_dotfile_symlink,Common/vimrc,.vimrc)

$(HOME_DIR)/.vim: Common/vim
	$(call create_dotfile_symlink,Common/vim,.vim)

$(HOME_DIR)/.config/rofi: linux/rofi
	$(call create_dotfile_symlink,linux/rofi,.config/rofi)

$(HOME_DIR)/.config/deadd: linux/deadd/
	$(call create_dotfile_symlink,linux/deadd,.config/deadd)

$(HOME_DIR)/.config/waybar: linux/waybar
	$(call create_dotfile_symlink,linux/waybar,.config/waybar)

$(HOME_DIR)/.config/foot: linux/foot
	$(call create_dotfile_symlink,linux/foot,.config/foot)

$(HOME_DIR)/.config/alacritty: linux/alacritty
	$(call create_dotfile_symlink,linux/alacritty,.config/alacritty)

$(HOME_DIR)/.config/powerline: linux/powerline_config
	$(call create_dotfile_symlink,linux/powerline_config,.config/powerline)

$(HOME_DIR)/.config/sxhkd: linux/sxhkd
	$(call create_dotfile_symlink,linux/sxhkd,.config/sxhkd)

$(HOME_DIR)/.config/bspwm: linux/bspwm
	$(call create_dotfile_symlink,linux/bspwm,.config/bspwm)

')m4_dnl
m4_ifelse(DT_HOMEBIN, `yes', `m4_dnl
$(HOME_DIR)/bin: bin
	$(call create_dotfile_symlink,bin,bin)

')m4_dnl
m4_ifelse(DT_BASH, `yes', `m4_dnl
Common/bashrc: Common/bashrc.m4                                                 \
              ${M4_COMMON_DEPS}
	$(call M4_EXEC)

$(HOME_DIR)/.bashrc: Common/bashrc
	$(call create_dotfile_symlink,Common/bashrc,.bashrc)

')m4_dnl
m4_ifelse(DT_ZSH, `yes', `m4_dnl
Common/zshrc: Common/zshrc.m4                                                 \
              ${M4_COMMON_DEPS}
	$(call M4_EXEC)

$(HOME_DIR)/.zshrc: Common/zshrc
	$(call create_dotfile_symlink,Common/zshrc,.zshrc)

m4_ifelse(DT_ZSH, `yes', `m4_dnl
$(HOME_DIR)/.p10k.zsh: Common/vim
	$(call create_dotfile_symlink,Common/p10k.zsh,.p10k.zsh)

')m4_dnl
')m4_dnl
m4_ifelse(DT_TMUX, `yes', `m4_dnl
linux/tmux.conf: linux/tmux.conf.m4                                           \
                 ${M4_COMMON_DEPS}
	$(call M4_EXEC)
	$(call create_symlink,$(SRC_DIR)/Common/nvim,$(HOME_DIR)/.config/nvim)

$(HOME_DIR)/.tmux.conf: linux/tmux.conf
	$(call create_dotfile_symlink,linux/tmux.conf,.tmux.conf)

')m4_dnl
m4_ifelse(DT_SWAY, `yes', `m4_dnl
linux/sway/%: linux/sway/%.m4                                                 \
                      ${M4_COMMON_DEPS}
	$(call M4_EXEC)

$(HOME_DIR)/.config/sway/%: linux/sway/config linux/sway/hid linux/sway/autostart
	$(call create_symlink,${SRC_DIR}/linux/sway,$(HOME_DIR)/.config/sway)

')m4_dnl
m4_ifelse(DT_QTILE, `yes', `m4_dnl
linux/qtile/config/config.py: linux/qtile/config/config.py.m4                 \
                              linux/qtile/config/screen.m4.py                 \
                              linux/qtile/config/group.m4.py                  \
                              linux/qtile/config/layout.m4.py                 \
                              linux/qtile/config/keys.m4.py                   \
                              ${M4_COMMON_DEPS}
	$(call M4_EXEC)

$(HOME_DIR)/.config/qtile/config.py: linux/qtile/config/config.py
	$(call create_symlink,$(SRC_DIR)/linux/qtile/config/,$(HOME_DIR)/.config/qtile/)
	sudo cp linux/qtile/qtile.desktop /usr/share/xsessions/qtile.desktop
	sudo cp linux/qtile/qtile-wayland.desktop /usr/share/wayland-sessions/qtile-wayland.desktop

')m4_dnl
m4_ifelse(DT_NEOVIM, `yes', `m4_dnl
/usr/local/bin/nvim:
	git clone https://github.com/neovim/neovim /tmp/neovim
	git -C /tmp/neovim checkout tags/v0.9.5
	(cd /tmp/neovim && sudo make install)

$(HOME_DIR)/.config/nvim/: /usr/local/bin/nvim
	$(call create_symlink,$(SRC_DIR)/Common/nvim,$(HOME_DIR)/.config/nvim)

')m4_dnl

# General package manager stuff
m4_ifelse(DT_DISTRO, `debian', m4_dnl
DPKG_DEPENDENCIES := m4_dnl
m4_ifelse(DT_TOOLS, `yes', `highlight atool w3m mediainfo curl zsh vim git python3-pip zsh tmux nodejs catimg ripgrep silversearcher-ag',) m4_dnl
m4_ifelse(DT_GREETD_TUIGREET', `yes', `greetd',) m4_dnl
m4_ifelse(DT_TLP, `yes', `tlp',) m4_dnl
m4_dnl
m4_ifelse(DT_SWAY, `yes', `sway swayidle physlock alacritty blueman network-manager-gnome wob wlogout wofi brightnessctl clipman xwayland seahorse fcitx5',) m4_dnl
m4_dnl
m4_ifelse(DT_QTILE, `yes', `python3-cffi python3-cairocffi pango pango-devel python3-dbus-next',) m4_dnl qtile core
m4_ifelse(DT_QTILE, `yes', `python3_xcffib xsecurelock',) m4_dnl qtile x11
m4_ifelse(DT_QTILE, `yes', `wlroots python3-wlroots python3-pywayland python3-xkbcommon xwayland',) m4_dnl qtile wayland


install_packages:
	@missing_packages=""; \
	for pkg in $(DPKG_DEPENDENCIES); do \
		if ! dpkg -s "$$pkg" >/dev/null 2>&1; then \
			missing_packages="$$missing_packages $$pkg"; \
		fi; \
	done; \
	if [ -n "$$missing_packages" ]; then \
		echo "Installing missing packages: $$missing_packages"; \
		sudo apt-get update; \
		sudo apt-get install -y $$missing_packages; \
	fi

update_packages:
	@echo "Updating all packages..."
	sudo apt-get update
	sudo apt-get upgrade -y $(DPKG_DEPENDENCIES)
)m4_dnl

m4_ifelse(DT_DISTRO, `fedora', m4_dnl
DPKG_DEPENDENCIES := m4_dnl
m4_ifelse(DT_TOOLS, `yes', `highlight atool w3m mediainfo curl zsh vim-enhanced git python3-pip zsh tmux nodejs catimg ripgrep the_silver_searcher',) m4_dnl
m4_ifelse(DT_GREETD_TUIGREET', `yes', `greetd',) m4_dnl
m4_ifelse(DT_TLP, `yes', `tlp',) m4_dnl
m4_dnl
m4_ifelse(DT_SWAY, `yes', `sway swayidle alacritty blueman wob wlogout wofi brightnessctl clipman seahorse fcitx5 imsettings',) m4_dnl
m4_dnl
m4_ifelse(DT_QTILE, `yes', `python3-cffi python3-cairocffi pango pango-devel python3-dbus-next',) m4_dnl qtile core
m4_ifelse(DT_QTILE, `yes', `python3-xcffib xsecurelock',) m4_dnl qtile x11
m4_ifelse(DT_QTILE, `yes', `wlroots python3-pywayland python3-xkbcommon',) m4_dnl qtile wayland


install_packages:
	@missing_packages=""; \
	for pkg in $(DPKG_DEPENDENCIES); do \
		if ! rpm -q "$$pkg" >/dev/null 2>&1; then \
			missing_packages="$$missing_packages $$pkg"; \
		fi; \
	done; \
	if [ -n "$$missing_packages" ]; then \
		echo "Installing missing packages: $$missing_packages"; \
		sudo dnf install -y $$missing_packages; \
	fi

update_packages:
	@echo "Updating all packages..."
	sudo dnf upgrade -y $(DPKG_DEPENDENCIES)
)m4_dnl