sed: 1: "s,@FC_DEFAULT_FONTS\@,\ ...": bad flag in substitute command: '/'
On macOS 10.13.6 I used fontconfig 2.13.94 and ran:
LIBTOOLIZE=glibtoolize ./autogen.sh --prefix=/opt/fontconfig --with-add-fonts=/Library/Fonts,/System/Library/Fonts
make -j$(sysctl -n hw.activecpu)
sudo make install
The result was:
sed \
-e 's,@FC_CACHEDIR\@,/opt/fontconfig/var/cache/fontconfig,g' \
-e 's,@FC_DEFAULT_FONTS\@,\t<dir>/System/Library/Fonts,/Library/Fonts,~/Library/Fonts,/System/Library/Assets/com_apple_MobileAsset_Font3,/System/Library/Assets/com_apple_MobileAsset_Font4</dir>\n,g' \
-e 's,@FC_FONTPATH\@,<dir>/Library/Fonts</dir> <dir>/System/Library/Fonts</dir>,g' \
-e 's,@CONFIGDIR\@,conf.d,g' \
-e 's,@PACKAGE\@,fontconfig,g' \
-e 's,@VERSION\@,2.13.94,g' \
./fonts.conf.in > fonts.conf.tmp && \
mv fonts.conf.tmp fonts.conf
sed: 1: "s,@FC_DEFAULT_FONTS\@,\ ...": bad flag in substitute command: '/'
make[2]: *** [fonts.conf] Error 1
make[1]: *** [install-am] Error 2
make: *** [install-recursive] Error 1
I noticed that the commas I specified in --with-add-fonts
have been translated into </dir> <dir>
within FC_FONTPATH
but a similar substitution has not been performed in FC_DEFAULT_FONTS
so the commas within FC_DEFAULT_FONTS
are interfering with the commas used as separators for sed.
This is caused by a simple mistake in configure.ac:
diff --git a/configure.ac b/configure.ac
index 7c1a697..93ccf1b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -499,7 +499,7 @@ FC_DEFAULT_FONTS=""
if test x${default_fonts+set} = xset; then
fc_IFS=$IFS
IFS=","
- for p in "$default_fonts"; do
+ for p in $default_fonts; do
FC_DEFAULT_FONTS="$FC_DEFAULT_FONTS\t<dir>$p</dir>\n"
done
IFS=$fc_IFS
Once this is fixed, we see that the resulting presentation of this data in fonts.conf is wrong:
<!-- Font directory list -->
t<dir>/System/Library/Fonts</dir>nt<dir>/Library/Fonts</dir>nt<dir>~/Library/Fonts</dir>nt<dir>/System/Library/Assets/com_apple_MobileAsset_Font3</dir>nt<dir>/System/Library/Assets/com_apple_MobileAsset_Font4</dir>n
<dir>/Library/Fonts</dir> <dir>/System/Library/Fonts</dir>
<dir prefix="xdg">fonts</dir>
<!-- the following element will be removed in the future -->
<dir>~/.fonts</dir>
\t
and \n
have been converted to t
and n
. (Presumably the code was tested using GNU sed, which replaces \t
with a tab and \n
with a newline, but macOS ships with BSD sed which does not have that feature.) I am not certain of the best way to fix this. As far as I know, autoconf config values cannot contain real newlines, so perhaps it is acceptable to forgo the newlines and put everything on one line for FC_DEFAULT_FONTS
to match how it already is for FC_FONTPATH
.
I will submit a merge request to fix these issues shortly. Whether using my merge request or another method, please fix these problems before releasing fontconfig 2.14.0 so as to avoid breaking things for macOS users.