I have 3 tarball files like aa I need to build all of them with different configuration options like for the first tarball the configuration option is:.
I know for a single source file in tar we can specify. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 4 years, 5 months ago. Active 4 years, 5 months ago. I'm just another Fedora contributor. Great article, by the way. Is there any chance that you can put the previous articles and this one together as a downloadable PDF file.
Your expository is most informative. Fedora Linux 35 is available now. Read the release announcement for all the details. Email Address. The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site.
The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions. We need rpmdev-setuptree to setup rpmbuild directory structure to create rpm package. There are some other pre-requisite rpms which are required to create rpm package. Some of them are:. Now later when we build rpm from source code, it is possible we may get any more dependency error, so we will install any additional rpms based on the requirement.
To create rpm package using rpmbuild , we need a proper directory structure. Run the rpmdev-setuptree utility from the location where you wish to setup the rpmbuild structure to create rpm package. I will execute under root's home folder. In this example, we already have an rpm, but we would like to modify the rpm content and build rpm from the source code with our modifications. First we must access the source rpm which we have to modify to create rpm package. You can get the source rpm depending upon your environment and vendor.
I will take a basic example of httpd rpm, and the src rpm was available at CentOS project repository. Next we will extract the source code from the rpm. Next extract the httpd This contains all the source code for httpd package.
This is good for those practicing a DevOps workflow as it allows for the team writing the software to maintain their normal Branching Workflow.
Tito will then allow for the software to be incrementally packaged, built in an automated fashion, and still provide a native installation experience for RPM based systems.
Tito operates based on git tags and will manage tags for you if you elect to allow it, but can optionally operate under whatever tagging scheme you prefer as this functionality is configurable. As we can see here, the spec file is at the root of the git repository and there is a rel-eng directory in the repository which is used by tito for general book keeping, configuration, and various advanced topics like custom tito modules.
We can see in the directory layout that there is a sub-directory entitled packages which will store a file per package that tito manages in the repository as you can have many RPMs in a single git repository and tito will handle that just fine.
In this scenario however, we see only a single package listing and it should be noted that it matches the name of our spec file. All of this is setup by the command tito init when the developers of dist-git first initialized their git repo to be managed by tito. We could then use the output as the installation point for some other component in the pipeline.
Below is a simple example of commands that could accomplish this and they could be adapted to other environments. Note that the final command would need to be run with either sudo or root permissions and that much of the output has been omitted for brevity as the dependency list is quite long.
This concludes our simple example of how to use tito but it has many amazing features for traditional Systems Administrators, RPM Packagers, and DevOps Practitioners alike. I would highly recommend consulting the upstream documentation found at the tito GitHub site for more information on how to quickly get started using it for your project as well as various advanced features it offers.
The build system is then configured to pull the items that are listed as SourceX entries in the spec files in from this look-aside-cache, while the spec and patches remain in a version control system. There is also a helper command line tool to assist in this. In an effort to not duplicate documentation, for more information on how to setup a system such as this please refer to the upstream dist-git docs. You can define your own macros.
Below is an excerpt from the RPM Official Documentation , which provides a comprehensive reference on macros capabilities. A parameterized macro contains an opts field. The shell output is set with set -x enabled. DhddsG use the --debug option, since rpmbuild deletes temporary files after successful build. This displays the setup of environment variables, for example:. Only tar -xof is executed instead of tar -xvvof. This option has to be used as first.
For example, if the package name is cello , but the source code is archived in hello The -c option can be used if the source code tarball does not contain any subdirectories and after unpacking, files from an archive fill the current directory. The -c option creates the directory and steps into the archive expansion. An illustrative example:. Essentially, -D option means that following lines are not used:. The -T option disables expansion of the source code tarball by removing the following line from the script:.
Option -b which stands for before expands specific sources before entering the working directory. Option -a which stands for after expands those sources after entering.
Their arguments are source numbers from the spec file preamble. In this case use -a 1 , as we want to expand Source1 after entering the working directory:. But if the examples were in the separate cello This identifies the file listed as documentation and it will be installed and labeled as such by RPM.
This is often used not only for documentation about the software being packaged but also code examples and various items that should accompany documentation. In the event code examples are included, care should be taken to remove executable mode from the file.
Identifies that the path is a directory that should be owned by this RPM. This is important so that the RPM file manifest accurately knows what directories to clean up on uninstall. Specifies that the following file is a configuration file and therefore should not be overwritten or replaced on a package install or update if the file has been modified from the original installation checksum.
In the event that there is a change, the file will be created with. Your system has many built-in RPM Macros and the fastest way to view them all is to simply run the rpm --showrc command. Note that this will contain a lot of output so it is often used in combination with a pipe to grep. Different distributions will supply different sets of recommended RPM Macros based on the language implementation of the software being packaged or the specific guidelines of the distribution in question.
These are often provided as RPM Packages themselves and can be installed with the distribution package manager, such as yum or dnf. One primary example of this is the Fedora Packaging Guidelines section pertaining specifically to Application Specific Guidelines which at the time of this writing has over 60 different sets of guidelines along with associated RPM Macro sets for subject matter specific RPM Packaging.
One example of this kind of RPMs would be for Python version 2. The above output displays the raw RPM Macro definitions, but we are likely more interested in what these will evaluate to which we can do with rpm --eval in order to determine what they do as well as how they may be helpful to us when packaging RPMs. Any changes you make will affect every build on your machine. You can create this directory, including all subdirectories using the rpmdev-setuptree utility.
By default, it is set to -jX , where X is a number of cores. If you alter the number of cores, you can speed up or slow down a build of packages.
In this section we will cover the most common of these such as Epoch, Scriptlets, and Triggers. First on the list is Epoch , epoch is a way to define weighted dependencies based on version numbers. This was not covered in the SPEC File section of this guide because it is almost always a bad idea to introduce an Epoch value as it will skew what you would normally otherwise expect RPM to do when comparing versions of packages.
For example if a package foobar with Epoch: 1 and Version: 1. This approach is generally only used when absolutely necessary as a last resort to resolve an upgrade ordering issue which can come up as a side effect of upstream software changing versioning number schemes or versions incorporating alphabetical characters that can not always be compared reliably based on encoding.
In RPM Packages, there are a series of directives that can be used to inflict necessary or desired change on a system during install time of the RPM. These are called scriptlets. At install time we will need to notify systemd that there is a new unit so that the system administrator can run a command similar to systemctl start foo.
Scriptlet that is executed just before the package is installed on the target system. Scriptlet that is executed just after the package is installed on the target system.
Scriptlet that is executed just before the package is uninstalled from the target system. Scriptlet that is executed just after the package is uninstalled from the target system. It is also common for RPM Macros to exist for this function. In our previous example we discussed systemd needing to be notified about a new unit file , this is easily handled by the systemd scriptlet macros as we can see from the below example output.
More information on this can be found in the Fedora systemd Packaging Guidelines. Another item that provides even more fine grained control over the RPM Transaction as a whole is what is known as triggers. These are effectively the same thing as a scriptlet but are executed in a very specific order of operations during the RPM install or upgrade transaction allowing for a more fine grained control over the entire process.
An illustrative example is a script, which prints out a message after the installation of pello. The conditional checks whether the operating system is RHEL6.
This conditional handles support for the rubypick tool. If the operating system is Fedora version 19 or newer, rubypick is supported. This conditional handles definition of the macros. These variants are commonly used, so they have their own macros. It is followed by one or more architecture specifiers, each separated by commas or whitespace.
It can be followed by one or more operating system names. A new command, rpmkeys , used for keyring import and signature verification has been added. The posix. Pre-transaction and post-transaction scriptlet dependencies can now be correctly expressed with Requires pretrans and Requires posttrans scriptlets.
The OrderWithRequires tag for supplying additional ordering hints has been added. The tag follows Requires tag syntax, but does not generate actual dependencies. The ordering hints are treated as if they were Requires when calculating the transaction order, only if the involved packages are present in the same transaction. The automatic dependency generator has been rewritten into extensible and customizable rule based system with built-in filtering.
Some of these are advanced and extend far beyond the introductory material included in this guide. Software Collections - SoftwareCollections. How to prepare source code for packaging into an RPM. How to package source code into an RPM.
Advanced packaging scenarios. Document Conventions The document uses the following conventions:. Contributing to this guide You can contribute to this guide by submitting an issue or a pull request on the GitHub repository. Prerequisites To follow this tutorial, you need the packages mentioned below.
Install, reinstall, remove, upgrade and verify packages Users can use standard package management tools for example Yum or PackageKit to install, reinstall, remove, upgrade and verify your RPM packages. Use a database of installed packages to query and verify packages Because RPM maintains a database of installed packages and their files, users can easily query and verify packages on their system.
Package pristine software sources into source and binary packages RPM allows you to take pristine software sources and package them into source and binary packages for your users. Add packages to Yum repositories You can add your package to a Yum repository that enables clients to easily find and deploy your software. Digitally sign your packages Using a GPG signing key, you can digitally sign your package so that users are able to verify the authenticity of the package.
Preparing Software for Packaging This chapter is about source code and creating software, which are a necessary background for an RPM Packager. What is Source Code? Hello World written in bash :. Hello World written in Python :. How Programs Are Made There are many methods by which human-readable source code becomes machine code - instructions the computer follows to actually execute the program. The program is natively compiled. The program is interpreted by raw interpreting.
The program is interpreted by byte compiling. Natively Compiled Code Natively compiled software is software written in a programming language that compiles to machine code, with a resulting binary executable file. Interpreted Code Some programming languages, such as bash or Python , do not compile to machine code. Raw-interpreted programs Raw-interpreted language programs do not need to be compiled at all, they are directly executed by the interpreter.
Byte-compiled programs Byte-compiled languages need to be compiled into byte code, which is then executed by the language virtual machine. Building Software from Source This section explains building software from its source code. Natively Compiled Code In this example, you will build the cello. That is all. You have built and ran natively compiled software from source code.
Automated Building Instead of building the source code manually, you can automate the building. You have now compiled a program both manually and using a build tool. Interpreted Code The next two examples showcase byte-compiling a program written in Python and raw-interpreting a program written in bash.
Byte-Compiled Code In this example, you will compile the pello. Raw Interpreted Code In this example, you will raw-interpret the bello program written in the bash shell built-in language. Patching Software A patch is source code that updates other source code. You have created a patch, patched a program, built the patched program, and run it.
Using the install command Sometimes using build automation tooling such as GNU make is not optimal - for example, if the packaged program is simple and does not need extra overhead. Using the make install command A popular automated way to install built software to the system is to use the make install command.
You have installed a build artifact into a chosen location on the system. Preparing Source Code for Packaging Note. Putting Source Code into Tarball In the examples below, we put each of the three Hello World programs into a gzip -compressed tarball. What is an RPM? For more information on the above utilities, see their manual pages or help dialogs. See the Scriptlets and Triggers for advanced topics. RPM Macros An rpm macro is a straight text substitution that can be conditionally assigned based on the optional evaluation of a statement when certain built-in functionality is used.
On a RHEL 7. For more information on macros, see More on Macros. Populate the Name , Version , Release , and Summary directives: The Name was already specified as an argument to rpmdev-newspec. The Summary is a short, one-line explanation of what this software is. After your edits, the first section of the SPEC file should resemble:. Name: bello Version: 0.
Each change entry can contain multiple items - one for each change Each item starts on a new line. Each item begins with a - character.
0コメント