#
# Makefile for converting code examples to syntax highlight'ed
# documents that can be opened with OpenOffice and copy-pasted
# over into OpenOffice presentations.
#
# Dependency for tool highlight
#  http://www.andre-simon.de/doku/highlight/en/highlight.php
#
TARGETS := xdp_bench01_simple01.rtf
TARGETS += xdp_bench01_maps.rtf
TARGETS += bpf_maps01.rtf
TARGETS += bpf_maps02_user_percpu.rtf
TARGETS += bpf_maps03_blacklist_modify.rtf

TOOL_HIGHLIGHT ?= highlight

all: dependencies $(TARGETS)

.PHONY: dependencies clean verify_cmds $(TOOL_HIGHLIGHT)

clean:
	rm -f $(TARGETS)

dependencies: verify_cmds

verify_cmds: $(TOOL_HIGHLIGHT)
	@for TOOL in $^ ; do \
		if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
			echo "*** ERROR: Cannot find tool '$${TOOL}'" ;\
			exit 1; \
		else true; fi; \
	done

$(TARGETS): %.rtf: %.c $(dependencies)
	@echo Converting: $< to syntax-highlighted document: $@
	$(TOOL_HIGHLIGHT) --style solarized-dark \
	   --syntax=c --inline-css --include-style \
	   --line-numbers -out-format rtf \
	   -i $< -o $@
