Initial commit
[profile/ivi/fontpackages.git] / rpm / macros.fonts
1 # RPM macros for font packages.
2 #
3 # © 2008-2009 Nicolas Mailhot <nim at fedoraproject dot org>
4
5 ## Default directories
6
7 # Font installation directory root
8 %_fontbasedir %{_datadir}/fonts
9
10 # Actual font installation directory
11 %_fontdir %{_fontbasedir}/%{?fontname:%{fontname}}%{?!fontname:%{name}}
12
13 # Master fontconfig configuration directory
14 # Only needed to avoid a circular directory dependency with the fontconfig
15 # package — you should *not* use this
16 %_fontconfig_masterdir   %{_sysconfdir}/fonts
17
18 # Fontconfig directory for active configuration snippets
19 %_fontconfig_confdir     %{_sysconfdir}/fonts/conf.d
20
21 # Fontconfig configuration template directory
22 # Templates are activated by symlinking in _fontconfig_confdir
23 %_fontconfig_templatedir %{_datadir}/fontconfig/conf.avail
24
25 ## Magic
26
27 # Utility macro that computes a canonical font (sub)package name
28 #
29 # Expects an (optional) subpackage name as argument
30
31 %_font_pkg_name() %{lua:
32 local function rpmeval(name)
33   local sname = rpm.expand(name)
34   if sname == name
35   then return ""
36   else
37     sname = string.lower("-" .. sname .. "-")
38     sname = string.gsub(sname, "[_%-]+", "-")
39     sname = string.gsub(sname, "%-font(s?)%-", "-")
40     sname = string.gsub(sname, "^%-", "")
41     sname = string.gsub(sname, "%-$", "")
42     return sname
43   end
44 end
45 local function meld(name1,name2)
46   local name3 = "-" .. name2 .. "-"
47   for token in string.gmatch(name1 .. "-" , "..-%-") do
48     token = string.gsub(token, "%-", "%%-")
49     name3 = string.gsub(name3, "%-" .. token, "-")
50   end
51   return string.gsub( name1 .. name3 , "%-+$", "")
52 end
53 local pkgname  = rpmeval("%{name}")
54 local fontname = rpmeval("%{fontname}")
55 local subname  = rpmeval("%1")
56 print(meld(meld(pkgname,fontname),subname) .. "-fonts")
57 } %{nil}
58
59
60 # Macro to generate file sections and scriptlets for font (sub)packages
61 #
62 # Expects:
63 # – an (optional) subpackage name as argument: -n <name>
64 #      without -n the macro will work on the core package
65 # – an (optional) fontconfig file pattern as argument: -f <pattern>
66 # — a variable number of file patterns corresponding to the font files
67 #   installed in _fontdir and associated to this (sub)package
68 #
69 # Files corresponding to the file pattern must be installed in
70 # _fontconfig_templatedir and symlinked to _fontconfig_confdir
71 #
72 # If you want to install a configuration template disabled by default, make
73 # the corresponding symlink point to /dev/null
74
75 %_font_pkg(n:f:) \
76 %define spn %_font_pkg_name %{-n:%{-n*}} \
77 %post -n %{spn} \
78 if [ -x %{_bindir}/fc-cache ]; then \
79     %{_bindir}/fc-cache %{_fontdir} || : \
80 fi \
81 \
82 \
83 %postun -n %{spn}  \
84 if [ $1 -eq 0 -a -x %{_bindir}/fc-cache ] ; then \
85     %{_bindir}/fc-cache %{_fontdir} || : \
86 fi\
87 \
88 \
89 %files -n %{spn} \
90 %defattr(0644,root,root,0755) \
91 \
92 %dir %{_fontdir} \
93 %{lua: \
94 for arg=1,rpm.expand("%#") do \
95   print(rpm.expand("%{_fontdir}/%" .. arg) .. "\\n") \
96 end} \
97 %{-f:%{_fontconfig_templatedir}/%{-f*}} \
98 %{-f:%config(noreplace) %{_fontconfig_confdir}/%{-f*} \
99 } %{nil}
100