Packaging HOWTO
(revision 0.3)

Dmitry V. Levin <ldv@altlinux.ru>
ALT Linux Team

��������

��� ���������� ��������� � ���������� � rpm �������� ��������� ������:

���������� �������� ����������������:
���� ������ ������ �������� ������������ ��������, � ������� ������ ���� ��������� �����. ��� ����� ����, ����� spec-����� ������������ ���������� ���� ������.
������ ������������:
��� ��� spec-����� ��� ��� ����� ����, �� �� ������ ����� ������ � ���� ��������, �������, ����������, � ������� ������� ��������. ����������� �� ������ ���������� ����� ���� �� ����� � ����, ��� ��� ������������������ ������ �������� ����� ��� � ������� ��������. ��� ����� ���� �������. ���� �����-�� ��� ���������� � ������ spec-������ ����� ������ ����, �� ���� �������� ������(�).
������� spec-����� ����� ������������:
��, ��� ��� ����� ������ - ���� ����� ����. �� ����� �������, ���� � ������������, ������������ � ������������� ��������� ��������� spec-������ ����� ������������ �������.

����������� ���� ������ rpm.

����� �������.

������� ��� ����� ������������ ���������.

X11R6:
%_x11dir, %_x11bindir, %_x11libdir, %_x11includedir, %_x11mandir, %_x11datadir;
��������:
%_licensedir;
����:
%_menudir, %_iconsdir, %_miconsdir, %_liconsdir;
emacs:
%_emacslispdir;
������ ���������:
%_initdir, %_lockdir, %_logdir.

���������� ������� ����������� gcc.

%add_optflags <options>:
�������� ��������� ��������� � ����������� ����� %opflags;
%remove_optflags <options>:
������ ��������� ��������� �� ������������ ������ %opflags;
%optflags_core:
������� ���������;
%_optlevel:
������� �����������;
%optflags_optimization:
���������, ���������� �� �����������, ����� ������������-���������;
%optflags_warnings:
warning options;
%optflags_debug:
debugging options;
%optflags_shared:
���������, ����������� ��� �������� relocatable ������;
%optflags_nocpp:
���������, ����������� ��������� C++ exceptions � C++ RTTI;
%optflags_notraceback:
-fomit-frame-pointer;
%optflags_fastmath:
-ffast-math;
%optflags_strict:
-fstrict-aliasing;
%optflags_kernel:
���������, ������������ ��� ���������� ���� � ��� �������.
�� ���������, ����������� ����� %opflags ������� �� "%optflags_core %optflags_warnings %optflags_optimization".

�������-���������� ��� �������� make.

%make_build:
����� make � ����������, �������������� ����������� ������������ ������ � ������ �����;
%make_install:
����� make c �������������� ���������� INSTALL, ��� � ������ ���������� ���������� Makefile�� ������ ��������� ��������� ���� ��������� ����������� ������, ��� �������� ����� ��� ������������;
%makeinstall:
``%make_install <������������� ������ ����������, ������������ ������� Makefile���> install''.

����������� ������������ � ������� info.

%install_info:
����������� �����/����������� info-�������;
%uninstall_info:
������ ����������� ��������� info-�������.

����������� ����.

%update_menus:
����������� �����/����������� ����;
%clean_menus:
������ ����������� ��������� ����.

��������������� ������� %configure.

%__libtoolize:
���� � ������� libtoolize;
%_configure_script:
���� � ������� configure;
%_configure_target:
������� ��������� ��� configure;
%_configure_gettext:
-without-included-gettext.

��������� �������.

%post_service:
����������� ������ ������� ��� ���������, ���������� ��� ����������;
%preun_service:
������ ����������� ������� � ��� ���������� ��� ��������.

�������, ������������ ��������� ������� packaging policy.

%buildroot:
�������� BuildRoot;
%_defattr:
�������� ������ � ��������� �� ��������� ��� ������ ������ %files � ��� ������� �����, ����������� � ���� �������;
%_compress_method:
�����, ������������ ��� ������ ������������ � ������ %install;
%_strip_method:
�����, ������������ ��� ��������� ELF-������ � ������ %install;
%_findreq_default_method:
�����, ������������ �� ��������� ��� ������ ��������� ������������;
%_findprov_default_method:
�����, ������������ �� ��������� ��� ������ ��������������� ������������;
%set_strip_method:
�������� �������� ������� %_strip_method;

����� ��������������� ��������.

%find_lang:
����� /usr/lib/rpm/find-lang
%strip_executable:
����� /usr/lib/rpm/brp-strip ��� ��������� ELF executables;
%strip_relocatable:
����� /usr/lib/rpm/brp-strip ��� ��������� ELF relocatables;
%strip_shared:
����� /usr/lib/rpm/brp-strip ��� ��������� ELF shared objects;
%strip_static:
����� /usr/lib/rpm/brp-strip ��� ��������� ELF ar archives;
%cleanup_build:
����� /usr/lib/rpm/brp-cleanup;
%compress_docs:
����� /usr/lib/rpm/brp-compress;
%strip_binaries:
����� /usr/lib/rpm/brp-strip;
%clean_buildroot:
���������� rm -rf %buildroot, ���� %buildroot �� ��������� �� ��������� /.

���������� ��������� ������.

%buildmulti:
�������������� ��������� %build ��� ������, ����� � ������ %build ���������� ���������� %buildroot. ������ ������, ����� ������� ����� �������� �� ���� �������, ����� ��� ��������.

������ ��������� ������������� � ������� �������.

glibc:
%__glibc_version, %__glibc_version_major, %__glibc_version_minor;
python:
%__python_version;
%get_version:
������ ���������� ������;
%get_release:
����� ���������� ������;
%get_serial:
Serial ���������� ������;
%add_serial:
Serial ���������� ������ � ����, ��������� ��� ��������� � spec-����.
��� �������, ��� �������, ������������ � �������, ������ ������� �������� � ���������� �������� ���� ��������, ���� ��� ������ ��������� ���������.

������ �������.

%intel:
������ ���������� intel, ����������� � i386;
%amd:
������ ���������� amd, ����������� � i386;
%ix86:
������ ���� ����������, ����������� � i386;
���������� ������� %packager:
%packagerName, %packagerAddress.

����e ��������� rpm.

-bE:
����� ����� ������ rpm, ��� ������� ���������� ������ ����������� ��������;
-nowait-lock:
�� ����������� �������, ���� ���� ������ rpm ������;
-fancypercent:
���������� �������������� ���������� � ��������� ����������� ������ ��� ���������/���������� �������.

����� ����������� rpm.

�������������� ����� ��������� � ��������������� ������������.

� ���������� � ������������ ������ ������������ ��/��� ����������� ���������, ����������� ��������� ������ ��������� ������������ ��� shellperl-��������, � ����� ��������� ������ ��������������� ������������ ��� perl-��������.

��������� ��������� �����, ����������� ������� ������������.

����� ����������� rpm �� ��������������� ������ ������������ ��� ������ ������� �����������, ��� � ������, ���������� ����� AutoReq, AutoProvAutoReqProv. � ����������� ��������� yes/no (true/false), ����� �������, ��������� ����� ��������� ��������, ���������� ������� ������� ������ ������������: ��������� ���� ����� �������� ��� ���� �����, ��� � ������������ �������. �� ���������, ��� ������� ��� ������ ����������� ������ AutoReq = AutoProv = yes, ��� �� �������� �������� ������������� �������� %_findreq_default_method%_findprov_default_method ��� ����������� ������� ������ ������������.

�������������� ������ maninfo-������������ � ���������� ��������� ������� ������.

��� ������������ ������, �������������� ��� man ��� info-������������, �� ��������� ������ ������ %install, ��������� �������� ���������� ������. �������������� ��������� ������ ������: ����� ����� ����� ����������� � ������ ���������� ������, ������� �� �������� ������� %_compress_method; �������� �� ��������� ��� ����� ������� - auto. �� ��������� ��������� ������ ������������ ������������ ������, �������, ��������, ������� ��������� � ����� � ����������� ���� ������ � �������� �� ������.

�������������� �������� ���������� ���������� �� ELF-������ � ���������� ��������� ��������� ������ ������, ���������� ���������.

�������� �������� ��������� ������ ���������� � ���������� ������ ������ ELF-������ ��� ������ �������� �� ���� �������� �� ��� ���������� ����������. ������� �� ��������� ������ ������ %install ��� ELF-����� ��������� ����� �������������� ���������� strip. ����� ����� ������ ������������ ��������� ������� %_strip_method, ������� ���� ����� �� ��������� ��������� ��������: ����� ����, ���� ����������� �������� strip �������, ��� ���� ���� ������������� ������� %strip_executable, %strip_relocatable, %strip_shared, %strip_static. ��������� ���� �������� �������� ������� � ``/usr/lib/rpm/brp-strip -help''.

�������������� �������������� python-�������.

��� ��������, python-������ ������ ����������� � �������� ����� ��� ���������� �������������� ��� ����������� ������ � ����. ������ ����� ������, ������ ����� �������, ������ ����� ������ �������� � ������ ��� �����, � ������� ������ ����������. � ����� � ��������� ��������������� ���������������� ������, ��������� � ���������� ������ ������ %install, ����������, ��� �� ����� ���� ������������ ����� ��������� ������. �� ���� ������� ������ �� ��������� ������ ������ %install ������������ �������������� ���� python-������� ����� �������, ����� �� ����� ���� ������������ ����� ��������� ������. � �������� ����-����������� ����� �������������� ���������, ��� ������� �������� � ������� %__python. ������ ��� /usr/bin/python, ������ � ��������� ������� ����� ������������� �������� ��� �������� �� ������ (��������, � ������ ������ ������ python ��� ���� �� �����-�� ������� �������������� �� �����).

BuildRoot.

�������, ����� ��� BuildRootspec-����� ���������, ����� ������� rpm ����� ������������ � �������� BuildRoot, ������ ������������. ������ ���� ��� �� ����� ������� ���������� � ����� (� ������) ���� ������. ������ ����� ������������ �������� ������� %buildroot, ������� ��������� ��� ``%{_tmppath}/%{name}-buildroot'' � ����� /usr/lib/rpm/macros � ����� ���� ������������� � ����� �����, ��� ����������� ���������� �������. � ������, ���� ������ %buildroot �� ��������� ���� ��� �������� ������������ ����� ������������ �������� ``/'', ������ ������ �� ����� ���������.

�������������� ������� BuildRoot.

����� ����������� ������ %install � �� ��������� ���������� ������ %clean rpm ������������� ������� BuildRoot � ������� ������� %clean_buildroot. ��� ������, ��� ������ �� ����� ������������ ��� ������� ``rm -rf $RPM_BUILD_ROOT''. ������ %clean ������ ����� (� ������) ���� �������, ���� � ��� �� ���������� ������, ����� ����� ``rm''. � ��� ������ �������, ����� � spec-����� ������������ ���������� BuildRoot �� � ������ %install, ��� ��� ������ ����, � � ������ %build, ��� � �������� �����������, ����� ��������� ����� ������� BuildRoot �� ������ ������ %install � ������ ������ %build, ���� �������� ��������� %build �� ������ %buildmulti.

��������� ������ %files.

����� � ������ ������ ������ %files ���� ���������� ��������� �������� ������ � ��������� ����������� ������� � ������� �������� ����������� ������������ ��������� %defattr. ������ ��� ���������� ������������� � ������ ������ ������ %files, � ����� � ������ ������� �����, ����������� � ������ %files � ������� ����� -f. ������ ������, � �������� ���� ��������� ������������ �������� ������� %_defattr. ����� �������, ������� ������������� ��������� %defattr � ������ ������ � ������ ������� ������� ������������.

������ ������� ����������������� �������������.

��, ��� �����-�� ���� ��������������, �� �������� ����� ��������, � ����� � ������ �������. ������, ����� ��� ������, ����� ������-������������� MAKEDEV, ����� (� �����) �������� ������������������� ������������� �� ��������� ����� ���������� ������� � ������������ ������, ������ ������� ����������������� ������������� �� ��������� ���������. ���� ������ ����� ����� ����� ��������� �������� ������� %_allow_root_build.

��������� packager'�.

���������� �����������.

�� ������� ������������ ���������� ����������� - ��� ���� ������������ spec-����, ������ ��� ����� ��� �������������. � ���������� ������������, � ���������, ���������:

�������� ������.

��� ������ �������� ����� spec-����� ��������� ��������� ��������. ��������� �� ��� �����:
perl -pi -e 's/%\{([A-Za-z_0-9]+)\}([^A-Za-z_0-9?*]|$)/%$1$2/g' spec-����

������� �����.

������������� ������� ������������ �����: Name, Version, Release, Serial, ����� Summary, License, Group, Url, Packager, BuildArch, ����� Source, Patch, ����� Provides, Requires, PreReqs, Conflicts, �, �������, Prefix, BuildPreReqs, BuildRequires. ����������, �� ��� �� ����������������� �����, ��� �������, ������������, ����� ��� ����������� � ������ ����� ������������ ����. � ����� � ���, ��� BuildRequires �������������� ��� ������������� ����������� ������������, ��� �������� ������ ������������ ������� ������������ BuildPreReq.

����� �����������.

���� � ������ ������ ������ ����� ����������� ���� ������ ����� �� ������ ������, ����� ������������ ������ %find_lang. ��������� ���������� ���� � ``/usr/lib/rpm/find-lang -h''

������.

������� �� ��������� ����� Group: ��� ������ ��������������� ���������������� � ��� ���� ������������ �������������� ���������, �������������� � ����� /usr/lib/rpm/GROUPS.

�������������� �����������.

��� ������ � ��������������� spec-������� ���������� ������� �������������� ������������: ���� ���� ����� � �����-���� ���� ������� �� ������� ���������, �� ��� ����������� ������ ���� ������� ���������, ������� �� ������ ���, �� ����� ���c��, ����� � serial (���� ����). ��������, ``Requires: %name = %version-%release''. �������� �������� �� ���������: ���� ���������, � ������� �� ������, ������� ���������.

����������� ����������.

������, ���������� ��� ����������� ����������, ��� � ������������ �� ���������, ������ ���� ��������� �� ��������� ����� �������, ����� � ��������, ���������� ����������� ����������, �� ������� ������������ �� ���������. ��� �������� ��������� ���������� ����������� ������������. �� ��������, ����� �������, ��������� ������ �� ����������� ���������, ������ ���������� � �������� ``lib`` ���� ��������� ��� ������ �����. ��� ���������� ���������� ������� ������� � �������������� ������������.

����������� ����������.

����������� ���������� ������ ���������� � ��������� ���������, ��� ������� �� ���������� �� �������������. ���� ��� devel-��������� ������������� ��������� -devel, �� ��� ������ devel-static-��������� ����� ������������� ��������� -devel-static. ��� ���������� ���������� ������� ������� � �������������� ������������: � ������ ������������ devel-static-��������� ������ �������������� ����������� �� -devel = %version-%release.

�������������� �������.

������ ������ ���������������. ��������, ��� ��������� ��� �������� ����������� ���������. � ����� ������� ������� ��������� ���������� ���������� � ������������, ����������� ��� ����������� ����������. � ���������, ����� ��������������:

����������