• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1SHELL=/usr/bin/env bash
2SED ?= $(shell which gsed 2>/dev/null || which sed)
3
4MKDOCS_PAGES=$(shell cd ../mkdocs/docs/ && find * -type f -name '*.md' | sort)
5
6.PHONY: all
7all: JSON_for_Modern_C++.tgz
8
9docSet.dsidx: docSet.sql
10	# generate index
11	sqlite3 docSet.dsidx <docSet.sql
12
13JSON_for_Modern_C++.docset: Info.plist docSet.dsidx
14	rm -fr JSON_for_Modern_C++.docset JSON_for_Modern_C++.tgz
15	mkdir -p JSON_for_Modern_C++.docset/Contents/Resources/Documents/
16	cp icon*.png JSON_for_Modern_C++.docset
17	cp Info.plist JSON_for_Modern_C++.docset/Contents
18	# build and copy documentation
19	$(MAKE) build -C ../mkdocs
20	cp -r ../mkdocs/site/* JSON_for_Modern_C++.docset/Contents/Resources/Documents
21	# patch CSS to hide navigation items
22	echo -e "\n\nheader, footer, nav.md-tabs, nav.md-tabs--active, div.md-sidebar--primary, a.md-content__button { display: none; }" >> "$$(ls JSON_for_Modern_C++.docset/Contents/Resources/Documents/assets/stylesheets/main.*.min.css)"
23	# fix spacing
24	echo -e "\n\ndiv.md-sidebar div.md-sidebar--secondary, div.md-main__inner { top: 0; margin-top: 0 }" >> "$$(ls JSON_for_Modern_C++.docset/Contents/Resources/Documents/assets/stylesheets/main.*.min.css)"
25	# remove "JSON for Modern C++" from page titles (fallback)
26	find JSON_for_Modern_C++.docset/Contents/Resources/Documents -type f -exec $(SED) -i 's| - JSON for Modern C++</title>|</title>|' {} +
27	# replace page titles with name from index, if available
28	for page in $(MKDOCS_PAGES); do \
29		case "$$page" in \
30			*/index.md) path=$${page/\/index.md/} ;; \
31			*)          path=$${page/.md/}        ;; \
32		esac; \
33		title=$$(sqlite3 docSet.dsidx "SELECT name FROM searchIndex WHERE path='$$path/index.html'" | tr '\n' ',' | $(SED) -e 's/,/, /g' -e 's/, $$/\n/'); \
34		if [ "x$$title" != "x" ]; then \
35			$(SED) -i "s%<title>.*</title>%<title>$$title</title>%" "JSON_for_Modern_C++.docset/Contents/Resources/Documents/$$path/index.html"; \
36		fi \
37	done
38	# clean up
39	rm JSON_for_Modern_C++.docset/Contents/Resources/Documents/sitemap.*
40	# copy index
41	cp docSet.dsidx JSON_for_Modern_C++.docset/Contents/Resources/
42
43JSON_for_Modern_C++.tgz: JSON_for_Modern_C++.docset
44	tar --exclude='.DS_Store' -cvzf JSON_for_Modern_C++.tgz JSON_for_Modern_C++.docset
45
46# install docset for Zeal documentation browser (https://zealdocs.org/)
47.PHONY: install_docset_zeal
48install_docset_zeal: JSON_for_Modern_C++.docset
49	docset_root=$${XDG_DATA_HOME:-$$HOME/.local/share}/Zeal/Zeal/docsets; \
50	rm -rf $$docset_root/JSON_for_Modern_C++.docset; \
51	mkdir -p $$docset_root; \
52	cp -r JSON_for_Modern_C++.docset $$docset_root/
53
54# list mkdocs pages missing from the docset index
55.PHONY: list_missing_pages
56list_missing_pages: docSet.dsidx
57	@for page in $(MKDOCS_PAGES); do \
58		case "$$page" in \
59			*/index.md) path=$${page/\/index.md/} ;; \
60			*)          path=$${page/.md/}        ;; \
61		esac; \
62		if [ "x$$page" != "xindex.md" -a "x$$(sqlite3 docSet.dsidx "SELECT COUNT(*) FROM searchIndex WHERE path='$$path/index.html'")" = "x0" ]; then \
63			echo $$page; \
64		fi \
65	done
66
67# list paths in the docset index without a corresponding mkdocs page
68.PHONY: list_removed_paths
69list_removed_paths: docSet.dsidx
70	@for path in $$(sqlite3 docSet.dsidx "SELECT path FROM searchIndex"); do \
71		page=$${path/\/index.html/.md}; \
72		page_index=$${path/index.html/index.md}; \
73		page_found=0; \
74		for p in $(MKDOCS_PAGES); do \
75			if [ "x$$p" = "x$$page" -o "x$$p" = "x$$page_index" ]; then \
76				page_found=1; \
77			fi \
78		done; \
79		if [ "x$$page_found" = "x0" ]; then \
80			echo $$path; \
81		fi \
82	done
83
84.PHONY: clean
85clean:
86	rm -f docSet.dsidx
87	rm -fr JSON_for_Modern_C++.docset JSON_for_Modern_C++.tgz
88