1# 2# Makefile for converting svg files 3# to something else: png, pdf, eps 4# 5# There would be absolutely no reason, at all, to produce EPS neither PNG of this covers. Anyway you can do it it you want to. 6# 7# 22-oct-2020 - Philippe Chauvat / Bacula Systems 8# Better handling process for SVG files 9# Inkscape does not recognize .template files as inkscape when opening/closing/saving them 10# Source files are now: .svg then will be moved to .tpl and compiled as .pdf 11# Template files are therefore intermediate and can be deleted if needed. 12# 27-jul-2017 - Philippe Chauvat / Bacula Systems : Improvements with date and version management 13# Work is based on svg files named *.template which contain __BVERSION__ and __BDATE__ 14# These "variables" are going to be seded to the current version and the current date. 15# 10-Oct-2012 - Philippe Chauvat / Bacula Systems 16# 17INKSCAPE=inkscape 18VERSION=$(shell $(INKSCAPE) -V 2>/dev/null|cut -d ' ' -f2|cut -d'.' -f1) 19VERBOSE=FALSE 20ifeq ($(VERBOSE),TRUE) 21 HIDE= 22else 23 HIDE=@ 24endif 25 26# 27# Traitement de la compilation à partir de la version 1 d'Inkscape 28ifeq ($(VERSION),1) 29 INKSCAPE_FLAGS=-o 30 SVG_TO_PDF=--export-type=pdf -C --export-pdf-version=1.5 -T $(INKSCAPE_FLAGS) 31 SVG_TO_EPS=--export-type=eps -C -T $(INKSCAPE_FLAGS) 32 SVG_TO_PNG=--export-type=png -C -T --export-dpi=120 $(INKSCAPE_FLAGS) 33# 34# Version 0.x 35else 36 INKSCAPE_FLAGS=-z -T -C 37 SVG_TO_PDF=$(INKSCAPE_FLAGS) -A 38 SVG_TO_EPS=$(INKSCAPE_FLAGS) -E 39 SVG_TO_PNG=$(INKSCAPE_FLAGS) -e 40endif 41PDFDIR=../pdf 42EPSDIR=../eps 43 44TPLSVGS=$(shell grep -l '__' *.svg) 45SVGS=$(shell grep -L '__' *.svg) 46TPLS=$(TPLSVGS:.svg=.tpl) 47PDFS=$(addprefix $(PDFDIR)/,$(SVGS:.svg=.pdf)) $(addprefix $(PDFDIR)/,$(TPLS:.tpl=.pdf)) 48EPSS=$(addprefix $(EPSDIR)/,$(SVGS:.svg=.eps)) $(addprefix $(EPSDIR)/,$(TPLS:.tpl=.eps)) 49 50BDATE := $(shell date +%Y-%m-%d) 51 52all: tpl pdf 53 54.SUFFIXES: 55.PHONY: 56.DONTCARE: 57 58check: 59 $(HIDE)echo "Template SVG files: $(TPLSVGS)" 60 $(HIDE)echo "Regular SVG files: $(SVGS)" 61 $(HIDE)echo "TPL files to be generated: $(TPLS)" 62 $(HIDE)echo "PDFDIR: $(PDFDIR)" 63 $(HIDE)echo "PDFs $(PDFS)" 64 $(HIDE)echo "EPSDIR: $(EPSDIR)" 65 66help: 67 $(HIDE)echo "This Makefile handles .svg file containing parameters to .pdf format while replacing the parameters with their values." 68 $(HIDE)echo " Parameter should be __PARAMETER_NAME__ at least in one place" 69 $(HIDE)echo " This is the way the Makefile identifies the SVG file to convert. Other SVG files will be directly exported into PDF directly" 70 $(HIDE)echo "The process is in two steps:" 71 $(HIDE)echo " a) SVG to TPL file which will replace the parameters with their respective value" 72 $(HIDE)echo " b) TPL to PDF. As inkscape is complaining about .tpl not being an expected file extension" 73 $(HIDE)echo " both STDERR and STDOUT are sent to their .svg_error file" 74# 75# PDF images creation 76pdf: tpl $(TEMPLATES) $(PDFS) 77 78tpl: $(TPLS) 79 80$(TPLS): $(VERSION_TEX) 81 82%.tpl: %.svg 83 $(HIDE)echo "$< : Handling version number and date" 84 $(HIDE)sed "s/__BVERSION__/`awk '{print $$1}' $(VERSION_TEX)`/g" $< > $@ 85 $(HIDE)sed -i 's/__BEDITION__/$(BACULAVERSION)/g' $@ 86 $(HIDE)sed -i 's/__BDATE__/$(BDATE)/g' $@ 87 88 89$(PDFS): | $(PDFDIR) 90$(PDFDIR): 91 $(HIDE)echo "Creating PDF images directory..." 92 $(HIDE)mkdir $(PDFDIR) 93 $(HIDE)echo "Done" 94 95$(PDFDIR)/%.pdf: %.tpl 96 $(HIDE)echo "Converting $< to $@" 97 $(HIDE)$(INKSCAPE) $(SVG_TO_PDF) $@ $< 1>$<.svg_error 2>$<.svg_error 98 99$(PDFDIR)/%.pdf: %.svg 100 $(HIDE)echo "$< : Converting to PDF" 101 $(HIDE)$(INKSCAPE) $(SVG_TO_PDF) $@ $< 102# 103# EPS images creation 104eps: $(EPSS) 105$(EPSS): | $(EPSDIR) 106$(EPSDIR): 107 $(HIDE)echo "Creating EPS images directory..." 108 $(HIDE)mkdir $(EPSDIR) 109 $(HIDE)echo "Done" 110 111$(EPSDIR)/%.pdf: %.tpl 112 $(HIDE)echo "Converting $< to $@" 113 $(HIDE)$(INKSCAPE) $(SVG_TO_EPS) $@ $< 1>$<.svg_error 2>$<.svg_error 114 115$(EPSDIR)/%.eps: %.svg 116 $(HIDE)${INKSCAPE} ${INKSCAPE_FLAGS} ${SVG_TO_EPS} $(EPSDIR)/$@ $< 117 118# 119# PNG images creation 120png: $(PNGS) 121$(PNGS): | $(PNGDIR) 122$(PNGDIR): 123 $(HIDE)echo "Creating PNG images directory..." 124 $(HIDE)mkdir $(PNGDIR) 125 $(HIDE)echo "Done" 126 127$(PNGDIR)/%.pdf: %.tpl 128 $(HIDE)echo "Converting $< to $@" 129 $(HIDE)$(INKSCAPE) $(SVG_TO_PNG) $@ $< 1>$<.svg_error 2>$<.svg_error 130 131$(PNGDIR)/%.png: %.svg 132 $(HIDE)${INKSCAPE} ${INKSCAPE_FLAGS} ${SVG_TO_PNG} $(PNGDIR)/$@ $< 133 134clean: 135 $(HIDE)rm -f $(TPLS) 136 $(HIDE)(if [ -e $(PDFDIR) ]; then cd $(PDFDIR) ; rm -f $(PDFS); fi) 137 $(HIDE)(if [ -e $(EPSDIR) ]; then cd $(EPSDIR) ; rm -f $(EPSS); fi) 138 $(HIDE)(if [ -e $(PNGDIR) ]; then cd $(PNGDIR) ; rm -f $(PNGS); fi) 139 $(HIDE)rm -f *~ *.svg_error 140 141distclean: clean 142