The Content of this Post has been taken from http://wiki.centos.org/Newsletter/0904.
Before you start to package you should set up a packaging environment. Any setup you make for packaging should work as normal user. If you package on fedora/redhat derived systems you can make a simple setup by installing the rpm-build, redhat-rpm-config and rpmdevtools package. Some default configuration of rpm have %_topdir set to some shared directory only accessibly by root. You should override that locally by setting %_topdir to some other location in you ~/.rpmmacros file. This file might look something like this:
%_unpackaged_files_terminate_build 0 %_topdir /tmp/yourname %buildroot %{_tmppath}/%{name}-build %_tmppath /tmp/yourname %packager yourname <yourname@yourserver.org> %_gpg_name %packager %vendor yourcompany
When you write SPEC-files there is some things you should consider:
- KISS: Try to avoid complex conditionals unless you really need it. If you need to change something in the source consider to make patches and use the patch-macros instead of doing everything in the specfile.
- No absolute paths: filenames in the %files section should _ALWAYS_ start with a macro (e.g. %{_bindir}, %{_libdir} etc), exception %doc entries.
- Avoid globs: in the %files section try to avoid using globs, on updates new/missing files will be detected and you avoid to have files in the rpm wich should not be there.
-
Try to use macros wherever possible, especially %{name} and %{version} but also thinks like %{make} and %configure
-
one item per line: only put one item on a line at a time for things like Requires, BuildRequires etc. This way it is much easier to diff spec files.
- sort lists: if you have multiple entries as mentioned above sort this also helps in diff.
A nice little spec file is the htop program on rpmforge. This explains the techniques mentioned above quite simply.
Summary: Interactive process viewer Name: htop Version: 0.8.3 Release: 1 License: GPL Group: Applications/System URL: http://htop.sourceforge.net/ Source: http://dl.sf.net/htop/htop-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root BuildRequires: gcc >= 3.0, ncurses-devel %description htop is an interactive process viewer for Linux. %prep %setup %build %configure %{__make} %{?_smp_mflags} %install %{__rm} -rf %{buildroot} %{__make} install DESTDIR="%{buildroot}" %clean %{__rm} -rf %{buildroot} %files %defattr(-, root, root, 0755) %doc AUTHORS ChangeLog COPYING INSTALL NEWS README %doc %{_mandir}/man1/htop.1* %{_bindir}/htop %{_datadir}/applications/htop.desktop %{_datadir}/pixmaps/htop.png %changelog * Wed Jun 24 2009 Dag Wieers <dag@wieers.com> - 0.8.3-1 - Updated to release 0.8.3.
Here is a list of common directory macros:
%{_sysconfdir} /etc %{_prefix} /usr %{_exec_prefix} %{_prefix} %{_bindir} %{_exec_prefix}/bin %{_lib} lib (lib64 on 64bit systems) %{_libdir} %{_exec_prefix}/%{_lib} %{_libexecdir} %{_exec_prefix}/libexec %{_sbindir} %{_exec_prefix}/sbin %{_sharedstatedir} /var/lib %{_datadir} %{_prefix}/share %{_includedir} %{_prefix}/include %{_infodir} /usr/share/info %{_mandir} /usr/share/man %{_localstatedir} /var %{_initddir} %{_sysconfdir}/rc.d/init.d
To see the expanded definition of a macro you can use the command rpm --eval "%{macro}".
No comments:
Post a Comment