summaryrefslogtreecommitdiff
path: root/Makefile
blob: d27cd56c3deafa66848b18b70519314162602053 (plain)
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
url=https://webcache.googleusercontent.com/search?q=cache:http://$1+lukeshu.ath.cx&hl=en
ua=Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111009 IceCat/7.0.1

define deps
sed 's/[ \t<>]/\n/g #tokenize' '$1'|\
grep href |\
sed -r \
  -e "s/'/\"/g                     #normalize quotes" \
  -e 's@^href="http://([^"]*)"@\1@ #strip href off  ' \
  -e 's@^/@http://lukeshu.ath.cx/@ #fix docroot     ' \
  |\
grep '^lukeshu\.ath\.cx/1/wordpress' |\
fgrep -v '/feed/'          |\
fgrep -v '/wp-admin/'      |\
fgrep -v '/wp-content/'    |\
fgrep -v 'wlwmanifest.xml' |\
fgrep -v 'xmlrpc.php'      |\
fgrep -v 'wp-login.php'    |\
sed 's/\#.*//' | sort | uniq
endef

sleep = x=$$RANDOM; let 'x %= 15'; sleep $$((30+$$x))
download = wget -U '$(ua)' '$(call url,$1)'  -O tmp/$$$$ && mkdir -vp $(@D) && mv -v tmp/$$$$ $@

default:
	rm -rf mk
	$(MAKE) mk/lukeshu.ath.cx/1/wordpress/2011/05/why-sed-i-exists/index.chtml
.SECONDARY:

web/%:
	$(call download,$*); $(sleep)
web/%/index.chtml:
	$(call download,$*/); $(sleep)

dep/%: web/% Makefile
	test -f $<
	mkdir -p $(@D)
	$(call deps,$<) > $@

mk/%: dep/%
	mkdir -p $(@D)
	touch $@
	sed -e 's@.@mk/&@' -e 's@/$$@/index.chtml@' $< |xargs -d '\n' $(MAKE) -k

%.html: %.chtml
	sed '1,3d' < $< > $@

html:
	find web -name '*.chtml'|sed 's/chtml$$/html/' |xargs $(MAKE)