Blame rpm/macros.fonts

Packit 46375d
# RPM macros for font packages.
Packit 46375d
#
Packit 46375d
# © 2008-2009 Nicolas Mailhot <nim at fedoraproject dot org>
Packit 46375d
Packit 46375d
## Default directories
Packit 46375d
Packit 46375d
# Font installation directory root
Packit 46375d
%_fontbasedir %{_datadir}/fonts
Packit 46375d
Packit 46375d
# Actual font installation directory
Packit 46375d
%_fontdir %{_fontbasedir}/%{?fontname:%{fontname}}%{?!fontname:%{name}}
Packit 46375d
Packit 46375d
# Master fontconfig configuration directory
Packit 46375d
# Only needed to avoid a circular directory dependency with the fontconfig
Packit 46375d
# package — you should *not* use this
Packit 46375d
%_fontconfig_masterdir   %{_sysconfdir}/fonts
Packit 46375d
Packit 46375d
# Fontconfig directory for active configuration snippets
Packit 46375d
%_fontconfig_confdir     %{_sysconfdir}/fonts/conf.d
Packit 46375d
Packit 46375d
# Fontconfig configuration template directory
Packit 46375d
# Templates are activated by symlinking in _fontconfig_confdir
Packit 46375d
%_fontconfig_templatedir %{_datadir}/fontconfig/conf.avail
Packit 46375d
Packit 46375d
## Magic
Packit 46375d
Packit 46375d
# Utility macro that computes a canonical font (sub)package name
Packit 46375d
#
Packit 46375d
# Expects an (optional) subpackage name as argument
Packit 46375d
Packit 46375d
%_font_pkg_name() %{lua:
Packit 46375d
local function rpmeval(name)
Packit 46375d
  local sname = rpm.expand(name)
Packit 46375d
  if sname == name
Packit 46375d
  then return ""
Packit 46375d
  else
Packit 46375d
    sname = string.lower("-" .. sname .. "-")
Packit 46375d
    sname = string.gsub(sname, "[_%-]+", "-")
Packit 46375d
    sname = string.gsub(sname, "%-font(s?)%-", "-")
Packit 46375d
    sname = string.gsub(sname, "^%-", "")
Packit 46375d
    sname = string.gsub(sname, "%-$", "")
Packit 46375d
    return sname
Packit 46375d
  end
Packit 46375d
end
Packit 46375d
local function meld(name1,name2)
Packit 46375d
  local name3 = "-" .. name2 .. "-"
Packit 46375d
  for token in string.gmatch(name1 .. "-" , "..-%-") do
Packit 46375d
    token = string.gsub(token, "%-", "%%-")
Packit 46375d
    name3 = string.gsub(name3, "%-" .. token, "-")
Packit 46375d
  end
Packit 46375d
  return string.gsub( name1 .. name3 , "%-+$", "")
Packit 46375d
end
Packit 46375d
local pkgname  = rpmeval("%{name}")
Packit 46375d
local fontname = rpmeval("%{fontname}")
Packit 46375d
local subname  = rpmeval("%1")
Packit 46375d
print(meld(meld(pkgname,fontname),subname) .. "-fonts")
Packit 46375d
} %{nil}
Packit 46375d
Packit 46375d
Packit 46375d
# Macro to generate file sections and scriptlets for font (sub)packages
Packit 46375d
#
Packit 46375d
# Expects:
Packit 46375d
# – an (optional) subpackage name as argument: -n <name>
Packit 46375d
#      without -n the macro will work on the core package
Packit 46375d
# – an (optional) fontconfig file pattern as argument: -f <pattern>
Packit 46375d
# — a variable number of file patterns corresponding to the font files
Packit 46375d
#   installed in _fontdir and associated to this (sub)package
Packit 46375d
#
Packit 46375d
# Files corresponding to the file pattern must be installed in
Packit 46375d
# _fontconfig_templatedir and symlinked to _fontconfig_confdir
Packit 46375d
#
Packit 46375d
# If you want to install a configuration template disabled by default, make
Packit 46375d
# the corresponding symlink point to /dev/null
Packit 46375d
Packit 46375d
%_font_pkg(n:f:) \
Packit 46375d
%define spn %_font_pkg_name %{-n:%{-n*}} \
Packit 46375d
%post -n %{spn} \
Packit 46375d
if [ -x %{_bindir}/fc-cache ]; then \
Packit 46375d
    %{_bindir}/fc-cache %{_fontdir} || : \
Packit 46375d
fi \
Packit 46375d
\
Packit 46375d
\
Packit 46375d
%postun -n %{spn}  \
Packit 46375d
if [ $1 -eq 0 -a -x %{_bindir}/fc-cache ] ; then \
Packit 46375d
    %{_bindir}/fc-cache %{_fontdir} || : \
Packit 46375d
fi\
Packit 46375d
\
Packit 46375d
\
Packit 46375d
%files -n %{spn} \
Packit 46375d
%defattr(0644,root,root,0755) \
Packit 46375d
\
Packit 46375d
%dir %{_fontdir} \
Packit 46375d
%{lua: \
Packit 46375d
for arg=1,rpm.expand("%#") do \
Packit 46375d
  print(rpm.expand("%{_fontdir}/%" .. arg) .. "\\n") \
Packit 46375d
end} \
Packit 46375d
%{-f:%{_fontconfig_templatedir}/%{-f*}} \
Packit 46375d
%{-f:%config(noreplace) %{_fontconfig_confdir}/%{-f*} \
Packit 46375d
} %{nil}
Packit 46375d