-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
159 lines (130 loc) · 3.39 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
SHELL = /bin/bash
# FG_YELLOW = \x1b[0;33m
# ALL_RESET = \x1b[0m
# use empty string as false, so `ifneq ($VAR,)` === if bool(VAR)
# the `$$` will become `$`
USER_IS_MOSKY = $(shell whoami | grep '^mosky$$' -o)
WITH_VIM_7_x = $(shell vim --version | head -1 2> /dev/null | grep -F 'VIM - Vi IMproved 7.' -o)
WITH_TMUX_1_x = $(shell tmux -V 2> /dev/null | grep -F 'tmux 1.' -o)
WITH_TMUX_2_old = $(shell tmux -V 2> /dev/null | grep 'tmux 2\.[1-8]' -o)
ON_MAC = $(shell uname | grep 'Darwin' -o)
MKDIR = mkdir -p
CP = cp
CPB = cp -b
RM = rm -rf
RMI = rm -rf -i
ifneq ($(USER_IS_MOSKY),)
CPB = cp
RMI = rm -rf
endif
BASHRC_THE_SOURCING_LINE = for path in ~/.bashrc.d/*.sh; do . $$path; done
.PHONY: all
all: build/ \
build/bashrc.d/ \
build/bash_profile \
build/vimrc \
build/gitconfig \
build/tmux.conf \
build/ssh_config \
build/karabiner_bash_emacs.json
# $@: the target, i.e., 'build/'
build/:
$(MKDIR) $@
# $?: the newer prerequisites
build/bashrc.d/: configs/bashrc.d/*
$(MKDIR) $@
$(CP) $? $@
# $<: the first prerequisite
build/bash_profile: configs/bash_profile
ifneq ($(ON_MAC),)
$(CP) $< $@
endif
build/vimrc: configs/vimrc patches/vimrc_*.patch
$(CP) $< $@
ifneq ($(WITH_VIM_7_x),)
patch $@ patches/vimrc_7.x.patch
endif
build/gitconfig: configs/gitconfig \
patches/gitconfig_mosky.patch
$(CP) $< $@
ifneq ($(USER_IS_MOSKY),)
patch $@ patches/gitconfig_mosky.patch
endif
build/tmux.conf: configs/tmux.conf patches/tmux.conf_*.patch
$(CP) $< $@
ifneq ($(WITH_TMUX_1_x),)
patch $@ patches/tmux.conf_2_old.patch
patch $@ patches/tmux.conf_1.x.patch
endif
ifneq ($(WITH_TMUX_2_old),)
patch $@ patches/tmux.conf_2_old.patch
endif
build/ssh_config: configs/ssh_config
ifneq ($(ON_MAC),)
$(CP) $< $@
endif
build/%: configs/%
$(CP) $< $@
.PHONY: clean
clean:
$(RM) build/
.PHONY: install
install:
$(MKDIR) ~/.bashrc.d/
$(CPB) build/bashrc.d/* ~/.bashrc.d/
grep -F '$(BASHRC_THE_SOURCING_LINE)' ~/.bashrc \
|| echo $$'\n''$(BASHRC_THE_SOURCING_LINE)' >> ~/.bashrc
ifneq ($(ON_MAC),)
$(CPB) build/bash_profile ~/.bash_profile
endif
$(CPB) build/vimrc ~/.vimrc
$(CPB) build/gitconfig ~/.gitconfig
$(CPB) build/tmux.conf ~/.tmux.conf
ifneq ($(ON_MAC),)
$(CPB) build/ssh_config ~/.ssh/config
endif
ifneq ($(ON_MAC),)
$(MKDIR) ~/.config/karabiner/assets/complex_modifications/
$(CP) build/karabiner_bash_emacs.json ~/.config/karabiner/assets/complex_modifications/bash_emacs.json
endif
.PHONY: uninstall
uninstall:
$(RM) ~/.bashrc.d/
$(RMI) ~/.bashrc
ifneq ($(ON_MAC),)
$(RM) ~/.bash_profile
endif
$(RM) ~/.vimrc
$(RM) ~/.gitconfig
$(RM) ~/.tmux.conf
ifneq ($(ON_MAC),)
$(RM) ~/.ssh/config
endif
ifneq ($(ON_MAC),)
$(RM) ~/.config/karabiner/assets/complex_modifications/bash_emacs.json
endif
.PHONY: install-extra
install-extra:
ifneq ($(ON_MAC),)
./scripts/install-homebrew || true
./scripts/install-homebrew-formulas || true
./scripts/install-pip-packages || true
endif
./scripts/install-vim-plug || true
./scripts/install-vim-plug-plugins || true
.PHONY: config
config:
./scripts/config . '$(HOST)' '$(REMOTE_SHELL)'
.PHONY: debug
debug:
@echo HOST: $(HOST)
@echo REMOTE_SHELL: $(REMOTE_SHELL)
@echo USER_IS_MOSKY: $(USER_IS_MOSKY)
@echo WITH_TMUX_1_x: $(WITH_TMUX_1_x)
@echo WITH_TMUX_2_old: $(WITH_TMUX_2_old)
@echo ON_MAC: $(ON_MAC)
@echo MKDIR: $(MKDIR)
@echo CP: $(CP)
@echo CPB: $(CPB)
@echo RM: $(RM)
@echo RMI: $(RMI)