Blob Blame History Raw
# RPM macros for font packages.
#
# © 2008-2009 Nicolas Mailhot <nim at fedoraproject dot org>

## Default directories

# Font installation directory root
%_fontbasedir %{_datadir}/fonts

# Actual font installation directory
%_fontdir %{_fontbasedir}/%{?fontname:%{fontname}}%{?!fontname:%{name}}

# Master fontconfig configuration directory
# Only needed to avoid a circular directory dependency with the fontconfig
# package — you should *not* use this
%_fontconfig_masterdir   %{_sysconfdir}/fonts

# Fontconfig directory for active configuration snippets
%_fontconfig_confdir     %{_sysconfdir}/fonts/conf.d

# Fontconfig configuration template directory
# Templates are activated by symlinking in _fontconfig_confdir
%_fontconfig_templatedir %{_datadir}/fontconfig/conf.avail

## Magic

# Utility macro that computes a canonical font (sub)package name
#
# Expects an (optional) subpackage name as argument

%_font_pkg_name() %{lua:
local function rpmeval(name)
  local sname = rpm.expand(name)
  if sname == name
  then return ""
  else
    sname = string.lower("-" .. sname .. "-")
    sname = string.gsub(sname, "[_%-]+", "-")
    sname = string.gsub(sname, "%-font(s?)%-", "-")
    sname = string.gsub(sname, "^%-", "")
    sname = string.gsub(sname, "%-$", "")
    return sname
  end
end
local function meld(name1,name2)
  local name3 = "-" .. name2 .. "-"
  for token in string.gmatch(name1 .. "-" , "..-%-") do
    token = string.gsub(token, "%-", "%%-")
    name3 = string.gsub(name3, "%-" .. token, "-")
  end
  return string.gsub( name1 .. name3 , "%-+$", "")
end
local pkgname  = rpmeval("%{name}")
local fontname = rpmeval("%{fontname}")
local subname  = rpmeval("%1")
print(meld(meld(pkgname,fontname),subname) .. "-fonts")
} %{nil}


# Macro to generate file sections and scriptlets for font (sub)packages
#
# Expects:
# – an (optional) subpackage name as argument: -n <name>
#      without -n the macro will work on the core package
# – an (optional) fontconfig file pattern as argument: -f <pattern>
# — a variable number of file patterns corresponding to the font files
#   installed in _fontdir and associated to this (sub)package
#
# Files corresponding to the file pattern must be installed in
# _fontconfig_templatedir and symlinked to _fontconfig_confdir
#
# If you want to install a configuration template disabled by default, make
# the corresponding symlink point to /dev/null

%_font_pkg(n:f:) \
%define spn %_font_pkg_name %{-n:%{-n*}} \
%files -n %{spn} \
%defattr(0644,root,root,0755) \
\
%dir %{_fontdir} \
%{lua: \
for arg=1,rpm.expand("%#") do \
  print(rpm.expand("%{_fontdir}/%" .. arg) .. "\\n") \
end} \
%{-f:%{_fontconfig_templatedir}/%{-f*}} \
%{-f:%config(noreplace) %{_fontconfig_confdir}/%{-f*} \
} %{nil}