xref: /aosp_15_r20/external/selinux/secilc/docs/Makefile (revision 2d543d20722ada2425b5bdab9d0d1d29470e7bba)
1*2d543d20SAndroid Build Coastguard WorkerCWD = $(shell pwd)
2*2d543d20SAndroid Build Coastguard WorkerHTMLDIR = $(CWD)/html
3*2d543d20SAndroid Build Coastguard WorkerPDFDIR = $(CWD)/pdf
4*2d543d20SAndroid Build Coastguard WorkerTMPDIR = $(CWD)/tmp
5*2d543d20SAndroid Build Coastguard WorkerTESTDIR = $(CWD)/../test
6*2d543d20SAndroid Build Coastguard Worker
7*2d543d20SAndroid Build Coastguard Worker# All the markdown files that make up the guide:
8*2d543d20SAndroid Build Coastguard WorkerFILE_LIST ?= cil_introduction.md \
9*2d543d20SAndroid Build Coastguard Worker	cil_reference_guide.md \
10*2d543d20SAndroid Build Coastguard Worker	cil_access_vector_rules.md \
11*2d543d20SAndroid Build Coastguard Worker	cil_call_macro_statements.md \
12*2d543d20SAndroid Build Coastguard Worker	cil_class_and_permission_statements.md \
13*2d543d20SAndroid Build Coastguard Worker	cil_conditional_statements.md \
14*2d543d20SAndroid Build Coastguard Worker	cil_constraint_statements.md \
15*2d543d20SAndroid Build Coastguard Worker	cil_container_statements.md \
16*2d543d20SAndroid Build Coastguard Worker	cil_context_statement.md \
17*2d543d20SAndroid Build Coastguard Worker	cil_default_object_statements.md \
18*2d543d20SAndroid Build Coastguard Worker	cil_file_labeling_statements.md \
19*2d543d20SAndroid Build Coastguard Worker	cil_mls_labeling_statements.md \
20*2d543d20SAndroid Build Coastguard Worker	cil_network_labeling_statements.md \
21*2d543d20SAndroid Build Coastguard Worker	cil_policy_config_statements.md \
22*2d543d20SAndroid Build Coastguard Worker	cil_role_statements.md \
23*2d543d20SAndroid Build Coastguard Worker	cil_sid_statements.md \
24*2d543d20SAndroid Build Coastguard Worker	cil_type_statements.md \
25*2d543d20SAndroid Build Coastguard Worker	cil_user_statements.md \
26*2d543d20SAndroid Build Coastguard Worker	cil_infiniband_statements.md \
27*2d543d20SAndroid Build Coastguard Worker	cil_xen_statements.md
28*2d543d20SAndroid Build Coastguard Worker
29*2d543d20SAndroid Build Coastguard WorkerPANDOC_FILE_LIST = $(addprefix $(TMPDIR)/,$(FILE_LIST))
30*2d543d20SAndroid Build Coastguard Worker
31*2d543d20SAndroid Build Coastguard WorkerPANDOC_HIGHLIGHT_STYLE="theme.theme"
32*2d543d20SAndroid Build Coastguard Worker
33*2d543d20SAndroid Build Coastguard WorkerPDF_OUT=CIL_Reference_Guide.pdf
34*2d543d20SAndroid Build Coastguard WorkerHTML_OUT=CIL_Reference_Guide.html
35*2d543d20SAndroid Build Coastguard WorkerPANDOC = pandoc
36*2d543d20SAndroid Build Coastguard WorkerSED ?= sed
37*2d543d20SAndroid Build Coastguard Worker
38*2d543d20SAndroid Build Coastguard WorkerOS := $(shell uname)
39*2d543d20SAndroid Build Coastguard Workerifeq ($(OS), Darwin)
40*2d543d20SAndroid Build Coastguard Worker	SED := gsed
41*2d543d20SAndroid Build Coastguard Workerendif
42*2d543d20SAndroid Build Coastguard Worker
43*2d543d20SAndroid Build Coastguard Workerall: html pdf
44*2d543d20SAndroid Build Coastguard Worker
45*2d543d20SAndroid Build Coastguard Worker$(TMPDIR):
46*2d543d20SAndroid Build Coastguard Worker	mkdir -p $(TMPDIR)
47*2d543d20SAndroid Build Coastguard Worker
48*2d543d20SAndroid Build Coastguard Worker$(TMPDIR)/%.md: %.md | $(TMPDIR)
49*2d543d20SAndroid Build Coastguard Worker	cp -f $< $(TMPDIR)/
50*2d543d20SAndroid Build Coastguard Worker	@# Substitute markdown links for conversion into PDF links
51*2d543d20SAndroid Build Coastguard Worker	$(SED) -i -re 's:(\[`[^`]*`\])\([^#]*([^\)]):\1\(\2:g' $@
52*2d543d20SAndroid Build Coastguard Worker
53*2d543d20SAndroid Build Coastguard Worker$(TMPDIR)/policy.cil: $(TESTDIR)/policy.cil
54*2d543d20SAndroid Build Coastguard Worker	cp -f $< $@
55*2d543d20SAndroid Build Coastguard Worker	@# add a title for the TOC to policy.cil. This is needed to play nicely with the PDF conversion.
56*2d543d20SAndroid Build Coastguard Worker	$(SED) -i '1i Example Policy\n=========\n```secil' $@
57*2d543d20SAndroid Build Coastguard Worker	echo '```' >> $@
58*2d543d20SAndroid Build Coastguard Worker
59*2d543d20SAndroid Build Coastguard Workerhtml: $(PANDOC_FILE_LIST) $(TMPDIR)/policy.cil secil.xml
60*2d543d20SAndroid Build Coastguard Worker	mkdir -p $(HTMLDIR)
61*2d543d20SAndroid Build Coastguard Worker	$(PANDOC) \
62*2d543d20SAndroid Build Coastguard Worker		--highlight-style=$(PANDOC_HIGHLIGHT_STYLE) \
63*2d543d20SAndroid Build Coastguard Worker		--syntax-definition=secil.xml \
64*2d543d20SAndroid Build Coastguard Worker		--standalone \
65*2d543d20SAndroid Build Coastguard Worker		--metadata title="CIL Reference Guide" \
66*2d543d20SAndroid Build Coastguard Worker		--metadata document-css=false \
67*2d543d20SAndroid Build Coastguard Worker		-t html \
68*2d543d20SAndroid Build Coastguard Worker		$(PANDOC_FILE_LIST) $(TMPDIR)/policy.cil \
69*2d543d20SAndroid Build Coastguard Worker		-o $(HTMLDIR)/$(HTML_OUT)
70*2d543d20SAndroid Build Coastguard Worker
71*2d543d20SAndroid Build Coastguard Workerpdf: $(PANDOC_FILE_LIST) $(TMPDIR)/policy.cil secil.xml
72*2d543d20SAndroid Build Coastguard Worker	mkdir -p $(PDFDIR)
73*2d543d20SAndroid Build Coastguard Worker	$(PANDOC) \
74*2d543d20SAndroid Build Coastguard Worker		--highlight-style=$(PANDOC_HIGHLIGHT_STYLE) \
75*2d543d20SAndroid Build Coastguard Worker		--syntax-definition=secil.xml \
76*2d543d20SAndroid Build Coastguard Worker		--standalone \
77*2d543d20SAndroid Build Coastguard Worker		--toc \
78*2d543d20SAndroid Build Coastguard Worker		$(PANDOC_FILE_LIST) $(TMPDIR)/policy.cil \
79*2d543d20SAndroid Build Coastguard Worker		-o $(PDFDIR)/$(PDF_OUT)
80*2d543d20SAndroid Build Coastguard Worker
81*2d543d20SAndroid Build Coastguard Workerclean:
82*2d543d20SAndroid Build Coastguard Worker	rm -rf $(HTMLDIR)
83*2d543d20SAndroid Build Coastguard Worker	rm -rf $(PDFDIR)
84*2d543d20SAndroid Build Coastguard Worker	rm -rf $(TMPDIR)
85