Jump to Navigation

234 - Build packages from sorce codes

The rpmbuild command is used to build RPM package. The syntax for rpmbuild is :

# rpmbuild -[b|t]stage [build-option] spec-file ....

Specify -b to build a package directly from a spec file, or -t to open a tarred gzipped file and use its spec file.

1. You need to have the rpmbuild package in Linux server.

# yum install rpmbuild

2. Create work space for that. (You can do it as root user but all files are in /usr/src/redhat )

# mkdir ~/rpm
# cp -r /usr/src/redhat/* ~/rpm

3. Edit parameter file of rpmbuild

# vi ~/.rpmmacros

Add the following parameters in .rpmmacros

==========================================
%_topdir    /home/[user name]/rpm
%_specdir    %{_topdir}/SPECS
%_sourcedir    %{_topdir}/SOURCES
%_builddir    %{_topdir}/BUILD
%_srcrpmdir    %{_topdir}/SRPMS
%_rpmdir    %{_topdir}/RPMS

==========================================

If you are root user, the directory tree is as the follwoing :

 /usr/src/redhat/SOURCES - Contains the original sources, patches, and icon files.
 /usr/src/redhat/SPECS - Contains the spec files used to control the build process.
 /usr/src/redhat/BUILD - The directory in which the sources are unpacked, and the software is built.
 /usr/src/redhat/RPMS - Contains the binary package files created by the build process.
 /usr/src/redhat/SRPMS - Contains the source package files created by the build process.

4. Command

* tar.gz Archive to Binary Package

# cd /hoem/<user name>/rpm
# rebuild -tb SOURCEs/cups-1.5.2-source.tar.gz

* Source Package to Binary Package

# rpmbuild --rebuild cups-1.5.2.src.rpm

* SPEC to Binary Package & Source Package

# rpmbuild -ba SPECS/cups.spec

* Clean build files

# rpmbuild --clean cups.spec

* Installing the SRPM

# rpm -ivh package-1.0.src.rpm

 

 

 

Linux:


Main menu 2

Story | by Dr. Radut