Skip to content

Instantly share code, notes, and snippets.

@Anonymous1157
Last active February 22, 2017 17:47
Show Gist options
  • Select an option

  • Save Anonymous1157/2ae0bd22813cb54c84d6a2f8c282e1c5 to your computer and use it in GitHub Desktop.

Select an option

Save Anonymous1157/2ae0bd22813cb54c84d6a2f8c282e1c5 to your computer and use it in GitHub Desktop.
Simple Makefile to export SVG to PNG with Inkscape, then run optipng to optimize
# This Makefile exports PNGs from SVGs and optimizes the PNGs. It can also
# compress them for distribution as an archive.
VPATH:=src
# Detect SVGs and generate the output file names
SVGFILES:=$(sort $(notdir $(wildcard src/*.svg)))
PNGFILES:=$(patsubst %.svg,%.png,${SVGFILES})
OPTFILES:=$(patsubst %.svg,.%_ranopt,${SVGFILES})
# Name for the compressed files
PROJECT:=backgrounds
.SUFFIXES:
.PHONY: all all-png all-opt all-dist dist-zip dist-bzip2 dist-xz clean
# First target definition is the default target
# (The name "all" means nothing special)
all: all-opt
all-png: ${PNGFILES}
all-opt: ${OPTFILES}
all-dist: dist-zip dist-bzip2 dist-xz
dist-zip: ${PROJECT}.zip
dist-bzip2: ${PROJECT}.tar.bz2
dist-xz: ${PROJECT}.tar.xz
%.png: %.svg
inkscape -z -C -d 135 -e .$@_inkscape $< >/dev/null
mv .$@_inkscape $@
# Use a dotfile to track if optimization is done
.%_ranopt: %.png
optipng -o7 -zm1-9 -clobber -quiet $< -out .$(<F)_optipng
mv .$(<F)_optipng $<
touch $@
%.zip: ${OPTFILES}
zip -9 -q $@ ${PNGFILES}
%.tar.bz2: ${OPTFILES}
tar jcf $@ ${PNGFILES}
%.tar.xz: ${OPTFILES}
tar Jcf $@ ${PNGFILES}
clean:
rm -f *.png
rm -f .*_optipng
rm -f ${PROJECT}.zip
rm -f ${PROJECT}.tar.bz2
rm -f ${PROJECT}.tar.xz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment