summaryrefslogtreecommitdiff
path: root/Makefile
blob: fb76c8a7029a5b8fece15964515fa159f49daca8 (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
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
DOCS?=$(shell pwd)/docs
IMAGE?=$(shell pwd)/image

all:	$(addsuffix .html,$(basename $(shell find -type f -name '*.mkd' -not -wholename './docs*')))
	@echo $?

%.html:	%.mkd head.part.tmpl foot.part.tmpl contributors.part.tmpl
	@echo "Generating $@ ..."
	@ruby -e "File.open('$<.tmp', 'w') {|file| file.write File.read('$<').gsub(/#\{include ([0-9A-Za-z_.]+)\}/) {|z| File.read(\"#{\$$1}.part.tmpl\")}}"
	@sed -i -e '1 s,^Title: ,Title: Exherbo - ,' $<.tmp
	@maruku --html --output $@ $<.tmp
	@sed -i -e 's,<head>,&<link rel="shortcut icon" href="/favicon.png" />,' $@
	@sed -i -e 's,<td />,<td></td>,g' $@
	@sed -i -e 's,</nav>,</nav><div class="container">,;s,</body>,</div></body>,' $@
	@sed -i -e 's,<html.*xml:,<html ,' $@
	@sed -i -e '/^<?xml/ { N;N;N;d; };s/<html /<!DOCTYPE html>\n<html /' $@
	@sed -i -e 's,<table>,<table class="table">,g' $@
	@sed -i -e 's,</head>,<meta name="viewport" content="width=device-width\, initial-scale=1\, maximum-scale=1\, user-scalable=no" /><link rel="shortcut icon" href="/favicon.ico" /></head>,' $@
	@if [[ "$<" == developers.mkd ]];then make --no-print-directory developers;fi
	@rm $<.tmp

developers: developers.html
	@sed 's|<tbody><tr>|<tbody>\n<tr>|' -i developers.html
	@for dev in $$(grep '^<tr>' developers.html | cut -d'>' -f3 | cut -d'<' -f1);do \
		printf "$$dev... "; \
		gravatar=$$(echo "$$dev" | ./cgit/filters/email-gravatar.sh "$$dev@exherbo.org" 32); \
		sed "s|>$$dev<|>$$gravatar<|;s|>$$dev<d|\&amp;d|" -i developers.html; done
	@echo

deploy:	all
	@if [[ -d "$(IMAGE)" ]];then mkdir -p "$(IMAGE)";fi
	@rsync -a . "$(IMAGE)" \
		--delete-after \
		--exclude "$(IMAGE)" \
		--exclude image \
		--exclude '*.git*' \
		--exclude '*.mkd' \
		--exclude 'Makefile' \
		--exclude '*.tmp' \
		--exclude docs/
	@if [[ -d "$(DOCS)" ]];then make --no-print-directory -C "$(DOCS)" IMAGE="$(IMAGE)/docs" deploy;fi
	@pwd=$(PWD);pushd "$(IMAGE)" >/dev/null 2>&1;for file in **/*.js **/*.css;do \
		make --no-print-directory -C "$$pwd" FILE="$(IMAGE)/$$file" minify; done; popd >/dev/null 2>&1
	@echo "Run \`python2 -m SimpleHTTPServer 8080\` in \"$(IMAGE)\" to view the webpages."

ifdef NO_MINIFY

minify:
	@true

else

minify:
	@if [[ -z "$(FILE)" ]];then echo "FILE=<file to minify>" >&2; exit 1;fi
	@echo "Minifying $(FILE) ..."
	@sed \
		-e "s|/\*\(\\\\\)\?\*/|/~\1~/|g" \
		-e "s|/\*[^*]*\*\+\([^/][^*]*\*\+\)*/||g" \
		-e "s|\([^:/]\)//.*$$|\1|" -e "s|^//.*$$||" \
		"$(FILE)" >"$(FILE)".tmp
	@cat "$(FILE)".tmp > "$(FILE)"
	@tr '\n' ' ' <"$(FILE)" > "$(FILE)".tmp
	@sed \
		-e "s|/\*[^*]*\*\+\([^/][^*]*\*\+\)*/||g" \
		-e "s|/\~\(\\\\\)\?\~/|/*\1*/|g" \
		-e "s|\s\+| |g" \
		-e "s| \([{;:,]\)|\1|g" \
		-e "s|\([{;:,]\) |\1|g" \
		-e "s/^ *//;s/ *$$//" \
		-i "$(FILE).tmp"
	@cat "$(FILE)".tmp > "$(FILE)"
	@rm "$(FILE)".tmp


endif

ifdef NO_CONTRIBUTORS

contributors.part.tmpl:
	@echo "Generating stub $@"
	@git config --global user.name >$@

else

contributors.part.tmpl:
	@echo "Generating $@ ..."
	@echo > $@.tmp
	@for repo in ../*/; do ( cd "$${repo}" && git log --format="%aN," ) >> $@.tmp; done
	@sort -fu $@.tmp | tr '\n' ' ' | sed 's/\(.*\)\,/\1\n/' > $@
	@rm $@.tmp

endif

clean:
	rm -rf *.tmp *.html contributors.part.tmpl

.phony:	clean