Add a common dir layout recipe
[khome.git] / Makefile
1 MAKEFLAGS := --no-builtin-rules
2 SHELL := /bin/bash
3
4 DEPS := $(wildcard deps/*)
5
6 ifeq ($(shell uname),Darwin)
7 GREP := ggrep
8 SED := gsed
9 DIFF := $(shell gls -t1 /usr/local/Cellar/diffutils/*/bin/diff | head -1)
10 else
11 GREP := grep
12 SED := sed
13 DIFF := diff
14 endif
15
16 .PHONY: \
17 default \
18 clean \
19 $(DEPS) \
20 deps \
21 home \
22 diff \
23 pull \
24 push \
25 dirs \
26 pkgs_void \
27 pkgs_void_update \
28 pkgs_brew_cask_install \
29 pkgs_brew_install \
30 pkgs_cargo \
31 pkgs_deb_install \
32 pkgs_deb_purge \
33 pkgs_debian \
34 pkgs_mac \
35 pkgs_pip_install \
36 pkgs_pip_upgrade \
37 pkgs_snap_classic \
38 pkgs_snap_strict
39
40 default:
41 @echo '================================================================================'
42 @echo '| Default target disabled. Specify a concrete one.'
43 @echo '================================================================================'
44 @exit 1
45
46 home: compiled dirs
47 cp -Rp bin $(HOME)/
48 $(MAKE) push
49 xdg-user-dirs-update
50
51 dirs:
52 mkdir -p ~/arc/aud
53 mkdir -p ~/arc/img
54 mkdir -p ~/arc/vid
55 mkdir -p ~/dl
56 mkdir -p ~/doc
57 mkdir -p ~/proj/{pub,priv}
58 mkdir -p ~/var/lib/mpd/playlists
59 mkdir -p ~/var/log/mpd
60 mkdir -p ~/var/run/mpd
61
62 compiled:
63 mkdir -p bin
64 cd src && make
65 mv src/clockloop bin/
66
67 font_cache:
68 fc-cache -fv
69
70 #
71 # Void Linux
72 #
73
74 pkgs_void:
75 sudo xbps-install $(shell ./list pkgs-void.list)
76
77 pkgs_void_update:
78 xbps-query -m | awk -F - '{sub("-" $$NF "$$", ""); print}' | sort -u | grep -vf <(./list -v sep='\n' -v end='\n' pkgs-void-src.list) > pkgs-void.list
79 (echo '#'; ./patch-comments pkgs-void.list.comments pkgs-void.list) | sponge pkgs-void.list
80
81 #
82 # Golang
83 #
84 pkgs_golang: list pkgs-golang.list
85 go get -u $(shell ./list pkgs-golang.list)
86
87 #
88 # Ubuntu
89 #
90 pkgs_ubuntu: list pkgs-ubuntu.list
91 sudo apt install $(shell ./list pkgs-ubuntu.list)
92
93 pkgs_ubuntu_debfiles: list pkgs-ubuntu-debfiles.list
94 ./install-debfiles pkgs-ubuntu-debfiles.list
95
96 #
97 # PIP
98 #
99 pkgs_pip_install:
100 pip install --user $(shell ./list pkgs-pip.list)
101
102 pkgs_pip_upgrade:
103 pip install --user --upgrade $(shell ./list pkgs-pip.list)
104
105 #
106 # Rust (cargo)
107 #
108
109 pkgs_cargo: list pkgs-cargo.list
110 cargo install $(shell ./list pkgs-cargo.list)
111
112 #
113 # Homebrew/Mac
114 #
115
116 pkgs_mac:
117 $(MAKE) pkgs_brew_install
118 $(MAKE) pkgs_brew_cask_install
119
120 # TODO: Test pkgs_brew_tap when list contains multiple items
121 pkgs_brew_tap: list pkgs-brew-tap.list
122 brew tap $(shell ./list pkgs-brew-tap.list)
123
124 pkgs_brew_install: list pkgs-brew-install.list
125 brew install $(shell ./list pkgs-brew-install.list)
126
127 pkgs_brew_cask_install: list pkgs-brew-cask-install.list
128 brew cask install $(shell ./list pkgs-brew-cask-install.list)
129
130 #
131 # Debian
132 #
133 pkgs_deb_install: list pkgs-deb-install.list
134 sudo apt install $(shell ./list pkgs-deb-install.list)
135
136 pkgs_deb_purge: list pkgs-deb-purge.list
137 sudo apt purge $(shell ./list pkgs-deb-purge.list)
138
139 #
140 # Snap
141 #
142 pkgs_snap_classic: list pkgs-snap-classic.list
143 @$(MAKE) $(foreach p,$(shell ./list pkgs-snap-classic.list),pkg_snap_classic_$(p))
144
145 pkgs_snap_strict: list pkgs-snap-strict.list
146 @$(MAKE) $(foreach p,$(shell ./list pkgs-snap-strict.list),pkg_snap_strict_$(p))
147
148 # 'snap' command comes from 'snapd' deb pkg
149 pkg_snap_classic_%:
150 sudo snap install --classic $*
151 pkg_snap_strict_%:
152 sudo snap install $*
153
154 deps: $(DEPS)
155
156 define GEN_DEP_RULE
157 $(1):
158 cd $1 && make
159 endef
160
161 $(foreach d,$(DEPS),$(eval $(call GEN_DEP_RULE,$(d))))
162
163 diff:
164 find home -type f -print0 \
165 | $(SED) -z 's/^home\///g' \
166 | sort -zr \
167 | xargs -0 -I% sh -c 'echo %; $(DIFF) --color=auto ~/% home/%'
168
169 pull:
170 find home -type f -print0 \
171 | $(SED) -z 's/^home\///g' \
172 | xargs -0 -I% sh -c '$(DIFF) -q ~/% home/% > /dev/null || cp ~/% home/%'
173
174 push:
175 # TODO Backup files before replacing.
176 # But - recursive copy is not a good strategy for this.
177 # Need to do a file by file pass, like the diff recipe.
178 #
179 # Limit depth because directories are copied recursively:
180 find home -maxdepth 1 -print0 \
181 | $(GREP) -zv '^home$$' \
182 | xargs -0 -I% cp -Rp % ~
183
184 clean:
185 rm -rf ./debfiles
186 cd src && make clean
This page took 0.06679 seconds and 5 git commands to generate.