[PATCH 5/6] Makefile: restructure for usability and modularity

Jan Pokorny jpokorny at redhat.com
Mon Feb 20 16:18:37 UTC 2012


Previously, it was rather a shell script than set of recipes
with resource dependencies tracking.

The old targets (should) work as they used to, plus there are new ones:
- make ttf:
  generate TTF files in the "export" dir (which can be overriden from
  command line), utilizing native feature of "make" to generate only
  files the sources of which have changed (useful, e.g., for continuous
  updates tracking)
- make ttf-dir:
  target which "make" and "make down" boil down to, single-shot
  batch generation of TTF file to dedicated directory, i.e., without
  the advantage of dependency-change tracking as with the previous

To handle more universal tasks, new FontForge script was added
as scripts/fontexport.pe (it even contains brief help) and is
integrated on the places as the other ones.

Also .gitignore is extended with "export" dir.

Signed-off-by: Jan Pokorný <jpokorny at redhat.com>
---
 source/.gitignore            |    1 +
 source/Makefile              |   99 ++++++++++++++++++++++++++----------------
 source/scripts/fontexport.pe |   22 +++++++++
 3 files changed, 85 insertions(+), 37 deletions(-)
 create mode 100644 source/scripts/fontexport.pe

diff --git a/source/.gitignore b/source/.gitignore
index 0615b11..2b685a5 100644
--- a/source/.gitignore
+++ b/source/.gitignore
@@ -3,5 +3,6 @@
 /*.zip
 # generated subdirectories
 /liberation-fonts-ttf-*/
+/export/
 # logs from check
 /check_*
diff --git a/source/Makefile b/source/Makefile
index ff28e79..995443b 100644
--- a/source/Makefile
+++ b/source/Makefile
@@ -1,38 +1,65 @@
-VER = 1.07.2
-#VER = 1.06.0.$(shell date +%Y%m%d)
-FONTFORGE = fontforge
-FONTLINT = fontlint
-
-TMPDIR := $(shell mktemp -d)
-SFDFILES := src/LiberationMono-Bold.sfd src/LiberationMono-BoldItalic.sfd src/LiberationMono-Italic.sfd src/LiberationMono-Regular.sfd src/LiberationSans-Bold.sfd src/LiberationSans-BoldItalic.sfd src/LiberationS
ans-Italic.sfd src/LiberationSans-Regular.sfd src/LiberationSerif-Bold.sfd src/LiberationSerif-BoldItalic.sfd src/LiberationSerif-Italic.sfd src/LiberationSerif-Regular.sfd src/LiberationSansNarrow-Regular.sfd src
/LiberationSansNarrow-Bold.sfd src/LiberationSansNarrow-Italic.sfd src/LiberationSansNarrow-BoldItalic.sfd
-SCRIPTS := scripts/sfd2ttf.pe scripts/ttf2sfd.pe
-MISCFILES := AUTHORS ChangeLog COPYING License.txt README TODO
+FONTFORGE    = fontforge
+FONTLINT     = fontlint
+
+SCRIPTS      = scripts/sfd2ttf.pe scripts/ttf2sfd.pe scripts/fontexport.pe
+MISCFILES    = AUTHORS ChangeLog COPYING License.txt README TODO
+SRCDIR       = src
+EXPORTDIR    = export
 CHECK_PREFIX = check
 
-all: build
+VER          = 1.07.2
+#VER         = 1.06.0.$(shell date +%Y%m%d)
+NAME         = Liberation
+VARIANTS     = \
+    Mono-Regular       Mono-Bold        Mono-Italic       Mono-BoldItalic       \
+    Sans-Regular       Sans-Bold        Sans-Italic       Sans-BoldItalic       \
+    Serif-Regular      Serif-Bold       Serif-Italic      Serif-BoldItalic      \
+    SansNarrow-Regular SansNarrow-Bold  SansNarrow-Italic SansNarrow-BoldItalic
 
-build:
-       $(foreach sfdfile, $(SFDFILES), $(FONTFORGE) -script ./scripts/sfd2ttf.pe $(sfdfile);)
-       mkdir -p liberation-fonts-ttf-$(VER)/
-       mv src/*.ttf liberation-fonts-ttf-$(VER)/
+DISTPREFIX     := liberation-fonts-$(VER)
+DISTPREFIX_TTF := liberation-fonts-ttf-$(VER)
+SFDFILES       := $(addprefix $(SRCDIR)/$(NAME),    $(VARIANTS:=.sfd))
+TTFFILES       := $(addprefix $(EXPORTDIR)/$(NAME), $(VARIANTS:=.ttf))
 
-dist: dist-sfd dist-ttf
+# keeping backward compatibility for "build"
+all build: ttf-dir
 
-dist-src: dist-sfd
+$(EXPORTDIR):
+       mkdir -p $@
 
-dist-sfd:
-       mkdir -p $(TMPDIR)/liberation-fonts-$(VER)/{src,scripts}
-       cp Makefile $(MISCFILES) $(TMPDIR)/liberation-fonts-$(VER)/
-       cp $(SFDFILES) $(TMPDIR)/liberation-fonts-$(VER)/src/
-       cp $(SCRIPTS) $(TMPDIR)/liberation-fonts-$(VER)/scripts/
-       tar Cczvhf $(TMPDIR)/ liberation-fonts-$(VER).tar.gz \
-         liberation-fonts-$(VER)/
+# TrueType/OpenType Font, general usage
+# - ttf cares about source file changes, using shared EXPORTDIR
+# - ttf-dir should be a bit more efficient, creating dedicated dir for TTF
+ttf: $(EXPORTDIR) $(TTFFILES)
+ttf-dir:: $(SFDFILES)
+       $(FONTFORGE) -script ./scripts/fontexport.pe -ttf $^
+       mkdir -p $(DISTPREFIX_TTF)
+       mv $(addsuffix .ttf,$(basename $^)) $(DISTPREFIX_TTF)
 
-dist-ttf: clean-ttf build
-       cp $(MISCFILES) liberation-fonts-ttf-$(VER)/
-       tar czvhf liberation-fonts-ttf-$(VER).tar.gz liberation-fonts-ttf-$(VER)/
-#      zip -j liberation-fonts-ttf-$(VER).zip liberation-fonts-ttf-$(VER)/*
-       rm -rf liberation-fonts-ttf-$(VER)
+# single file export (primarily used by other targets)
+$(EXPORTDIR)/%.ttf:: $(SRCDIR)/%.sfd
+       $(FONTFORGE) -script ./scripts/fontexport.pe -$(lastword $(subst ., ,$@)) $<
+       mv $(SRCDIR)/$(notdir $@) $(EXPORTDIR)
+
+dist: clean-dist dist-sfd dist-ttf
+dist-src: dist-sfd
+
+dist-sfd:: $(SFDFILES)
+       tempdir=$$(mktemp -d) \
+         && mkdir -p $${tempdir}/$(DISTPREFIX)/{src,scripts} \
+         && cp Makefile $(MISCFILES) $${tempdir}/$(DISTPREFIX) \
+         && cp $(SFDFILES) $${tempdir}/$(DISTPREFIX)/src \
+         && cp $(SCRIPTS) $${tempdir}/$(DISTPREFIX)/scripts \
+         && tar Cczvhf $${tempdir} $(DISTPREFIX).tar.gz $(DISTPREFIX) \
+         || echo 'Problem encountered ($@)'; rm -rf -- $${tempdir}
+dist-ttf: ttf
+       tempdir=$$(mktemp -d) \
+         && mkdir -p $${tempdir}/$(DISTPREFIX_TTF) \
+         && cp $(MISCFILES) $(TTFFILES) $${tempdir}/$(DISTPREFIX_TTF) \
+         && tar Cczvhf $${tempdir} $(DISTPREFIX_TTF).tar.gz $(DISTPREFIX_TTF) \
+         || echo 'Problem encountered ($@)'; rm -rf -- $${tempdir}
+# substitute tar line with this if needed:
+#        && zip -j $(DISTPREFIX_TTF).zip $(MISCFILES) $(TTFFILES) \
 
 check:
        log="$(CHECK_PREFIX)_$$(git describe --dirty --always 2>/dev/null||date +%Y%m%d)" \
@@ -40,13 +67,11 @@ check:
                 $(FONTLINT) $${sfd} 2>/dev/null | tee -a $${log}; echo; \
             done
 
-clean: clean-ttf clean-src
-       rm -f $(CHECK_PREFIX)_*
-
-clean-ttf:
-       rm -rf liberation-fonts-*
-
-clean-src:
-       rm -f *.tar.gz
+clean: clean-dist
+       rm -rf -- $(DISTPREFIX)* $(DISTPREFIX_TTF)*
+       rm -rf -- $(EXPORTDIR)
+       rm -f -- $(CHECK_PREFIX)_*
+clean-dist:
+       rm -f -- *.tar.gz *.zip
 
-.PHONY: all build dist dist-src dist-sfd dist-ttf check clean clean-ttf clean-src
+.PHONY: all build ttf-dir ttf dist dist-src dist-sfd dist-ttf check clean clean-dist
diff --git a/source/scripts/fontexport.pe b/source/scripts/fontexport.pe
new file mode 100644
index 0000000..031cf08
--- /dev/null
+++ b/source/scripts/fontexport.pe
@@ -0,0 +1,22 @@
+# FontForge script to export font file(s) in selectable format
+# TODO: 0x800 fmflags only for TTF?
+
+if ($argc <= 1)
+    Print("usage: script [-<format>] file1 ...")
+    Print("(default format is ttf)")
+    return(1)
+endif
+
+format = "ttf"
+if (Strstr($1, "-") == 0)
+    format = Strsub($1, 1)
+    shift
+endif
+while ($argc > 1)
+    Print("Generating " + format  + " from " + $1)
+    Open($1)
+    Generate($1:r + "." + format, "", 0x800)
+    Close()
+    Print("")
+    shift
+endloop
-- 


More information about the fonts mailing list