From 1b77b1af5421b1ebd51a93e3ad8a0167b0a825e7 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Fri, 23 Aug 2024 19:02:34 +0200 Subject: [PATCH] use Makefile to use make -j all --- Makefile | 35 +++++++++++++++++++++ fc.format | 9 ++++++ fetchfont.nix | 84 ++++++++++++++++++++++++++++----------------------- 3 files changed, 90 insertions(+), 38 deletions(-) create mode 100644 Makefile create mode 100644 fc.format diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..be40d7c --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +FONTARTS := $(sort \ + $(patsubst %.otf,%,\ + $(patsubst %.woff,%,\ + $(patsubst %.woff2,%,\ + $(wildcard *.woff2 *.woff *.otf)\ + )))) +OTFS := $(patsubst %,%.otf,$(FONTARTS)) +WOFFS := $(patsubst %,%.woff,$(FONTARTS)) +WOFF2S := $(patsubst %,%.woff2,$(FONTARTS)) +FONTS := $(OTFS) $(WOFFS) $(WOFF2S) +CACHES := $(patsubst %,%.fc,$(FONTS)) + +all: fonts caches +.PHONY: all + +fonts: $(FONTS) +.PHONY: all + +caches: $(CACHES) +.PHONY: all + +%.woff: %.otf + sfnt2woff-zopfli "$<" + +%.woff2: %.otf + woff2_compress "$<" + +%.otf.fc: %.otf fc.format + > "$@" LANG=C LC_NUMERIC=C fc-scan --format "$$(cat fc.format)" "$<" + +%.woff.fc: %.woff fc.format + > "$@" LANG=C LC_NUMERIC=C fc-scan --format "$$(cat fc.format)" "$<" + +%.woff2.fc: %.woff.fc + cp "$<" "$@" diff --git a/fc.format b/fc.format new file mode 100644 index 0000000..9e082cb --- /dev/null +++ b/fc.format @@ -0,0 +1,9 @@ +family=%{family} +fullname=%{fullname} +postscriptname=%{postscriptname} +variable=%{variable} +slant=%{slant} +style=%{style} +weight=%{weight} +width=%{width} + diff --git a/fetchfont.nix b/fetchfont.nix index 5401e0c..b1593c2 100644 --- a/fetchfont.nix +++ b/fetchfont.nix @@ -3,6 +3,7 @@ ({src ? null , srcs ? null, name ? "", pname ? "", version ? ""}: with pkgs; let + escapeShellArg = lib.strings.escapeShellArg; name_ = if "" != name then name @@ -25,52 +26,59 @@ ;; esac done + >"Makefile" echo ${escapeShellArg (builtins.readFile ./Makefile)} + >"fc.format" echo ${escapeShellArg (builtins.readFile ./fc.format)} ''; buildPhase = '' set -e build_dir="$TMPDIR/build" mkdir "$build_dir" - find "$source_dir" \( -name \*.otf -or -name \*.ttf -or -name \*.woff -or -name \*.woff2 \) -exec cp \{\} "$build_dir" \; + find "$source_dir" \( -name Makefile -or -name fc.format -or -name \*.otf -or -name \*.ttf -or -name \*.woff -or -name \*.woff2 \) -exec cp \{\} "$build_dir" \; cd "$build_dir" - - for s in *.otf *.ttf + for f in *.ttf do - bn="''${s%.otf}" - bn="''${bn%.ttf}" - if ! [ -e "$bn.woff" ] - then - echo "sfnt2woff-zopfli $s => $bn.woff" - sfnt2woff-zopfli "$s" - fi - if ! [ -e "$bn.woff2" ] - then - echo "woff2_compress $s => $bn.woff2" - woff2_compress "$s" - fi + [ -f "''${f%.ttf}.otf" ] || mv "$f" "''${f%.ttf}.otf" done - - for s in *.otf *.ttf *.woff - do - fc="`dirname "$s"`/`basename "$s"`.fc" - echo "fc-scan $s" - LANG=C LC_NUMERIC=C fc-scan --format 'family=%{family} -fullname=%{fullname} -postscriptname=%{postscriptname} -variable=%{variable} -slant=%{slant} -style=%{style} -weight=%{weight} -width=%{width} - -' "$s" > "$fc" - done - for s in *.woff2 - do - o="`dirname "$s"`/`basename "$s" .woff2`.woff.fc" - fc="`dirname "$s"`/`basename "$s"`.fc" - cp "$o" "$fc" - done - ''; + make -j all + ''; +# for s in *.otf *.ttf +# do +# bn="''${s%.otf}" +# bn="''${bn%.ttf}" +# if ! [ -e "$bn.woff" ] +# then +# echo "sfnt2woff-zopfli $s => $bn.woff" +# sfnt2woff-zopfli "$s" +# fi +# if ! [ -e "$bn.woff2" ] +# then +# echo "woff2_compress $s => $bn.woff2" +# woff2_compress "$s" +# fi +# done +# +# for s in *.otf *.ttf *.woff +# do +# fc="`dirname "$s"`/`basename "$s"`.fc" +# echo "fc-scan $s" +# LANG=C LC_NUMERIC=C fc-scan --format 'family=%{family} +#fullname=%{fullname} +#postscriptname=%{postscriptname} +#variable=%{variable} +#slant=%{slant} +#style=%{style} +#weight=%{weight} +#width=%{width} +# +#' "$s" > "$fc" +# done +# for s in *.woff2 +# do +# o="`dirname "$s"`/`basename "$s" .woff2`.woff.fc" +# fc="`dirname "$s"`/`basename "$s"`.fc" +# cp "$o" "$fc" +# done +# ''; installPhase = '' cd "$TMPDIR" mkdir -p $out/share/{doc/${name_},fonts/{opentype,truetype,WOFF,WOFF2}{,/.fc}}