1.1. Setting up the directory structure
ls -l /usr/src/redhat/
The different directories will be used for:
BUILD : The place where rpmbuild will build the package
RPMS : The binary package created by rpmbuild will be stored here
SOURCES : The place where to keep the original software sources
SPECS : This is where the .spec will be stored
SRPMS : The source rpm from your build will be stored there
1.2. Installing the necessary packages
# yum install rpm-build
2. Creating the package
2.1. Getting the sources
$ cd ~/packages/SOURCES/
$ wget
Only .tar.gz, .tar, .tgz and .tar.Z can be used with RPM.
2.2. The .spec file
The .spec is the file holding the information on how-to build the package. This file will contain section for unpacking the sources, building them, installing, removing the files. It will also contains meta-information on the software such as the version, the dependencies ....
Let's go to the SPECS directory and create our .spec file:
$ cd ~/packages/SPECS
$ vi test.spec
Summary: Subtitle editor
Name: test
Version: 0.20.0alpha4
Release: 1.rb7
License: GPL
Group: Applications/Multimedia
URL:
Source: files/test-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Patch: gtk_update_icon_cache.patch
BuildRequires: gstreamer-plugins-base-devel, gtk2-devel, gtkmm24-devel, libglademm24-devel
BuildRequires: gstreamer-devel, pcre-devel, libxml++-devel, enchant-devel, iso-codes-devel
Packager: chantra
%description
Subtitle Editor is a GTK+2 tool to edit subtitles for GNU/*.
It can be used for new subtitles or as a tool to transform, edit,
correct and refine existing subtitle. This program also shows sound
waves, which makes it easier to synchronise subtitles to voices.
Subtitle Editor is free software released under the GNU General Public License (GPL).
%prep
%setup -q
%patch -p1 -b .buildroot
%build
%configure --disable-debug
%{__make}
%install
%{__rm} -rf %{buildroot}
%makeinstall
%find_lang %{name}
%clean
%{__rm} -rf %{buildroot}
%files -f %{name}.lang
%defattr(-, root, root, 0755)
%doc AUTHORS ChangeLog INSTALL NEWS TODO README COPYING
%{_bindir}/test
%{_datadir}/test/
%{_datadir}/icons/hicolor/*
%exclude %{_datadir}/icons/hicolor/icon-theme.cache
%{_datadir}/applications/test.desktop
%changelog
* Fri Aug 3 2007 - chantra AatT rpm-based DdOoTt org 0.20.alpha4-1.rb
- Initial release.
This is it, this .spec file contains all the information required to create an RPM from the sources. Let go through this file to get a better understanding of what's happening.
2.3. Inside .spec file
Let's get through this file. The best way to create your own will be to use this one as a template and adapt it to your need.
This file basically contains 7 sections: introduction, prep, build, install, clean, files and changelog. I will go through each section individually.
2.3.1. Introduction section
the first section, up to %prep is pretty explicit by itself. It mainly contains information as seen by rpm -qi test. Here is a short description of each parameters:
Summary: a short description of the package
Name: the name of the package
Version: the version of the package we are building. Here test-0.20.0alpha4
Release: the package release number. Here 1.rb7
License: the license under which the software is released, here GPL
Group: the group your package belongs to. See /usr/share/doc/rpm-{release}/GROUPS
URL: software homepage
Source: the location of the sources
BuildRoot: where the package is going to be built
Patch: if you need to apply patch, enter the patch file name and copy the file to the SOURCES directory
BuildRequires: packages requires in order to build this packages
Packager: the name of the packager
%description: a longer description of the package
2.3.2. prep section
The prep section prepares the package for the build process. This is the section taking care of untarring the package as well as patching if required.
%setup -q is a rpm macro which knows how to unarchive the source.
%patch will patch the source tree.
2.3.3. build section
This section will configure and make the package. Here we use the %configure to which we append the --disable-debug as we don't want to compile this feature.
Then we compile the package with the %{__make} macro.
The meaning of the macros can be found in /usr/lib/rpm/macros
2.3.4. install section
This section take care of cleaning up the BuildRoot and installing the application.
2.3.5. clean section
Cleans up files created by other sections.
2.3.6. files section
defines the files that have to go in the binary RPM. Permission are defined and special attributes can be used.
This section starts with %files, additionally, the list of files that have to be included can be in a separate file, here test.lang.
%defattr(-, root, root, 0755) define the file attributes.
Files can be marked as document files by prepending their name with %doc.
You can exclude a file from a package using the %exclude macro.
2.3.7. changelog section
Finally the last section: %changelog.
You should add a new changelog entry anytime you repackage the RPM. Changelogs entry are defined as:
* Date - email name
- Action taken
Well, now that we have defined how to build our package, let's build it!
2.4. building the package
Finally, we are ready do get our first package built!!!.
At this point, in ~/packages we can see the directories:
$ ls ~/packages/
BUILD RPMS SOURCES SPECS SRPMS
SPECS contains test spec file, SOURCES contains our source tarball and eventually, patches.
Let's go do our SPECS directory and start building our package.
$ cd ~/packages/SPECS
In order to build a package, we are going to use the rpmbuild command.
rpmbuild syntax is: rpmbuild -b . So, depending on which build stage you choose, you are going to build either th binary RPM, source RPM, none of them or both of them. Here is the list of the different switches that can be used:
-ba : build all, both a binary and source RPM
-bb : build only the binary RPM
-bc : only compile the program. Does not make the full RPM, stopping just after the %build section
-bp : prepare for building a binary RPM, and stop just after the %prep section
-bi : create a binary RPM and stop just after the %install section
-bl : check the listing of files for the RPM and generate errors if the buildroot is missing any of the files to be installed
-bs : build aonly the source RPM
$ rpmbuild -ba test.spec
Should unpack the archive, configure, compile and install the software into an rpm package. The source RPM will be in ~/packages/SRPMS while the binary RPM will be in ~/packges/RPMS// ... If rpmbuild did not end up on an error ;).
2.5. Signing your packages
Signing a RPM with rpmbuild is pretty easy. First, you need to have a GPG key. I suppose that you already have a GPG key. Now, go and edit ~/.rpmmacros and add:
%_signature gpg
%_gpg_path /path/to/.gnupg
%_gpg_name name lastname (comment)
%_gpgbin /usr/bin/gpg
You might want to use the output of gpg --list-keys to find out we value to enter for %_gpg_name .
Next time you want to sign your RPM, use the following command:
$ rpmbuild -ba --sign test.spec
============
create local yum repo ,use createrepo /path/yumpath/
install and config httpd
vim /etc/yum.repo.d/my.repo
url points to this httpd server .
done
阅读(1430) | 评论(0) | 转发(0) |