DOC = codina-a-tour-of-usb-device-controller.tex

PICTURES = \
	common/logo-penguins.pdf \
	common/logo-square.pdf \
	common/bootlin-logo.pdf \
	graphics/bus-topology.pdf \
	graphics/xfer-bulk.pdf \
	graphics/xfer-control.pdf \
	graphics/xfer-iso.pdf \
	graphics/dev-communication.pdf \
	graphics/usb-gadget.pdf \
	graphics/startup-reset.pdf \
	graphics/process-in.pdf \
	graphics/process-out.pdf \
	graphics/process-ep0.pdf \
	graphics/process-ep0-start.pdf \
	graphics/process-ep0-udc.pdf \
	graphics/process-ep0-core.pdf

INKSCAPE_IS_NEW = $(shell inkscape --version | grep -q "^Inkscape 1" && echo YES)

ifeq ($(INKSCAPE_IS_NEW),YES)
INKSCAPE_PDF_OPT = -o
else
INKSCAPE_PDF_OPT = -A
endif

XELATEX_OPT = -shell-escape

# '-8bit' or '--enable-8bit-chars' to avoid tab replaced by ^^I.
# Some web forum tells about '--enable-8bit-chars' instead of '-8bit' because
# '-8bit' seems not supported on all xelatex versions but '--enable-8bit-chars'
# is not supported by my xelatex ...
XELATEX_OPT_8BIT = $(shell xelatex --help | grep -q '^-8bit ' && echo y)
ifeq ($(XELATEX_OPT_8BIT),y)
XELATEX_OPT += -8bit
else
$(error Please check your xelatex supported option and update me ...)
endif

all: $(PICTURES)
	$(PDFLATEX_ENV) xelatex $(XELATEX_OPT) $(DOC)

%.pdf: %.svg
	inkscape -D $(INKSCAPE_PDF_OPT) $@ $<

%.pdf: %.eps
	epstopdf --outfile=$@ $^

%.eps: %.dia
	dia -e $@ -t eps $^

clean:
	$(RM) -r common/*.pdf *.pdf *.pyg *.snm *.toc *.vrb *.aux *.nav *.out *.dia~ *.log _minted* $(PICTURES)
