• Building RPM - quick start. We assemble an RPM package with our own hands Create an rpm package from sources

    But it often happens that you need to build a package with the necessary options (enable support for mysql, postgresql or cyrus-sasl2, etc.) that are not in the rpm package supplied on the distribution disk. The way out of this situation is to build your own package.

    To make it easier to build rpm packages, there is a package specially designed for this purpose - rpm-build.

    # rpm -qi rpm-build Name: rpm-build Relocations: (not relocatable) Version: 4.3.3 Vendor: CentOS Release: 7_nonptl Build Date: Mon 21 Feb 2005 20:21:52 Install Date: Sat 09 Apr 2005 22: 14:57 Build Host: guru.build.karan.org Group: Development/Tools Source RPM: rpm-4.3.3-7_nonptl.src.rpm Size: 1576124 License: GPL Signature: DSA/SHA1, Sun 27 Feb 2005 00: 36:59, Key ID a53d0bab443e1821 Packager: Karanbir Singh

    As can be seen from the description, this package contains a set of scripts and programs designed for assembling packages.

    In order to assemble any package, you first need to download the so-called. The sources for building the package are usually files with the extension src.rpm. Sometimes, as in the case of courier-imap, a spec file is included in the source code.

    The site www.rpmfind.net is very convenient for searching for rpm and src.rpm packages. For example, we found the package we needed - postfix, squid, etc. We can immediately find out which packages are needed to build it. Here is the standard package information page for both postix and squid. It also contains a checksum to verify the integrity of the package.

    After we have received the sources and verified their integrity, we need to install the appropriate package.

    # rpm -ivh postfix-2.2.8-1.2.src.rpm 1:postfix ################################ ###########

    After performing this operation, the postfix sources and all the necessary parts, as well as scripts, were installed in /usr/src/redhat/SOURCES/, and the spec file (instructions for building the rpm package) in /usr/src/redhat/SPECS/.

    # ls /usr/src/redhat/SOURCES/ pflogsumm-1.1.0.tar.gz postfix-etc-init.d-postfix postfix-2.1.1-config.patch postfix-hostname-fqdn.patch postfix-2.1.1 -obsolete.patch postfix-large-fs.patch postfix-2.1.5-aliases.patch postfix-pam.conf postfix-2.2.5-cyrus.patch postfix-sasl.conf postfix-2.2.8.tar.gz README- Postfix-SASL-RedHat.txt postfix-alternatives.patch # ls /usr/src/redhat/SPECS/ postfix.spec

    This is the default file location when installing src.rpm. In principle, the names of the folders speak for themselves.

    And so, in order to start building the package, you need to go to the folder with the spec file and run the following command

    # cd /usr/src/redhat/SPECS/ # rpmbuild -ba --target=i686 postfix.spec Platforms to build: i686 Build for i686 platform Running (%prep): /bin/sh -e /var/tmp/rpm -tmp.82019 + umask 022 + cd /usr/src/redhat/BUILD + umask 022 + cd /usr/src/redhat/BUILD + rm -rf postfix-2.2.8 + /bin/gzip -dc /usr/src /redhat/SOURCES/postfix-2.2.8.tar.gz + tar -xf - + STATUS=0 + "[" 0 -ne 0 "]" + cd postfix-2.2.8 ++ /usr/bin/id - u + "[" 0 = 0 "]" + /bin/chown -Rhf root . ++ /usr/bin/id -u + "[" 0 = 0 "]" + /bin/chgrp -Rhf root . + /bin/chmod -Rf a+rX,u+w,g-w,o-w . + echo "Patch #1 (postfix-2.1.1-config.patch):" Patch #1 (postfix-2.1.1-config.patch): + patch -p1 -b --suffix .config -s ... ... ... Recorded by: /usr/src/redhat/SRPMS/postfix-2.2.8-1.2.src.rpm Recorded by: /usr/src/redhat/RPMS/i686/postfix-2.2.8-1.2.i686 .rpm Written by: /usr/src/redhat/RPMS/i686/postfix-pflogsumm-2.2.8-1.2.i686.rpm Executed (%clean): /bin/sh -e /var/tmp/rpm-tmp.73987 + umask 022 + cd /usr/src/redhat/BUILD + cd postfix-2.2.8 + /bin/rm -rf /var/tmp/postfix-buildroot + exit 0

    From the last lines you can see that the finished rpm package is called postfix-2.2.8-1.2.i686.rpm and is saved in the /usr/src/redhat/RPMS/i686/ folder, since when building the package we specified the --target=i686 key .

    The actual assembly should not cause any problems. But what if we need to build a package with our own options, for example, enable mysql or sasl2 support, etc.? For these purposes, you will need to edit the spec file.

    Let's look at part of the postfix spec file. It should be noted that postfix has a non-standard spec file, so to speak.

    For example, we wanted to build postfix with MySQL support, to do this, at the very beginning we change %define MYSQL 0 to %define MYSQL 1. and run the command again

    # rpmbuild -ba --target=i686 postfix.spec Platforms to build: i686 Build for i686 platform error: Unmet build dependencies: mysql-devel needed for postfix-2.2.8-1.2.i686

    He writes to us that to build it we need to install the mysql-devel package. Please note that the version is not specified, this means that you can install any version that postfix supports or the package you need.

    If you were building from source, you would have to find out on your own what packages are needed to build a given package. This is one of the advantages of building from src.rpm compared to tar.gz or tar.bz2.

    Install the appropriate package

    # rpm -ivh MySQL-devel-4.1.9-0.i386.rpm Preparing... ################################ ############## 1:MySQL-devel ############################### #############

    And we restart the postfix assembly. This time we see that all the necessary packages for the build are installed and now we just need to wait for the build to finish.

    # rpmbuild -ba --target=i686 postfix.spec Platforms to build: i686 Build for i686 platform Running (%prep): /bin/sh -e /var/tmp/rpm-tmp.86320 + umask 022 + cd /usr /src/redhat/BUILD + umask 022 + cd /usr/src/redhat/BUILD + rm -rf postfix-2.2.8 ... ... ... Recorded in: /usr/src/redhat/SRPMS/postfix- 2.2.8-1.2.src.rpm Written by: /usr/src/redhat/RPMS/i686/postfix-2.2.8-1.2.i686.rpm Written by: /usr/src/redhat/RPMS/i686/postfix-pflogsumm- 2.2.8-1.2.i686.rpm Running(%clean): /bin/sh -e /var/tmp/rpm-tmp.52381 + umask 022 + cd /usr/src/redhat/BUILD + cd postfix-2.2. 8 + /bin/rm -rf /var/tmp/postfix-buildroot + exit 0

    We have all the package assembled, now we need to install it and enjoy life.

    # rpm -ivh /usr/src/redhat/RPMS/i686/postfix-2.2.8-1.2.i686.rpm Preparing... #################### ######################### 1:postfix ######################### ###################

    For a better understanding, let's look at the squid build, which has a more standard spec file structure. As always, first install src.rpm, and do not forget to check the size and checksum.

    # rpm -ivh squid-2.5.STABLE11-2.src.rpm 1:squid ################################### ###########

    You can find out all possible keys as follows.

    # cd /usr/src/redhat/SPECS # rpmbuild --bp squid.spec # cd ../BUILD/squid-2.5.STABLE11/ # ./configure --help Usage: configure Options: Configuration: --cache-file =FILE cache test results in FILE --help print this message --no-create do not create output files --quiet, --silent do not print `checking..." messages --site-file=FILE use FILE as the site file --version print the version of autoconf that created configure Directory and file names: --prefix=PREFIX install architecture-independent files in PREFIX --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX --bindir=DIR user executables in DIR --sbindir=DIR system admin executables in DIR --libexecdir=DIR program executables in DIR --datadir=DIR read-only architecture-independent data in DIR --sysconfdir=DIR read-only single-machine data in DIR --sharedstatedir=DIR modifiable architecture-independent data in DIR --localstatedir=DIR modifiable single-machine data in DIR --libdir=DIR object code libraries in DIR --includedir=DIR C header files in DIR --oldincludedir=DIR C header files for non-gcc in DIR --infodir=DIR info documentation in DIR --mandir=DIR man documentation in DIR --srcdir=DIR find the sources in DIR --program-prefix=PREFIX prepend PREFIX to installed program names --program-suffix=SUFFIX append SUFFIX to installed program names --program-transform-name=PROGRAM run sed PROGRAM on installed program names Host type: --build=BUILD configure for building on BUILD --host=HOST configure for HOST --target=TARGET configure for TARGET Features and packages: --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE --with-PACKAGE[= ARG] use PACKAGE --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --x-includes=DIR X include files are in DIR --x-libraries=DIR X library files are in DIR --enable and --with options recognized: --disable-dependency-tracking Speeds up one-time builds --enable-dependency-tracking Do not reject slow dependency extractors --enable-maintainer-mode enable make rules and dependencies not useful (and sometimes confusing) to the casual installer --enable-dlmalloc[=LIB] Compile & use the malloc package by Doug Lea --enable-gnuregex Compile GNUregex. Unless you have reason to use this option, you should not enable it. This library file is usually only required on Windows and very old Unix boxes which do not have their own regex library built in. --enable-xmalloc-statistics Show malloc statistics in status page --enable-carp Enable CARP support --enable-async-io[=N_THREADS] Shorthand for --with-aufs-threads=N_THREADS --with-pthreads -- enable-storeio=ufs,aufs --with-aufs-threads=N_THREADS Tune the number of worker threads for the aufs object store. --with-pthreads Use POSIX Threads --with-aio Use POSIX AIO --with-dl Use dynamic linking --enable-storeio="list of modules" Build support for the list of store I/O modules. The default is only to build the ufs module. See src/fs for a list of available modules, or Programmers Guide section
    for details on how to build your custom store module
    --enable-heap-replacement
    Backwards compatibility option. Please use the
    new --enable-removal-policies directive instead.
    --enable-removal-policies="list of policies"
    Build support for the list of removal policies.
    The default is only to build the lru module.
    See src/repl for a list of available modules, or
    Programmers Guide section 9.9 for details on how
    to build your custom policy
    --enable-icmp Enable ICMP pinging
    --enable-delay-pools Enable delay pools to limit bandwidth usage
    --enable-useragent-log Enable logging of User-Agent header
    --enable-referer-log Enable logging of Referer header
    --disable-wccp Disable Web Cache Coordination Protocol
    --enable-kill-parent-hack
    Kill parent on shutdown
    --enable-snmp Enable SNMP monitoring
    --enable-cachemgr-hostname[=hostname]
    Make cachemgr.cgi default to this host
    --enable-arp-acl Enable use of ARP ACL lists (ether address)
    --enable-htcp Enable HTCP protocol
    --enable-ssl Enable ssl gatewaying support using OpenSSL
    --with-openssl[=prefix]
    Compile with the OpenSSL libraries. The path to
    the OpenSSL development libraries and headers
    installation can be specified if outside of the
    system standard directories
    --enable-forw-via-db Enable Forw/Via database
    --enable-cache-digests Use Cache Digests
    see http://www.squid-cache.org/FAQ/FAQ-16.html
    --enable-default-err-language=lang
    Select default language for Error pages (see
    errors directory)
    --enable-err-languages="lang1 lang2.."
    Select languages ​​to be installed. (All will be
    installed by default)
    --with-coss-membuf-size COSS membuf size (default 1048576 bytes)
    --enable-poll Enable poll() instead of select(). Normally poll
    is preferred over select, but configure knows poll
    is broken on some platforms. If you think you are
    smarter than the configure script, you may enable
    poll with this option.
    --disable-poll Disable the use of poll().
    --disable-http-violations
    This allows you to remove code which is known to
    violate the HTTP protocol specification.
    --enable-ipf-transparent
    using IP-Filter network address redirection.
    --enable-pf-transparent
    Enable Transparent Proxy support for systems
    using PF network address redirection.
    --enable-linux-netfilter
    Enable Transparent Proxy support for Linux 2.4.
    --with-large-files Enable support for large files (logs etc).
    --enable-large-cache-files
    Enable support for large cache files (>2GB).
    WARNING: on-disk cache format is changed by this option
    --with-build-environment=model
    The build environment to use. Normally one of
    POSIX_V6_ILP32_OFF32 32 bits
    POSIX_V6_ILP32_OFFBIG 32 bits with large file support
    POSIX_V6_LP64_OFF64 64 bits
    POSIX_V6_LPBIG_OFFBIG large pointers and files
    XBS5_ILP32_OFF32 32 bits (legacy)
    XBS5_ILP32_OFFBIG 32 bits with large file suppor
    XBS5_LP64_OFF64 64 bits (legacy)
    XBS5_LPBIG_OFFBIG large pointers and files
    default The default for your OS
    --enable-leakfinder
    Enable Leak Finding code. Enabling this alone
    does nothing; you also have to modify the source
    code to use the leak finding functions. Probably
    Useful for hackers only.
    --disable-ident-lookups
    This allows you to remove code that performs
    Ident (RFC 931) lookups.
    --disable-internal-dns This prevents Squid from directly sending and
    receiving DNS messages, and instead enables the
    old external "dnsserver" processes.
    --enable-truncate This uses truncate() instead of unlink() when
    removing cache files. Truncate gives a little
    performance improvement, but may cause problems
    when used with async I/O. Truncate uses more
    filesystem inodes than unlink..
    --disable-hostname-checks
    Squid by default rejects any host names with
    odd characters in their name to conform with
    internet standards. If you disagree with this
    you may use this switch to turn off any such
    checks, provided that the resolver used by
    Squid does not reject such host names.. This
    may be required to participate in testbeds for
    international domain names.
    --enable-underscores Squid by default rejects any host names with _
    in their name to conform with internet standards.
    If you disagree with this you may allow _ in
    hostnames by using this switch, provided that
    the resolver library on the host where Squid runs
    does not reject _ in hostnames...
    --enable-auth="list of auth scheme modules"
    Build support for the list of authentication schemes.
    The default is to build support for the Basic scheme.
    See src/auth for a list of available modules, or
    Programmers Guide section authentication schemes
    for details on how to build your custom auth scheme
    module
    --enable-auth-modules="list of helpers"
    Backwards compatibility alias for
    --enable-basic-auth-helpers
    --enable-basic-auth-helpers="list of helpers"
    This option selects which basic scheme proxy_auth
    helpers to build and install as part of the normal
    build process. For a list of available
    helpers see the helpers/basic_auth directory.
    --enable-ntlm-auth-helpers="list of helpers"
    This option selects which proxy_auth ntlm helpers
    to build and install as part of the normal build
    process. For a list of available helpers see
    the helpers/ntlm_auth directory.
    --enable-digest-auth-helpers="list of helpers"
    This option selects which digest scheme authentication
    helpers to build and install as part of the normal build
    helpers/digest_auth directory.
    --enable-ntlm-fail-open Enable NTLM fail open, where a helper that fails
    one of the Authentication steps can allow squid to
    still authenticate the user.
    --enable-external-acl-helpers="list of helpers"
    This option selects which external_acl helpers to
    build and install as part of the normal build
    process. For a list of available helpers see the
    helpers/external_acl directory.
    --with-samba-sources=/path/to/samba-source-tree
    Path where the correct Samba source files can be
    found while building winbind helpers. (defaults to
    use internal copies of the headers from Samba-2.2.7)

    Disable-unlinkd Do not use unlinkd
    --enable-stacktraces Enable automatic call backtrace on fatal errors
    --enable-x-accelerator-vary
    Enable support for the X-Accelerator-Vary
    HTTP header. Can be used to indicate
    variance within an accelerator setup.
    Typically used together with other code
    that adds custom HTTP headers to the requests.
    --with-maxfd=N Override maximum number of filedescriptors. Useful
    if you build as another user who is not privileged
    to use the number of filedescriptors you want the
    resulting binary to support

    After you have found the required key, add it to %configure. For example, we want to build squid with ssl support. From the help, we determined that for this, we need to add two keys --enable-ssl and --with-openssl. We make the appropriate changes

    Save the file and start building.

    # rpmbuild -ba --target=athlon squid.spec Platforms to build: athlon Build for the athlon platform Running (%prep): /bin/sh -e /var/tmp/rpm-tmp.59199 + umask 022 + cd /usr /src/redhat/BUILD + cd /usr/src/redhat/BUILD + rm -rf squid-2.5.STABLE11 + /usr/bin/bzip2 -dc /usr/src/redhat/SOURCES/squid-2.5.STABLE11.tar .bz2 ... ... ... SSL gatewaying using OpenSSL enabled
    Using OpenSSL MD5 implementation
    ... ... ... Recorded by: /usr/src/redhat/SRPMS/squid-2.5.STABLE11-2.src.rpm Recorded by: /usr/src/redhat/RPMS/athlon/squid-2.5.STABLE11- 2.athlon.rpm Running(%clean): /bin/sh -e /var/tmp/rpm-tmp.7322 + umask 022 + cd /usr/src/redhat/BUILD + cd squid-2.5.STABLE11 + rm - rf /var/tmp/squid-2.5.STABLE11-root + exit 0 Execute(--clean): /bin/sh -e /var/tmp/rpm-tmp.7322 + umask 022 + cd /usr/src/redhat /BUILD + rm -rf squid-2.5.STABLE11 + exit 0

    We have assembled all squid successfully, now all that remains is to install or update it.

    First, let's figure out what should be on the system to build an rpm package. The rpm-build package must be installed. Without it, the rpmbuild command will not be available. Along with it, a number of packages used during assembly will be supplied as dependencies. In dependencies for building a package in ROSE, it is usually not customary to specify a C/C++ compiler; for this reason, sooner or later you will need the gcc and gcc-c++ packages. All other dependencies must be requested by the package itself. Of course, there are mistakes, and during the assembly process you realize that you missed something, but this is usually quite rare and not critical.

    What exactly is an RPM package? RPM packages are divided into source packages - src.rpm and ready-to-install packages - %(arch).rpm. The src.rpm packages contain the original tarball (program source), any other sources, parts, and the most important spec file that controls the build process. All these files are packed into a cpio archive. When you try to access the src.rpm package using the mc file manager, you will see it. The package also contains some files with information.

    %(arch).rpm packages contain a cpio archive with files that, after installation, will be distributed in the appropriate directories, information files and installation scripts.

    You may also find it without source code. They are usually created for proprietary programs that cannot be included in the distribution (there are no source codes, and the binary somehow needs to be remade or is simply prohibited from being placed on distribution mirrors by the license). Inside this package there is usually only a spec file, and the binary is downloaded and, if necessary, modified during the installation of the package (for example, in a post-script, which will be discussed below).

    Packages can be collected from any user. It is not recommended to do this as root, because there is a possibility that the root for the installation section will be the directory / and then the rm -rf %(buildroot) command will destroy everything in the world. It also happens that “crooked” packages are not perform the installation correctly, and place them not in a temporary directory, but directly somewhere in %(_prefix) (/usr ). Some of the files will be lost, although this, of course, will not affect the performance of the package on this machine.

    What needs to be done to be able to collect packages from under a regular user? First of all, you need to create a rpmbuild directory file in your home directory with the following structure:

    ~/rpmbuild |-- BUILD |-- BUILDROOT |-- RPMS | |-- i586 | |-- x86_64 | `-- noarch |-- SOURCES |-- SPECS `-- SRPMS

    You need to create the BUILD , RPMS , SOURCES , SPECS , SRPMS directories manually, the RPMS directory subdirectories should be created automatically during build depending on the architecture.

    In ROSE it is not customary to write the package builder and vendor in spec files; these values ​​are set automatically by the ABF build system. ABF also automatically signs compiled packages with the key of the corresponding repository. Therefore, we will not touch on these issues here.

    Now let's see what the most important file of the rpm package, the spec file, is. For example, let's take it from the stardict package. This package is well suited for learning, since it contains several tarballs (program source packaged in tar), several packages are obtained, and there is such a thing as diagrams. Typically the spec file has the same name as the package itself (stardict.spec). However, you can add a package version (stardict-2.spec), useful if you are trying to support multiple branches of programs. You can even give it some other name, but this is, to put it mildly, inconvenient.

    So, the contents of the stardict.spec file are given below. We will immediately insert comments after certain sections, but if you combine all the blocks into the same file, you will get a full-fledged stardict.spec.

    The spec file consists of sections and a header:

    Summary: StarDict dictionary Name: stardict Version: 2.4.8 Release: 4 License: GPL URL: Group: User Interface/Desktops Source0: %(name)-%(version).tar.bz2 Source1: %(name)-tools- %(version).tar.bz2 Patch0: %(name)-2.4.8-desktop.patch

    Summary- a brief description of the package, Name- Name, Version- version, Release- release. The last three tags correspond to the macro definitions %(name) , %(version) , %(release) . They are often used later. Name And Version usually the same as the name of the tarball. If they differ, then in principle there is nothing to worry about, but in some places in the spec file you will have to use non-standard methods. If you are assembling a package from cvs, svn, etc., then it is recommended that at the very beginning of the file you make the macro definition %define date 20070422 (in this format, you can guess why) and define the Release tag as follows:

    Release: 0.git%(date).4

    Source*- source texts, tarballs, just files. In this example there are two tarballs with different programs, which makes the assembly much more complicated. Regular files, such as configurations, can simply be copied to the %%install section using the install command. It has a simple syntax, install -m mask_as_chmod what goes where. You can also create directories using it. It is not used in our example, but you can read more about it in man.

    Patch- patches, fixes that you or someone else have released for this package. It is not customary to change the source code of the program itself and then wrap it in a tarball. It is customary to apply patches. You can do them as follows. Unpack the original tarball, for us it will be stardict-2.4.8, then copy stardict-2.4.8 to stardict-2.4.8.orig. After that, change the code in the stardict-2.4.8 directory, exit it and issue the command diff -ur stardict-2.4.8.orig stardict-2.4.8 > stardict-2.4.8-patch_name.patch. As you can see, before the patch is added there is %(name)-%(version) of the package. In the spec file itself, you must write the name of the patch without macro definitions. At least a version, for sure. Otherwise, when you update the package version, you will update the version of the patch defined by the %(version) macro, and the patch may be suitable for the new version of the program without any changes. If during the assembly itself the patch could not be applied, then it should either be modified for this version of the program, or disabled in the %setup section.

    In the spec files of packages of many distributions, you can also find in the header a definition of BuildRoot - the directory in which the build is carried out. In ROSE this definition is not necessary; the name BuildRoot is generated automatically.

    BuildRequires: libgnomeui-devel >= 2.2.0 BuildRequires: scrollkeeper BuildRequires: gettext Requires(post): GConf2 Requires(post): scrollkeeper Requires(postun): scrollkeeper

    BuildRequires is a section in which packages that are required to build our program are written, separated by commas or separated by spaces. You can get them from some README and INSTALL files (although there is rarely anything useful about this), from the configuration process (usually the configure script at this point) and from the build process itself (sometimes configure will miss something and assembly will stop).

    Requires - this section contains packages or files(!) that this package will require during installation. When building, the dependencies will automatically include all the libraries that our package will require, but you can also specify the packages manually. Rpm also automatically registers the dependencies of perl, python, mono and some others (all these dependencies are written not in the spec file, of course, but in the package itself). If you do not need dependencies to be registered automatically, you should add a new AutoReq: no tag to the spec file. It is usually prescribed when building proprietary programs, since rpm adds internal dependencies from the compiled program.

    Our example uses the Requires(post) and Requires(postun) constructs for dependencies in the install and uninstall scripts. In principle, a simple Requires is sufficient. There's not much to comment on here. It’s just that StarDict itself doesn’t need these dependencies during operation. They are needed only during installation and removal.

    There are several other useful tags that are not used here.

    Provides: title1, title2

    Names other than %(name) that this package will respond to. It is convenient to indicate if you have changed the name of a package, but other packages continue to depend on the old name.

    Obsoletes: name1, name2

    Removes the specified packages when installing the current package. It is as if they were saying that this package replaces the ones specified (in terms of functionality, set of files, etc.). You can use the construction name< . Тут вы должны сами понимать, что к чему.

    Conflicts: title1, title2

    Packages that conflict with the current one are listed. It is implied that these packages must be manually removed before installing ours. Constructions with comparison marks and versions are also used (see above).

    Suggests: title1, title2

    - soft dependencies are packages that add additional functionality to a given package (for example, codecs for a media player), but which you can do without.

    Epoch: number

    Usually it is either not specified at all or equal to 0. The essence of this parameter is this. Let our package stardict still have the version 2.4.8 and there is also an older one 2.4.5 . So if stardict 2.4.5 has %(epoch) 1 , and for 2.4.8 - 0 , then package 2.4.5 will always be newer than 2.4.8. This is what RPM will tell you during installation. This parameter is convenient if you want to roll back to a previous version (of course, if you put everything in a public repository and grab everything through urpmi or rpmdrake . For “home” needs, the parameter rpm --force is suitable). If the Epoch: 0 tag is defined, then the packet will take precedence over a packet with an undefined Epoch tag.

    BuildArch: architecture

    The architecture under which our package will be assembled. If this option is not specified, the package will be built for the current architecture. Typically this option is specified in order to build an architecture package noarch, that is, a package that does not contain binaries.

    ExclusiveArch: architecture1 architecture2

    Architectures for which this package can be assembled. Typically used when assembling modules for the kernel.

    This is where the header ends and the individual sections begin.

    %description StarDict is an international dictionary written for the GNOME environment. It has powerful features such as "Glob-style pattern matching," "Scan selection word," "Fuzzy search," etc.

    Description of the main package, the one with the name %(name)

    %package tools Summary: StarDict-Editor Requires: %(name) = %(version)-%(release) Group: User Interface/Desktops

    Here we create a new package whose name will be %(name)-tools . If you need to call the package something completely different, you should do it, for example, like this: %package -n tools-stardict . The version of the new package is taken from the given Version tag. Pay attention to Requires. It contains a dependency on the main stardict package. If it had %(epoch) , then it would be necessary to specify Requires: %(name)-%(epoch):%(version)-%(release). Otherwise, you simply will not be able to install this package.

    %description tools A simple tool for StarDict.

    Description of the second package

    %prep %setup -q -a1 %patch0 -p1

    The %prep section begins preparation for assembly. %setup unpacks the sources. Option -q does not show archive unpacking output. Option -a1 used to unpack %(SOURCE1) , the second tarball inside(!) the directory of the first tarball. Accordingly, the number indicates the SOURCE number. The parameter is also sometimes used -b, then the second tarball is unpacked into the same directory as the first. Accordingly, if we have one tarball, then the options -a, -b are not used.

    If your first directory in the tarball has a name different from %(name)-%(version), then rpm will not be able to automatically enter this directory. In this case, you should change %setup a little. If in the archive stardict-2.4.8.tar.bz2 the first directory is named, for example, simply stardict , then it will look like this:

    %setup -q -n %(name) -a1

    Immediately after unpacking the package, before %patch , if necessary, you can copy the files, or run any programs to change the sources. Let's say copy the Russification file, or correct some source code with sed. Just call cp, sed or something else here. The root here is the directory into which the first tarball was unpacked (the $RPM_BUILD_DIR variable is responsible for it, but it is extremely rarely used).

    Using %patch patches are applied. If you made a patch, as we wrote above, then you will always have the parameter -p1. The parameter is also often used -b .patch_name, to create a backup.

    %build pushd %(name)-tools-%(version) %configure %make popd %configure %make

    The %build section is where the package is built. Pay attention to pushd and popd. With these commands we navigate and exit the second tarball directory. This will be the root directory after pushd . After the popd command we will return to the directory of the first tarball. Accordingly, if you have one source, then you do not need to use these commands.

    Since we have two programs in one package, we run %configure configuration twice and make twice. If the package is configured using autotools , then the %configure macro runs the configure script from the root of the unpacked tarball. It usually has many parameters, they can be viewed from the command line using ./configure --help . After %configure you can specify the parameters you need. Note that the call to %configure and ./configure are different. In the first case, the configurator will be given the correct directories for installation (as well as standard parameters), in the second - default directories.

    After a successful configuration, assembly occurs, namely the %make macro, which calls the command of the same name with some additional parameters (in particular, on multiprocessor machines, parallel assembly is used - the option -j).

    If the package does not use autotools, then %configure and maybe %make do not need to be used; to build, read the README and INSTALL file. ROSA also has macros for other situations - for example, %cmake for the build tool of the same name.

    When the build is completed successfully, the %install section comes into effect.

    %install pushd %(name)-tools-%(version) %makeinstall_std popd %makeinstall_std %find_lang %(name)

    %%find_lang , search for localization files. Its parameter is the name of the files that will be located in the directory after installation %(buildroot)/usr/share/locale/*/LC_MESSAGES/*.mo. This usually matches %(name) . If this is not the case, write a different name.

    In many spec files, you may notice that the command rm -rf %(buildroot) or rm -rf $RPM_BUILD_ROOT is executed at the very beginning of the %install section, as well as the %clean section with the same lines. In modern ROSE there is no need for this; such cleaning is performed automatically.

    %preun %preun_uninstall_gconf_schemas %(name)

    Sections for installation scripts. In general, there are several of them. %pre - executed before installation, %post - after installation, %preun - before removal, %postun - after removal. In our example, uninstalling removes the Gconf schemas. Here we assume that there is only one schema in the package and its name is the same as the package name. Please note that to remove schemas we call a special macro; this macro is expanded by ROSA's rpmbuild into a set of necessary Shell commands, which, in fact, delete the schema. Installation of schemas when installing a package is done automatically using RPM file triggers.

    Each package may have its own scripts, so you should also read the documentation. If no scripts are needed for proper operation, then these sections should not be used. You can use bash scripts in these sections (just like in any other sections).

    In the %files sections we must specify which files should be packaged. All files must be specified, otherwise rpmbuild will report unpacked files.

    Option -f a file containing a list of processed files is specified. In our case, this file contains the paths to the localization files. You can, in principle, create your own file and insert it.

    Special macro definitions are used to define directories.

    • %(_prefix) - /usr
    • %(_sysconfdir) - /etc
    • %(_bindir) - /usr/bin
    • %(_datadir) - /usr/share
    • %(_libdir) - /usr/lib or /usr/lib64 depending on the system bit depth
    • %(_lib) - /lib or /lib64, respectively
    • %(_libexecdir) - /usr/libexec
    • %(_includedir) - /usr/unclude
    • %(_mandir) - /usr/share/man
    • %(_sbindir) - /usr/sbin
    • %(_localstatedir) - /var .
    • %(systemd_libdir) - /usr/lib/systemd
    %files -f %(name).lang %defattr(-, root, root) %doc AUTHORS COPYING INSTALL README NEWS %(_sysconfdir)/gconf/schemas/stardict.schemas %(_bindir)/stardict %(_bindir)/stardict -editor %(_libdir)/bonobo/servers/GNOME_Stardict.server %(_datadir)/applications/*.desktop %(_datadir)/stardict %(_datadir)/locale/*/LC_MESSAGES/* %(_datadir)/pixmaps/stardict .png %(_datadir)/gnome/help/%(name)/* %(_datadir)/idl/GNOME_Stardict.idl %(_datadir)/omf/* %doc %(_mandir)/man?/*

    %doc marks files as documentation. The third line copies the specified files to the directory %(_datadir)/doc/%(name)-%(version). By default, files in the rpm package will be owned by root, and root access rights will be the same as during the installation process. If this needs to be changed, then use the %defattr construct.

    %files tools %(_bindir)/stardict-editor

    Same for the stardict-tools package. If it were called tools-stardict , then %files would look like this:

    %files -n tools-%(name).

    The last thing in the spec file is %changelog . In the changelog you indicate changes in the package compared to the previous version. Its syntax is approximately as follows.

    %changelog * Sun Apr 22 2007 Your Name - 2.4.8-4 - update desktop patch

    Macro definitions

    Now it's time to take a closer look at macros and variables. Let's say we are building a package from SVN, in this case the revision date is usually included in the release. At the very beginning of the spec file you need to define the date variable:

    %define date 20070612

    As we can see, the macro definition %define is responsible for defining variables. Now, anywhere in the spec file, we can use our variable in the form %(date) (brackets are not required, but in ROSE it is customary to put variables in brackets, and not to take macro definitions; this makes it easier to distinguish between them). For example, defining the main parameters would look something like this:

    Version: 0.5 Release: 0.svn%(date).3

    Please note that the date is preceded by 0. , and after the date - a number, which increases if necessary to raise the release. Why is this done? When will the final version finally be released (in our case - 0.5 ), the revision can be removed and simply written into the release 1 . At the same time, literal 1 greater than any line starting with 0 , and the package will be considered newer than pre-release packages built from SVN revisions.

    An extremely popular macro definition is the construction

    %if condition action1 %else action2 %endif

    or just %if without %else . The idea is simple, if the condition at %if is true, then action1 is executed, otherwise action2 is executed.

    Let's say we are again collecting something from SVN. Usually inside the archive, if it is from SVN, instead of the %(name)-%(version) directory, they simply indicate %(name) (the sim-0.9.5.tar.bz2 archive has a sim directory inside, since the final release is sim 0.9.5 does not exist. The final release will have sim-0.9.5 as its first directory. To avoid rewriting the spec file every time, you can make the following macro definitions:

    %define svn 1 ... %prep %if %(svn) %setup -q -n %(name) %else %setup -q %endif

    If the svn variable is not defined, then the part of the script after %else will be executed. You can also use a stricter condition (don't forget the quotes):

    %define svn 1 ... %prep %if "%(svn)" == "1" %setup -q -n %(name) %else %setup -q %endif

    Inside all sections of the spec file, we can use any Linux commands, without any bells and whistles, but in the file header it’s not so simple. For example, we need to determine the Firefox version for a package (let's say epiphany) and add it to the Requires: section. It will look like this:

    Requires: firefox = %(rpm -q firefox --qf "%%(version)")

    Please note that the external command is executed in %() (almost like bash - $() ) and in the spec file you must put two % signs in the parameters. This way you can call any Linux commands, for example, to determine the kernel version.

    Another popular macro definition is the %ifarch .. %endif construct. If the architecture matches the one specified after %ifarch , then some action is performed. The architectures come in i386, i486, i586, i686, i?86, x86_64, and, of course, some others that you probably won’t come across.

    As noted above, in all sections of the spec file you can use any Shell commands, including for, while, if, etc.

    Building the package

    Now let's move on directly to assembling the package. Sources and patches should be in the SOURCES directory, and the spec file should be in the SPECS directory. After this you need to issue the command:

    Rpmbuild -ba spec file

    After this, the package will be built (or not built, but will fall out with errors), and binary packages will appear in the subdirectories of the RPMS directory, and the source will appear in the SRPMS directory.

    Very often, just before the build is completed, rpmbuild displays a message about files found but unpacked. This means that you simply did not include them in the %files section. You just need to add them there. If you do not want these files to be included in the package, you can use one of the following methods:

    • Add a macro definition to the %files section
    %exclude file_path/file
    • Add a macro definition to the beginning of the spec file
    %define_unpackaged_files_terminate_build 0

    If you need to build only the binary or only the source, then instead of -ba should be used -bb And -bs respectively. Among the useful parameters of rpmbuild we can note -clean(remove all garbage), -rmsource(remove sources from the SOURCE directory) and -target=architecture(build a package for a specific architecture).

    You can also run scripts only in a specific section. We will not describe such parameters here, see man rpmbuild.

    Building an RPM package from one already installed on the system

    Sometimes a situation happens that some package is already installed on the system (maybe in a very old system) and you really want to get an rpm with it, but it just hasn’t been saved. You may also want to quickly put together a package with configuration files modified to suit your needs.

    To solve this problem, you should use the rpmrebuild utility. This utility, written in bash, is available in the ROSA contrib repository.

    It's extremely easy to work with. You just need to issue the command:

    Rpmrebuild installed package_name

    If any file has been changed, you will be notified about it, but the build process will not be interrupted.

    Rpmrebuild has a huge number of parameters, for example, you can change the release of the package, changelog, scripts, Requires sections, package descriptions and much more. You can even simply change the spec file, which the script will generate itself. It's true that it will be a little scary, but it's still better than nothing.

    All parameters can be viewed using

    Rpmrebuild --help

    All the manuals I found on the Internet in most cases come down to two types:
    — translation of documentation (which I still advise you to read, as my article will cover only part of the information that you will need in the future)
    — brief instructions on how to run rpmbuild when we already have everything.
    Personally, I was faced with the need to build a package from a source, with which there was nothing, and most importantly, a spec file from which to build the package. As a result, we will write our own spec file to build the package and immediately add our own configs there (this issue is also not very well covered).

    I will be building a package from the ffmpeg sources for AirVideoServer, which I already described as . I am a supporter of installing applications through it in a distribution that uses a package manager, which is why on CentOS I don’t like building software from source. For this reason, I decided to collect everything in bags for myself. Assembling the also necessary lame (it comes with spec files included) and x264 (you can write a spec file for it yourself after reading this article) should not cause you problems in the future.

    And so, first we need to set up the “environment” in which we will collect the package. It is not recommended to build packages from under root, so we will create a separate user, but for now we will install all the necessary software:

    Yum install gcc gcc-c++ automake autoconf libtool yasm nasm ncurses-devel git ftp rpmdevtools

    Now let’s create a special user

    Useradd rpmbuild

    and let's go under it

    Su - rpmbuild

    let's execute the command

    Rpmdev-setuptree

    so that it would deploy the necessary directory structure for us to build
    And now we can proceed directly to the assembly.
    We need the source itself

    Wget http://inmethod.com/airvideo/download/ffmpeg-for-2.4.5-beta7.tar.bz2

    unfold it

    Tar -xjf ffmpeg-for-2.4.5-beta7.tar.bz2

    Let's put the configuration file with the contents next to it:

    Nano airvideoserver.conf path.ffmpeg = /usr/bin/ffmpeg password = subtitles.encoding = utf-8 subtitles.font = Verdana folders = Movies:/home/share/films

    Let's download the server file here:

    Wget http://inmethod.com/airvideo/download/linux/alpha6/AirVideoServerLinux.jar

    And the init script:

    Nano AirVideoServer #!/bin/bash #chkconfig: - 80 20 #description: AirVideo server # Source function library. . /etc/rc.d/init.d/functions PREFIX_DIR=/usr/local/AirVideo case "$1" in start) echo -n "Starting AirVideo server: " daemon java -jar $(PREFIX_DIR)/AirVideoServerLinux.jar $( PREFIX_DIR)/properties.conf > /dev/null 2>&1 & [ $? -eq 0 ] && success || failure echo ;; stop) echo -n "Stopping AirVideo server: " killproc java echo ;; status) status java ;; restart | reload) $0 stop ; $0 start ;; *) echo "Usage: airvideo (start|stop|status|reload|restart" exit 1 ;; esac

    Now we can move on to writing our spec file for the assembly.
    First we have the various headings. The package name, version and release are important; they will determine which directory the source will be deployed into before assembly. In Source1, Source2 and Source3 we indicate our 3 additional files, config, server and init script, which must be added to the package when building.

    Name: ffmpeg Version: 2.4.5 Release: beta7 Summary: ffmpeg for AirVideoServer License: GPL URL: http://inmethod.com/airvideo/ Source: http://inmethod.com/airvideo/download/ffmpeg-for-2.4 .5-beta7.tar.bz2 Source1: airvideoserver.conf Source2: AirVideoServer Source3: AirVideoServerLinux.jar BuildRoot: %(_tmppath)/%(name)-for-%(version)-%(release)

    %description Utility and library for encoding H264/AVC video streams for AirVideoServer.

    The %prep section is responsible for the commands necessary to start the build, so that I don’t have to worry about renaming the directory for the format - I just use the -n switch to indicate where the unpacked sources are located

    %prep %setup -n /home/rpmbuild/rpmbuild/BUILD/ffmpeg/

    The %build section is responsible for directly assembling the source; you can change the keys to the ones you need, as with normal assembly and installation from sources:

    %build ./configure \ --prefix="%(_prefix)" \ --bindir="%(_bindir)" \ --libdir="%(_libdir)" \ --enable-pthreads \ --disable-shared \ --enable-static \ --enable-gpl \ --enable-libx264 \ --enable-libmp3lame

    The %install section contains commands for installing package files on the system; here we need to additionally specify where to install our config file, server and init script

    %install %(__rm) -rf %(buildroot) %(__make) install DESTDIR="%(buildroot)" mkdir -p $RPM_BUILD_ROOT/usr/local mkdir -p $RPM_BUILD_ROOT/usr/local/AirVideo/ install -m 644 %(SOURCE1) $RPM_BUILD_ROOT/usr/local/AirVideo/ install -m 644 %(SOURCE2) $RPM_BUILD_ROOT/etc/init.d install -m 644 %(SOURCE3) $RPM_BUILD_ROOT/usr/local/AirVideo/

    Let's clean up the garbage and run ldconfig

    %clean %(__rm) -rf %(buildroot) %post -p /sbin/ldconfig %postun -p /sbin/ldconfig

    The commands in the %files section specify lists of files and directories that, with the appropriate attributes, should be copied from the build tree into the rpm package and will then be copied to the target system when this package is installed.

    %files %defattr(-,root,root,-) %doc COPYING* CREDITS README* %(_bindir)/avconv %(_bindir)/avprobe %(_bindir)/avserver %(_bindir)/ffmpeg /usr/include/* /usr/lib64/* /usr/share/avconv/* /usr/local/AirVideo/airvideoserver.conf /etc/init.d/AirVideoServer /usr/local/AirVideo/AirVideoServerLinux.jar

    The %doc macro marks documentation files, copyrights and other things.
    With this our spec file is ready, now we need to run the assembly itself

    Rpmbuild -bb ffmpeg/ffmpeg.spec

    Upon successful assembly of the package, after completion, in the RPMS/_architecture_/ directory we will have our package ffmpeg-2.4.5-beta7.x86_64.rpm which can now be uploaded and deployed on any machine.

    I hope this small manual will help you assemble your own packages for installation, with your own configuration files, which will make your life easier later.

    Many of our projects use open-source libraries. When development is carried out for one specific platform, there is no point in collecting the same libraries from source every time a new developer joins the project. In addition, installing libraries a la make && sudo make install is considered bad form, since the system is clogged with “orphan” files that have no information in the RPM package manager database.

    As a solution, it is proposed to assemble RPM packages from compiled libraries and store them in a single repository accessible to all developers. Below are instructions and some tips for assembling the packages.

    The instructions will be based on the example of Red Hat Enterprise Linux 6, but with minor changes it can be adapted for other distributions. For example, we will build a package from the zeromq library.

    Before building the package

    The first thing you need to do before assembling is to make sure that the package you need has not been assembled by someone else before you. Often resources like rpmfind.net and rpm.pbone.net can find what you need. But if the required version of the library is not found or there is no assembly for your platform, then you will have to build the package yourself.

    rpmbuild

    Packages are assembled using the utility rpmbuild. Before using it, you must configure the build environment. Let's create the necessary directory tree, for example, in the ~/rpmbuild directory:

    $ mkdir ~/rpmbuild $ mkdir ~/rpmbuild/(BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS)

    We create a configuration file for the rpmbuild utility so that it knows where the created directory tree is located:

    $ echo "%_topdir %(echo $HOME)/rpmbuild" >~/.rpmmacros

    rpmbuild on startup it will look for package files in the ~/rpmbuild/BUILDROOT/ directory<имя_пакета>. Let's figure out what RPM packages are called, using zeromq as an example:

    zeromq-3.2.4-1.rhel6.x86_64.rpm

    • zeromq - actually, the name of the packaged software;
    • 3.2.4 - software version;
    • 1.rhel6 - package build number (release number) - how many times this software version has been compiled into an rpm package. The rhel6 or el6 suffix is ​​usually used by packages for Red Hat Enterprise Linux 6;
    • x86_64 - processor architecture for which the software is compiled.

    Note the characters separating the package name fields. They should be exactly as in the example.

    So, create a directory for zeromq in BUILDROOT:

    $ mkdir ~/rpmbuild/BUILDROOT/zeromq-3.2.4-1.rhel6.x86_64

    Building the library

    Of course, before building the binary package, you need to compile the library itself. If the library uses the GNU Autotools build system, this is usually done with the commands:

    $ ./configure $ make

    Now we install the library in the directory we created in BUILDROOT:

    $ make install DESTDIR="$HOME/rpmbuild/BUILDROOT/zeromq-3.2.4-1.rhel6.x86_64"

    The DESTDIR parameter is not always processed in makefiles. For example, qmake generates makefiles that ignore this option. If the library uses a build system other than GNU Autotools, then read the corresponding manual to see what parameters need to be passed during the build to install the library in the specified directory.

    spec file for building the package

    In addition to the archived file tree, RPM packages store metainformation about the package. When building, it must be specified in the spec file, which is located in the ~/rpmbuild/SPECS folder. Let's look at an example zmq.spec file for the zeromq library:

    Name: zeromq Version: 3.2.4 Release: 1.rhel6 Summary: Software library for fast, message-based applications Packager: My organization Group: System Environment/libraries License: LGPLv3+ with exceptions %description The 0MQ lightweight messaging kernel is a library which extends the standard socket interfaces with features traditionally provided by specialized messaging middle-ware products. 0MQ sockets provide an abstraction of asynchronous message queues, multiple messaging patterns, message filtering (subscriptions), seamless access to multiple transport protocols and more. This package contains the ZeroMQ shared library for versions 3.x. %post /sbin/ldconfig %postun /sbin/ldconfig %files %defattr(-,root,root) /usr/lib64/libzmq.so.3 /usr/lib64/libzmq.so.3.0.0 %package devel Summary: Development files for zeromq3 Group: Development/Libraries Requires: %(name) = %(version)-%(release) %description devel The zeromq3-devel package contains libraries and header files for developing applications that use zeromq3 3.x. %files devel %defattr(-,root,root) /usr/include /usr/share /usr/lib64/pkgconfig /usr/lib64/libzmq.so /usr/lib64/libzmq.a /usr/lib64/libzmq.la

    At the beginning of the file, a minimum set of fields with information about the package is indicated. From the values ​​of the first three fields ( Name, Version, Release) is formed by the package name, so it is important that the correct values ​​are specified there. If the values ​​do not match the name of the directory with the file tree of the package being built, rpmbuild will throw an error. Field License is also required - without it, rpmbuild will refuse to build the package.

    Section purpose %description obviously. Sections %post And %postun contain scripts that are executed after installing package files on the system and after removing package files from the system, respectively. This is useful if the package installs dynamic libraries (.so) in non-standard directories (i.e. not /lib, /usr/lib, /lib64 or /usr/lib64). In this case, the package must provide a configuration file for ldconfig and install it in /etc/ld.so.conf.d. Team ldconfig updates the dynamic loader cache, adding to it all the libraries found in the directories specified in the configuration files.

    In section %files specifies a list of files that are packaged into rpm. Directive %defattr specifies default file attributes in the format:

    %defattr(, , ,

    )

    specified in octal, for example, "644" for rw-r--r--. Attribute

    may be omitted. Instead of attributes that should not change for installed files, you can specify a hyphen. Directories specified in the section %files, will be included in the package along with all their contents.

    Next comes the most interesting part. There are actually two types of library RPM packages. Some contain the dynamic library files themselves, which are necessary for the operation of programs that are linked with these libraries. For example, the package zeromq-3.2.4-1.rhel6.x86_64.rpm provides only two files: /usr/lib64/libzmq.so.3.0.0 and a symbolic link to it, /usr/lib64/libzmq.so.3. Another type of package contains files needed to develop applications using the provided library. The suffix "-devel" is added to the name of such packages, for example, zeromq-devel-3.2.4-1.el6.x86_64.rpm. These packages typically contain C/C++ headers, documentation, static libraries (.a), and are dependent on the first type of package.

    In the above spec file the directive %package allows you to build a “child” package with one run of rpmbuild. The header field values ​​of a child package are inherited from the parent, but they can be overridden. Field Requires specifies an additional dependency on the parent package. Note that section %files The zeromq-devel package contains the file /usr/lib64/libzmq.so. This is a symbolic link to the actual dynamic library file. It is required by the ld linker when building an application using the library because it looks for dynamic library files starting with "lib" and ending with ".so".

    Assembly

    There are two things to keep in mind before assembly.
    First, if the package is successfully built, rpmbuild will clean out the BUILDROOT directory. So, just in case, make a backup copy of the packaged files.
    Second: never build packages with root privileges. explains why this cannot be done.

    Now everything is ready to build the package. Run rpmbuild:

    $ cd ~/rpmbuild/SPECS $ rpmbuild -bb zmq.spec

    The -bb parameter means “build binary”, that is, build a binary package. In addition to binary packages, there are also source code packages, but they are not discussed here.

    If successful, the resulting rpm package will be saved in the RPMS folder.

    If you don’t know what to write in the header fields of the spec file for the library being packaged, you can take the RPM package for another distribution from the above resources and see what they write there:

    $ rpm -qip package.rpm

    Here "q" means "query mode", "i" - getting information about the package, "p" - getting information about the specified package file (without this option, information about the package installed on the system will be obtained, if installed) .

    If you don't know which files belong to the devel package and which belong to the library package, but you have both packages for another distribution, you can unpack the tree of files provided by this package into the current directory:

    $ rpm2cpio package.rpm | cpio -di

    The rpm2cpio utility writes to standard output the cpio archive stored in the rpm package; The cpio utility unpacks an archive received from standard input. The "i" parameter turns on the unpacking mode, and "d" creates the necessary directories.

    You can see what files a package provides without unpacking it, using the “f” option:

    $ rpm -qfp package.rpm

    Total

    By packaging used libraries in RPM, you can save your colleagues from having to download the sources of the required version of the library each time, save them from problems during assembly (if, for example, you need to apply some kind of patch to the downloaded library sources) and generally unify the process of adding a library to the project. The article does not describe all the intricacies of assembling packages and writing spec files (such as separating configuration files, documentation, etc.), but for assembling library packages this, by and large, is not necessary.

    Attention! Actions in paragraphs 1 and 4 of these instructions are performed with administrative rights (root)!

    1. Install the necessary packages for the build process

    # apt-get install rpm-build

    2. Install the src.rpm package of the required software that needs to be assembled

    We find and download the src.rpm package of the required software that we will build, and install it (from the user!):

    $ rpm -i package_name_version.src.rpm

    In this case, the sources (source code) of the package will be located in ~/RPM/SOURCES , and the spec - in ~/RPM/SPECS .
    Availability of software source code and spec, i.e. description of the build process, is a necessary and sufficient condition for building an rpm package (or rebuilding, for example, a package from a newer branch for an older one).

    3. Package assembly

    Let's start assembling, this is done with the command:

    $ rpm -ba --target (i586|x86_64) ~/RPM/SPECS/spec_name of the_required_package_for_build.spec

    In this case, it is necessary to expand the brackets depending on the architecture for which the package is built.

    The compiled packages will be located in ~/RPM/RPMS .

    Note:

    You can rebuild the package without installing (unpacking) it like this:

    $ rpmbuild --rebuild --target (i586/x86_64) package_name_with_version.src.rpm

    In this case, it is also necessary to expand the brackets depending on the architecture for which the package is built.

    Note: As for processors not belonging to the x86_64 family, the indication “--target i586” itself is optional (the build will work without it, but the compiler will build a package precisely tailored to your type of processor and the name of the package will differ from the name of the packages brunches, for example, xxx.athlon.rpm or xxx.pentium4.rpm). The absence of the "--target i586" parameter during assembly does not at all guarantee that the package compiled in this way can be installed on another computer with a different processor. If the assembly is performed under a 64-bit system (on a 64-bit processor with a 64-bit system installed), then the “--target x86_64” key loses its meaning and is not necessary to set it at all.

    Note: If rpm complains about not found macros something like this: “error: Macro %groupadd not found” or “error: Macro %license not found”, then the installation of one of the rpm-build-* packages on the system should help in the further assembly of the package, which, in fact, , is an additional dependency for building (rebuilding) your package and is responsible for assigning the required values ​​to these very unfound macros.

    4. Installing assembly dependencies

    If you have an srpm package that you need to install dependencies to build, you can do this by running the following command:

    # apt-get build-dep package_name_version.src.rpm

    If there is no srpm package and there is a separate spec and source code, then almost 100% of the build will not work right away - at the very beginning of the output, the console will show packages that must be installed on the system before the build can go further. You install them (these assembly dependencies displayed in the console)

    # apt-get install package1 package2 package3 ...

    and then repeat the assembly (return to step 3).

    5. Automatic search for dependencies for a newly built package

    If you are building a new package, and not rebuilding an existing srpm, then the utility will serve you well as part of the design (search and registration) of the necessary dependencies in the spec buildreq from the rpm-utils package:

    $ buildreq spec_file_name.spec