简体   繁体   中英

Creating a spec file for RPM

My general task is to put all the libraries from my software together with the executable software in a rpm file. My alternative way was to use a bash script which is putting all the libraries in the specified folders in CentOS. Also the dependencies of external packages like libraries that come from the yum package library need to be installied (eg yum apt-get install freeglut). Now I want only to use one rpm file that does everything for me, copying the libraries in the right folders, add the yum files too and that i can start the executable without any problems.

I read about creating rpm files in CentOS and my first try was to create the spec file. From https://stackoverflow.com/a/1165200/7105824 I found a minimal example:

Summary: A very simple toy bin rpm package
Name: toybinprog
Version: 1.0
Release: 1

License: GPL+
Group: Development/Tools
SOURCE0 : %{name}-%{version}.tar.gz
URL: http://toybinprog.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

In the macro %files, i can just put all the files inside. Is it also possible to put there the folder with the content of libraries inside than putting all 100 libraries extra? The next question is that I dont understand, what the macrro %SOURCE0 is doing.. What is the tar file that I have to put here? Maybe someone can make it clear for me what i have to do for my problem in an easy understandable way.

Thanks Everyone!

I like these guidelines here:

https://rpm-packaging-guide.github.io/

Source0 refers to the first source file that rpmbuild will look for when trying to prepare your package build. %SOURCE directive is a mapping to your sources. You can call %SOURCE0 in the other sections to refer to it.

%prep prepares the build setup and creates a RPM_BUILD_ROOT directory. %setup -q untars the tarball that you have in the current directory. From the example you have, it would be with a name toybinprog-1.0.tar.gz .

In the %build section, your source tarball is already extracted, so any command you enter, for example, make will be executed inside the extracted directory.

%install section tells rpmbuild where to install the files owned or generated during a build (that you want to install) by the package on a targeted system. On most occasions you want to install the binaries, libraries on the targeted system and keep header files and static libraries in a separate %{name}-devel sub-package.

Similar to the %files directive, there is a similar macro for directories, name %dir . Usage is similar. Some guidelines are here:

http://ftp.rpm.org/max-rpm/s1-rpm-inside-files-list-directives.html

%dir macro doesn't account for the files inside and rather a "sub" macro of the %file directive. An example,

  %files
  %license LICENSE
  %dir /usr/lib/%{name}/
  %{_bindir}/%{name}
  /usr/lib/%{name}/%{name}.py*

Above, the package, represented by %{name} will own two things

  1. %{name.py*} files inside /usr/lib/%{name}/
  2. The directory /usr/lib/%{name}

If your package %{name} is the primary package that's going to write to the specified %dir , then %{name} should own it. Normally, one wouldn't specify the ownership of the directory for a package, if it's written by multiple packages and during the installation of the package, the %dir is already created by some other package in the system.

Ownership of a file/directory can be queried using rpm command, for example /var/log directory is owned by the package filesystem on a Fedora box,

 ~]# rpm -qf /var/log
 filesystem-3.2-40.fc26.i686

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM