Re-implement the pkgsrc fonts-handling by integrating it into the

pkginstall framework:

  * Rewrite the mk/install/fonts script fragment as a scriptlet that's
    generated by the +INSTALL script during package installation.

  * Rename the FONTS_<TYPE>_DIRS variables to FONTS_DIRS.<type> to
    be more consistent with how "families" of variables are currently
    named in pkgsrc.

  * Rewrite mk/fonts.mk so that it's implemented in terms of the new
    functionality in the pkginstall framework.  This file will be
    obsoleted in the near future after packages have been transitioned
    to use the new functionality in the pkginstall framework.  Currently,
    packages will continue to work with no changes.

Integrating the fonts-handling into the pkginstall framework has the
benefit of generating a +FONTS scriptlet that may be run independently
of the +INSTALL scripts to (idempotently) update the fonts databases
and fix package installation errors.
This commit is contained in:
jlam 2005-12-29 03:44:38 +00:00
parent 382dff173a
commit f0aa85ac53
5 changed files with 174 additions and 94 deletions

View file

@ -1,61 +1,20 @@
# $NetBSD: fonts.mk,v 1.8 2005/12/28 17:54:20 joerg Exp $
# $NetBSD: fonts.mk,v 1.9 2005/12/29 03:44:38 jlam Exp $
#
# This Makefile fragment is intended to be included by packages that install
# fonts (most of them in the fonts category). It takes care of updating the
# fonts.dir files at install/deinstall time.
#
# The following variables need to be defined by packages using fonts.mk:
#
# FONTS_<TYPE>_DIRS - Whitespaced list of directories where the font database
# is updated. If empty, nothing is done for this TYPE.
#
# Supported TYPEs: TTF, TYPE1, X11.
# XXX This file's use is deprecated. This is here temporarily to help
# XXX packages transition to using the new fonts capability of the
# XXX pkginstall framework.
#
.if !defined(FONTS_MK)
FONTS_MK= # defined
# TrueType fonts
FONTS_TTF_DIRS?=
# Type1 fonts
FONTS_TYPE1_DIRS?=
# Generic X fonts (PCF, SNF, BDF)
FONTS_X11_DIRS?=
.if !empty(FONTS_TTF_DIRS) || !empty(FONTS_TYPE1_DIRS) || !empty(FONTS_X11_DIRS)
# Support the old FONTS_<TYPE>_DIRS variables for a while until we can
# nuke them.
#
FONTS_DIRS.ttf+= ${FONTS_TTF_DIRS}
FONTS_DIRS.type1+= ${FONTS_TYPE1_DIRS}
FONTS_DIRS.x11+= ${FONTS_X11_DIRS}
USE_PKGINSTALL= YES
HEADER_EXTRA_TMPL+= ${.CURDIR}/../../mk/install/fonts
.if !empty(FONTS_TTF_DIRS)
EVAL_PREFIX+= TTMKFDIR_PREFIX=ttmkfdir
TTMKFDIR_PREFIX_DEFAULT= ${LOCALBASE}
FILES_SUBST+= FONTS_TTF="YES"
FILES_SUBST+= FONTS_TTF_DIRS=${FONTS_TTF_DIRS:Q}
FILES_SUBST+= TTMKFDIR="${TTMKFDIR_PREFIX}/bin/ttmkfdir"
DEPENDS+= ttmkfdir2>=20021109:../../fonts/ttmkfdir2
# also need to run mkfontdir there
FONTS_X11_DIRS+= ${FONTS_TTF_DIRS}
.endif
.if !empty(FONTS_TYPE1_DIRS)
EVAL_PREFIX+= TYPE1INST_PREFIX=type1inst
TYPE1INST_PREFIX_DEFAULT= ${LOCALBASE}
FILES_SUBST+= FONTS_TYPE1="YES"
FILES_SUBST+= FONTS_TYPE1_DIRS=${FONTS_TYPE1_DIRS:Q}
FILES_SUBST+= TYPE1INST="${TYPE1INST_PREFIX}/bin/type1inst"
DEPENDS+= type1inst>=0.6.1:../../fonts/type1inst
# also need to run mkfontdir there
FONTS_X11_DIRS+= ${FONTS_TYPE1_DIRS}
.endif
.if !empty(FONTS_X11_DIRS)
FILES_SUBST+= FONTS_X11="YES"
FILES_SUBST+= FONTS_X11_DIRS=${FONTS_X11_DIRS:Q}
FILES_SUBST+= MKFONTDIR="${X11BASE}/bin/mkfontdir"
USE_TOOLS+= mkfontdir
.endif
.endif
.endif # FONTS_MK

View file

@ -1,4 +1,4 @@
# $NetBSD: bsd.pkginstall.mk,v 1.30 2005/12/05 22:07:07 rillig Exp $
# $NetBSD: bsd.pkginstall.mk,v 1.31 2005/12/29 03:44:38 jlam Exp $
#
# This Makefile fragment is included by bsd.pkg.mk to use the common
# INSTALL/DEINSTALL scripts. To use this Makefile fragment, simply:
@ -541,6 +541,87 @@ ${INSTALL_SHELL_FILE}: ../../mk/install/shell
${MV} -f ${.TARGET}.tmp ${.TARGET}
.endif
# FONTS_DIRS.<type> are lists of directories in which the font databases
# are updated. If this is non-empty, then the appropriate tools is
# used to update the fonts database for the font type. The supported
# types are:
#
# ttf TrueType fonts
# type1 Type1 fonts
# x11 Generic X fonts, e.g. PCF, SNF, BDF, etc.
#
FONTS_DIRS.ttf?= # empty
FONTS_DIRS.type1?= # empty
FONTS_DIRS.x11?= # empty
INSTALL_FONTS_FILE= ${WRKDIR}/.install-fonts
INSTALL_FONTS_MEMBERS= ${FONTS_DIRS.ttf} ${FONTS_DIRS.type1} ${FONTS_DIRS.x11}
INSTALL_UNPACK_TMPL+= ${INSTALL_FONTS_FILE}
# Directories with TTF and Type1 fonts also need to run mkfontdir, so
# list them as "x11" font directories as well.
#
.if !empty(FONTS_DIRS.ttf:M*)
USE_TOOLS+= ttmkfdir:run
FILES_SUBST+= TTMKFDIR=${TOOLS_PATH.ttmkfdir:Q}
FONTS_DIRS.x11+= ${FONTS_DIRS.ttf}
.endif
.if !empty(FONTS_DIRS.type1:M*)
USE_TOOLS+= type1inst:run
FILES_SUBST+= TYPE1INST=${TOOLS_PATH.type1inst:Q}
FONTS_DIRS.x11+= ${FONTS_DIRS.type1}
.endif
.if !empty(FONTS_DIRS.x11:M*)
USE_TOOLS+= mkfontdir:run
FILES_SUBST+= MKFONTDIR=${TOOLS_PATH.mkfontdir:Q}
.endif
.if empty(INSTALL_FONTS_MEMBERS:M*)
${INSTALL_FONTS_FILE}:
${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_FLAGS} ${.TARGET}
.else
${INSTALL_FONTS_FILE}: ../../mk/install/fonts
${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${.TARGET} ${.TARGET}.tmp
${_PKG_SILENT}${_PKG_DEBUG} \
${_FUNC_STRIP_PREFIX}; \
exec 1>>${.TARGET}.tmp; \
${ECHO} "# start of install-fonts"; \
${ECHO} "#"; \
${ECHO} "# Generate a +FONTS script that updates fonts databases."; \
${ECHO} "#"; \
${ECHO} "case \$${STAGE} in"; \
${ECHO} "PRE-INSTALL|UNPACK)"; \
${ECHO} " \$${CAT} > ./+FONTS << 'EOF_FONTS'"; \
${SED} ${FILES_SUBST_SED} ../../mk/install/fonts; \
${ECHO} ""; \
set -- dummy ${FONTS_DIRS.ttf}; shift; \
while ${TEST} $$# -gt 0; do \
dir="$$1"; shift; \
dir=`strip_prefix "$$dir"`; \
${ECHO} "# FONTS: $$dir ttf"; \
done; \
set -- dummy ${FONTS_DIRS.type1}; shift; \
while ${TEST} $$# -gt 0; do \
dir="$$1"; shift; \
dir=`strip_prefix "$$dir"`; \
${ECHO} "# FONTS: $$dir type1"; \
done; \
set -- dummy ${FONTS_DIRS.x11}; shift; \
while ${TEST} $$# -gt 0; do \
dir="$$1"; shift; \
dir=`strip_prefix "$$dir"`; \
${ECHO} "# FONTS: $$dir x11"; \
done; \
${ECHO} "EOF_FONTS"; \
${ECHO} " \$${CHMOD} +x ./+FONTS"; \
${ECHO} " ;;"; \
${ECHO} "esac"; \
${ECHO} ""; \
${ECHO} "# end of install-fonts"; \
exec 1>/dev/null; \
${MV} -f ${.TARGET}.tmp ${.TARGET}
.endif
# PKG_CREATE_USERGROUP indicates whether the INSTALL script should
# automatically add any needed users/groups to the system using
# useradd/groupadd. It is either YES or NO and defaults to YES.

View file

@ -1,7 +1,7 @@
# -*- sh -*-
# start of deinstall
#
# $NetBSD: deinstall,v 1.36 2005/08/19 22:24:10 jlam Exp $
# $NetBSD: deinstall,v 1.37 2005/12/29 03:44:38 jlam Exp $
case ${STAGE} in
VIEW-DEINSTALL)
@ -48,6 +48,11 @@ POST-DEINSTALL)
${RMDIR} -p `${DIRNAME} ${PKG_SYSCONFDIR}` 2>/dev/null || ${TRUE}
fi
#
# Update any fonts databases.
#
${TEST} ! -x ./+FONTS ||
./+FONTS ${PKG_METADATA_DIR}
#
# Remove empty directories and unused users/groups.
#
${TEST} ! -x ./+DIRS ||

View file

@ -1,47 +1,77 @@
# $NetBSD: fonts,v 1.6 2004/12/28 14:38:03 wiz Exp $
#!@SH@
#
# Handle font databases; used by fonts.mk.
# $NetBSD: fonts,v 1.7 2005/12/29 03:44:38 jlam Exp $
#
# +FONTS - font database management script
#
# Usage: ./+FONTS [metadatadir]
#
# This scripts rebuilds font databases needed by the package associated
# with <metadatadir>.
#
# Lines starting with "# FONTS: " are data read by this script that name
# the directories in which the font database will be rebuilt.
#
# # FONTS: /usr/pkg/lib/X11/fonts/TTF ttf
# # FONTS: /usr/pkg/lib/X11/fonts/Type1 type1
# # FONTS: /usr/pkg/lib/X11/fonts/misc x11
#
# For each FONTS entry, if the path is relative, that it is taken to be
# relative to ${PKG_PREFIX}.
#
FONTS_TTF="@FONTS_TTF@"
FONTS_TTF_DIRS="@FONTS_TTF_DIRS@"
FONTS_TYPE1="@FONTS_TYPE1@"
FONTS_TYPE1_DIRS="@FONTS_TYPE1_DIRS@"
FONTS_X11="@FONTS_X11@"
FONTS_X11_DIRS="@FONTS_X11_DIRS@"
ECHO="@ECHO@"
GREP="@GREP@"
LS="@LS@"
MKFONTDIR="@MKFONTDIR@"
PWD_CMD="@PWD_CMD@"
RM="@RM@"
SED="@SED@"
SORT="@SORT@"
TEST="@TEST@"
TRUE="@TRUE@"
TTMKFDIR="@TTMKFDIR@"
TYPE1INST="@TYPE1INST@"
MKFONTDIR="@MKFONTDIR@"
case ${STAGE} in
POST-INSTALL|POST-DEINSTALL)
${ECHO} "===> Updating font databases"
if [ "${FONTS_TTF}" = "YES" ]; then
for d in ${FONTS_TTF_DIRS}; do
if [ -z "`cd $d ; ${LS} | ${GREP} -v .pkgsrc | ${GREP} -v ^fonts | ${GREP} -v ^Fontmap`" ]; then
${RM} -f $d/fonts* $d/Fontmap*
else
( cd $d && ${TTMKFDIR} >/dev/null 2>&1 )
fi
done
fi
if [ "${FONTS_TYPE1}" = "YES" ]; then
for d in ${FONTS_TYPE1_DIRS}; do
if [ -z "`cd $d ; ${LS} | ${GREP} -v .pkgsrc | ${GREP} -v ^fonts | ${GREP} -v ^Fontmap`" ]; then
${RM} -f $d/fonts* $d/Fontmap*
else
( cd $d && ${TYPE1INST} >/dev/null 2>&1 )
fi
done
fi
if [ "${FONTS_X11}" = "YES" ]; then
for d in ${FONTS_X11_DIRS}; do
if [ -z "`cd $d ; ${LS} | ${GREP} -v .pkgsrc | ${GREP} -v ^fonts | ${GREP} -v ^Fontmap`" ]; then
${RM} -f $d/fonts* $d/Fontmap*
else
${MKFONTDIR} $d >/dev/null 2>&1
fi
done
fi
SELF=$0
PKG_METADATA_DIR="${1-`${PWD_CMD}`}"
: ${PKGNAME=${PKG_METADATA_DIR##*/}}
: ${PKG_PREFIX=@PREFIX@}
${SED} -n "/^\# FONTS: /{s/^\# FONTS: //;p;}" ${SELF} | ${SORT} -u |
{ while read dir font_type; do
case $dir in
"") continue ;;
[!/]*) dir="${PKG_PREFIX}/$dir" ;;
esac
${TEST} -d "$dir" || continue
case "$printed_header" in
yes) ;;
*) printed_header=yes
${ECHO} "==========================================================================="
${ECHO} "Updating font databases in the following directories:"
${ECHO} ""
;;
esac
( ${ECHO} " $dir ($font_type)"
cd $dir
case $font_type in
[tT][tT][fF]) update_cmd="${TTMKFDIR}" ;;
[tT][yY][pP][eE]1) update_cmd="${TYPE1INST}" ;;
[xX]11) update_cmd="${MKFONTDIR}" ;;
esac
${TEST} -f "$update_cmd" || update_cmd="${TRUE}"
$update_cmd >/dev/null
#
# Remove fonts databases if there are no fonts in the directory.
# We filter out the encodings.dir, fonts.{alias,dirs,scale}, and
# Fontmap database files from the directory listing.
#
${LS} | ${GREP} -v "^encodings.dir" | ${GREP} -v "^fonts\." | ${GREP} -v "^Fontmap" >/dev/null || ${RM} -f fonts.* Fontmap*
)
done
case "$printed_header" in
yes) ${ECHO} ""
${ECHO} "==========================================================================="
;;
esac
esac; }

View file

@ -1,7 +1,7 @@
# -*- sh -*-
# start of install
#
# $NetBSD: install,v 1.41 2005/08/19 22:24:10 jlam Exp $
# $NetBSD: install,v 1.42 2005/12/29 03:44:38 jlam Exp $
case ${STAGE} in
PRE-INSTALL)
@ -50,6 +50,11 @@ POST-INSTALL)
#
${TEST} ! -x ./+PERMS ||
./+PERMS ${PKG_METADATA_DIR}
#
# Update any fonts databases.
#
${TEST} ! -x ./+FONTS ||
./+FONTS ${PKG_METADATA_DIR}
# Check for any missing bits after we're finished installing.
#