« Back to Index

Building an RPM https://github.com/integralist/simple-rpm

View original Gist on GitHub

Building an RPM.md

See my working application (and additional notes) here:

https://github.com/integralist/simple-rpm

Other information that led to the above repository, can be found below

References

Folders

Macro Name Name Location Purpose
%_specdir Specification directory ~/rpmbuild/SPECS RPM specifications (.spec) files
%_sourcedir Source directory ~/rpmbuild/SOURCES Pristine source package (e.g. tarballs) and patches
%_builddir Build directory ~/rpmbuild/BUILD Source files are unpacked and compiled in a subdirectory underneath this.
%_buildrootdir Build root directory ~/rpmbuild/BUILDROOT Files are installed under here during the %install stage.
%_rpmdir Binary RPM directory ~/rpmbuild/RPMS Binary RPMs are created and stored under here.
%_srcrpmdir Source RPM directory ~/rpmbuild/SRPMS Source RPMs are created and stored here.

Setup

mkdir -p ~/rpmbuild/{RPMS,SRPMS,BUILD,SOURCES,SPECS,tmp}

cat <<EOF >~/.rpmmacros
%_topdir   %(echo $HOME)/rpmbuild
%_tmppath  %{_topdir}/tmp
EOF

cd ~/rpmbuild

Tarball your project

mkdir foo-1.0
mkdir -p foo-1.0/usr/bin
mkdir -p foo-1.0/etc/foo
install -m 755 foo foo-1.0/usr/bin
install -m 644 foo.conf foo-1.0/etc/foo/

tar -zcvf foo-1.0.tar.gz foo-1.0/

Copy to SOURCES

cp foo-1.0.tar.gz SOURCES/

cat <<EOF > SPECS/foo.spec
# Don't try fancy stuff like debuginfo, which is useless on binary-only
# packages. Don't strip binary too
# Be sure buildpolicy set to do nothing
%define        __spec_install_post %{nil}
%define          debug_package %{nil}
%define        __os_install_post %{_dbpath}/brp-compress

Summary: A very simple toy bin rpm package
Name: foo
Version: 1.0
Release: 1
License: GPL+
Group: Development/Tools
SOURCE0 : %{name}-%{version}.tar.gz
URL: http://foo.company.com/

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root

%description
%{summary}

%prep
%setup -q

%build
# Empty section.

%install
rm -rf %{buildroot}
mkdir -p  %{buildroot}

# in builddir
cp -a * %{buildroot}


%clean
rm -rf %{buildroot}


%files
%defattr(-,root,root,-)
%config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf
%{_bindir}/*

%changelog
* Thu Apr 24 2009  Elia Pinto <devzero2000@rpm5.org> 1.0-1
- First Build

EOF

Build

rpmbuild -ba SPECS/foo.spec

Directory Structure

Simple example of what the directory structure looks like and means in practice…

.
├── BUILD
├── RPMS
├── SOURCES
│   ├── http://cache.ruby-lang.org/pub/ruby/ruby-2.1.2.tar.gz
├── SPECS
│   ├── ruby.spec
├── SRPMS

The BUILD folder is where all files go which are created during a build of the package when you create the rpm.

If the package builds correctly then any rpm(s) created will go into the RPMS and SRPMS folders.

The SRPMS directory only contains source rpms.

Spec files are basically instructions on how the rpm is built and they go in the SPECS folder.

The source tar file should go into the SOURCES directory along with any patches.

Miscellaneous Information