Add recipe to find untracked ~/bin items
[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 $(shell ./list dirs)
53
54 compiled:
55 mkdir -p bin
56 cd src && make
57 mv src/clockloop bin/
58
59 font_cache:
60 fc-cache -fv
61
62 #
63 # Void Linux
64 #
65
66 pkgs_void:
67 sudo xbps-install $(shell ./list pkgs-void.list)
68
69 pkgs_void_update:
70 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
71 (echo '#'; ./patch-comments pkgs-void.list.comments pkgs-void.list) | sponge pkgs-void.list
72
73 #
74 # Golang
75 #
76 pkgs_golang: list pkgs-golang.list
77 go install $(shell ./list pkgs-golang.list)
78
79 #
80 # Ubuntu
81 #
82 pkgs_ubuntu: list pkgs-ubuntu.list
83 sudo apt install $(shell ./list pkgs-ubuntu.list)
84
85 pkgs_ubuntu_debfiles: list pkgs-ubuntu-debfiles.list
86 ./install-debfiles pkgs-ubuntu-debfiles.list
87
88 #
89 # PIP
90 #
91 pkgs_pip_install:
92 pip install --user $(shell ./list pkgs-pip.list)
93
94 pkgs_pip_upgrade:
95 pip install --user --upgrade $(shell ./list pkgs-pip.list)
96
97 #
98 # Rust (cargo)
99 #
100
101 pkgs_cargo: list pkgs-cargo.list
102 cargo install $(shell ./list pkgs-cargo.list)
103
104 #
105 # Homebrew/Mac
106 #
107
108 pkgs_mac:
109 $(MAKE) pkgs_brew_install
110 $(MAKE) pkgs_brew_cask_install
111
112 # TODO: Test pkgs_brew_tap when list contains multiple items
113 pkgs_brew_tap: list pkgs-brew-tap.list
114 brew tap $(shell ./list pkgs-brew-tap.list)
115
116 pkgs_brew_install: list pkgs-brew-install.list
117 brew install $(shell ./list pkgs-brew-install.list)
118
119 pkgs_brew_cask_install: list pkgs-brew-cask-install.list
120 brew cask install $(shell ./list pkgs-brew-cask-install.list)
121
122 #
123 # Debian
124 #
125 pkgs_deb_install: list pkgs-deb-install.list
126 sudo apt install $(shell ./list pkgs-deb-install.list)
127
128 pkgs_deb_purge: list pkgs-deb-purge.list
129 sudo apt purge $(shell ./list pkgs-deb-purge.list)
130
131 #
132 # Snap
133 #
134 pkgs_snap_classic: list pkgs-snap-classic.list
135 @$(MAKE) $(foreach p,$(shell ./list pkgs-snap-classic.list),pkg_snap_classic_$(p))
136
137 pkgs_snap_strict: list pkgs-snap-strict.list
138 @$(MAKE) $(foreach p,$(shell ./list pkgs-snap-strict.list),pkg_snap_strict_$(p))
139
140 # 'snap' command comes from 'snapd' deb pkg
141 pkg_snap_classic_%:
142 sudo snap install --classic $*
143 pkg_snap_strict_%:
144 sudo snap install $*
145
146 deps: $(DEPS)
147
148 define GEN_DEP_RULE
149 $(1):
150 cd $1 && make
151 endef
152
153 $(foreach d,$(DEPS),$(eval $(call GEN_DEP_RULE,$(d))))
154
155 diff:
156 find home -type f -print0 \
157 | $(SED) -z 's/^home\///g' \
158 | sort -zr \
159 | xargs -0 -I% sh -c 'echo %; $(DIFF) --color=auto ~/% home/%'
160
161 .PHONY: diff_bins_untracked
162 diff_bins_untracked:
163 ls -1 ~/bin | sort | grep -vf <(ls -1 home/bin | sort)
164
165 pull:
166 find home -type f -print0 \
167 | $(SED) -z 's/^home\///g' \
168 | xargs -0 -I% sh -c '$(DIFF) -q ~/% home/% > /dev/null || cp ~/% home/%'
169
170 push:
171 # TODO Backup files before replacing.
172 # But - recursive copy is not a good strategy for this.
173 # Need to do a file by file pass, like the diff recipe.
174 #
175 # Limit depth because directories are copied recursively:
176 find home -maxdepth 1 -print0 \
177 | $(GREP) -zv '^home$$' \
178 | xargs -0 -I% cp -Rp % ~
179
180 clean:
181 rm -rf ./debfiles
182 cd src && make clean
This page took 0.090188 seconds and 5 git commands to generate.