use Makefile to use make -j all

This commit is contained in:
Denis Knauf 2024-08-23 19:02:34 +02:00
parent 3252093a0e
commit 1b77b1af54
3 changed files with 90 additions and 38 deletions

35
Makefile Normal file
View file

@ -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 "$<" "$@"

9
fc.format Normal file
View file

@ -0,0 +1,9 @@
family=%{family}
fullname=%{fullname}
postscriptname=%{postscriptname}
variable=%{variable}
slant=%{slant}
style=%{style}
weight=%{weight}
width=%{width}

View file

@ -3,6 +3,7 @@
({src ? null , srcs ? null, name ? "", pname ? "", version ? ""}: ({src ? null , srcs ? null, name ? "", pname ? "", version ? ""}:
with pkgs; with pkgs;
let let
escapeShellArg = lib.strings.escapeShellArg;
name_ = name_ =
if "" != name if "" != name
then name then name
@ -25,52 +26,59 @@
;; ;;
esac esac
done done
>"Makefile" echo ${escapeShellArg (builtins.readFile ./Makefile)}
>"fc.format" echo ${escapeShellArg (builtins.readFile ./fc.format)}
''; '';
buildPhase = '' buildPhase = ''
set -e set -e
build_dir="$TMPDIR/build" build_dir="$TMPDIR/build"
mkdir "$build_dir" 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" cd "$build_dir"
for f in *.ttf
for s in *.otf *.ttf
do do
bn="''${s%.otf}" [ -f "''${f%.ttf}.otf" ] || mv "$f" "''${f%.ttf}.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 done
make -j all
for s in *.otf *.ttf *.woff '';
do # for s in *.otf *.ttf
fc="`dirname "$s"`/`basename "$s"`.fc" # do
echo "fc-scan $s" # bn="''${s%.otf}"
LANG=C LC_NUMERIC=C fc-scan --format 'family=%{family} # bn="''${bn%.ttf}"
fullname=%{fullname} # if ! [ -e "$bn.woff" ]
postscriptname=%{postscriptname} # then
variable=%{variable} # echo "sfnt2woff-zopfli $s => $bn.woff"
slant=%{slant} # sfnt2woff-zopfli "$s"
style=%{style} # fi
weight=%{weight} # if ! [ -e "$bn.woff2" ]
width=%{width} # then
# echo "woff2_compress $s => $bn.woff2"
' "$s" > "$fc" # woff2_compress "$s"
done # fi
for s in *.woff2 # done
do #
o="`dirname "$s"`/`basename "$s" .woff2`.woff.fc" # for s in *.otf *.ttf *.woff
fc="`dirname "$s"`/`basename "$s"`.fc" # do
cp "$o" "$fc" # fc="`dirname "$s"`/`basename "$s"`.fc"
done # 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 = '' installPhase = ''
cd "$TMPDIR" cd "$TMPDIR"
mkdir -p $out/share/{doc/${name_},fonts/{opentype,truetype,WOFF,WOFF2}{,/.fc}} mkdir -p $out/share/{doc/${name_},fonts/{opentype,truetype,WOFF,WOFF2}{,/.fc}}