6. Create RPMs of Your Fonts

Do not just throw .ttf files someplace on your system. It makes migrations more difficult, and makes a big mess in your computer. Package management software like RPM lets you easily install your fonts in an organized standard way, manage font upgrades, and make massive font distribution a piece of cake.

Here we'll provide templates and instructions for you to easily build RPM packages of your fonts. We'll accept contributions with instructions to build different types of packages.

6.1. Step 1: Prepare Your Environment to Build The Package

To build RPMs, you need a special structure of directories and some configurations on your environment. You should do everything as a regular user, in all steps. In fact, we recommend that you do not do this as root.

To create this directories, do this:


bash$ cd ~
bash$ mkdir -p src/rpm
bash$ cd src/rpm
bash$ cp -r /usr/src/rpm/* .
bash$ ls
BUILD/  RPMS/  SOURCES/  SPECS/  SRPMS/
bash$ 

Of course this is on a Red Hat system, but the important point is to have the following directories under src/rpm:

Then, you'll have to create the .rpmmacros file in you home directory, with this single line content:


%_topdir        YOUR_HOME_DIR_HERE/src/rpm
			

And you should substitute YOUR_HOME_DIR_HERE with the absolute name of your $HOME directory.

6.2. Step 2: Prepare the Fonts Files to Package

Now you must think about a name for your font collection. To make things easy in this documentation, we'll use the name myfonts from now on. Then you must create a directory named ~/src/myfonts/myfonts (yes, myfonts two times) and put all your .ttf files right under it. So you'll have something like:


bash$ cd ~/src
bash$ find myfonts/myfonts/
myfonts/myfonts/
myfonts/myfonts/font1.ttf
myfonts/myfonts/font2.ttf
myfonts/myfonts/font3.ttf
...

6.3. Step 3: Create a .spec File With This Template

To build an RPM package you'll have to create a .spec file that provides instructions to the package builder on how to organize the files, package description, author, copyright, etc. We provide a template here that you can use to start your work. The template looks like this:

Example 1. The .spec file template


Name: myfonts     (1)
Summary: Collection of My Funny Fonts   (2)
Version: 1.0
Release: 1
License: GPL    (3)
Group: User Interface/X
Source: %{name}.tar.gz
BuildRoot: %{_tmppath}/build-root-%{name}
BuildArch: noarch
Requires: freetype
Packager: Avi Alkalay <avi@unix.sh>    (4)
Prefix: /usr/share/fonts
Url: http://myfonts.com/     (5)

%description    (6)
These are the fonts used in our marketing campaign, designed by our marketing agency specially for us.
The package includes the following fonts: Bodoni, Bodoni Black, Company Logo, Outline Company Logo, etc.


%prep

%setup -q -n %{name}

%build

%install
mkdir -p $RPM_BUILD_ROOT/%{prefix}
cp -r %{name}/ $RPM_BUILD_ROOT/%{prefix}


%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,0755)
%{prefix}/%{name}


%post
{
	ttmkfdir -d %{prefix}/%{name} \
		-o %{prefix}/%{name}/fonts.scale
	umask 133
	/usr/X11R6/bin/mkfontdir %{prefix}/%{name}
	/usr/sbin/chkfontpath -q -a %{prefix}/%{name}
	[ -x /usr/bin/fc-cache ] && /usr/bin/fc-cache
} &> /dev/null || :


%preun
{
	if [ "$1" = "0" ]; then
		cd %{prefix}/%{name}
		rm -f fonts.dir fonts.scale fonts.cache*
	fi
} &> /dev/null || :

%postun
if [ "$1" = "0" ]; then
  /usr/sbin/chkfontpath -q -r %{prefix}/%{name}
fi
[ -x /usr/bin/fc-cache ] && /usr/bin/fc-cache



%changelog    (7)
* Thu Dec 14 2002 Avi Alkalay <avi@unix.sh> 1.0
- Tested
- Ready for deployment
* Thu Dec 10 2002 Avi Alkalay <avi@unix.sh> 0.9
- First version of the template

					

You must change the following items to meet your package characteristic's (leave everything else untouched):

(1)
Put the name of your package or font collection here.
(2)
Put a brief summary about your package here.
(3)
The usage license of your package here.
(4)
The name of the person responsible for this package here.
(5)
URL to get more info about this package or fonts here. Can be omitted.
(6)
A more detailed description about this fonts here.
(7)
The evolution history of this package here. Must follow this layout.

This file must be named as the name of the package. In our example, myfonts.spec. And you must put it under the main directory of the package. So in the end we'll have something like this:


bash$ cd ~/src
bash$ find myfonts
myfonts/
myfonts/myfonts.spec
myfonts/myfonts/
myfonts/myfonts/font1.ttf
myfonts/myfonts/font2.ttf
myfonts/myfonts/font3.ttf
...

6.4. Step 4: Build It

We are almost ready to go. Next steps:


bash$ cd ~/src
bash$ tar -czvf myfonts.tar.gz myfonts
bash$ rpmbuild -ta myfonts.tar.gz

Done (after seeing a lot of messages about the building process). So we basically created a .tar.gz containing all our font files and myfonts.spec, and then we used rpmbuild on it, that will look for myfonts.spec inside the archive and follow its instructions.

You'll find the generated RPM under ~/src/rpm/RPMS/noarch/ directory, and this is the file you'll deploy and install. Under ~/src/rpm/SRPMS/ you'll find the source RPM file, which you should backup if you need to regenerate the deployable RPM again in the future. When you'll need it, you should do:


bash$ rpmbuild --rebuild myfonts-1.0-1.src.rpm

And the RPM file will be generated again.