In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces how to write the spec file of RPM. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Here you take a closer look at the spec file, which contains instructions on how to build RPM.
Understand the source code
Before you start writing spec files, you need to know something about the software you want to package. Here, you are working on fpaste, which is a very simple software. It is written in Python and is a single-file script. When it releases a new version, it can be found on Pagure: https://pagure.io/releases/fpaste/fpaste-0.3.9.2.tar.gz.
As shown in the archive, the current version is 0.3.9.2. Download it so that you can view the contents of the archive:
$wget https://pagure.io/releases/fpaste/fpaste-0.3.9.2.tar.gz$ tar-tvf fpaste-0.3.9.2.tar.gzdrwxrwxr-x root/root 0 2018-07-25 02:58 fpaste-0.3.9.2/-rw-rw-r-- root/root 25 2018-07-25 02:58 fpaste-0.3.9.2/.gitignore-rw-rw-r-- root/root 3672 2018-07-25 02:58 fpaste-0.3.9.2/CHANGELOG-rw-rw-r-- root/root 35147 2018-07-25 02:58 fpaste-0.3.9.2/COPYING-rw-rw-r-- root/root 2018-07-25 02:58 fpaste-0.3.9.2/Makefile-rw-rw-r-- root/root 1656 2018-07-25 02:58 fpaste-0.3.9.2/README. Rst-rw-rw-r-- root/root 2018-07-25 02:58 fpaste-0.3.9.2/TODOdrwxrwxr-x root/root 0 2018-07-25 02:58 fpaste-0.3.9.2/docs/drwxrwxr-x root/root 0 2018-07-25 02:58 fpaste-0.3.9.2/docs/man/drwxrwxr-x root/root 0 2018-07-25 02:58 fpaste-0 .3.9.2 / docs/man/en/-rw-rw-r-- root/root 3867 2018-07-25 02:58 fpaste-0.3.9.2/docs/man/en/fpaste.1-rwxrwxr-x root/root 24884 2018-07-25 02:58 fpaste-0.3.9.2/fpastelrwxrwxrwx root/root 0 2018-07-25 02:58 fpaste-0.3.9.2/fpaste.py-> fpaste
The files you want to install are:
Fpaste.py: should be installed to / usr/bin/.
Docs/man/en/fpaste.1: manual, should be put in / usr/share/man/man1/.
COPYING: license text, should be put in / usr/share/license/fpaste/.
README.rst, TODO: other documents placed under / usr/share/doc/fpaste/.
The location where these files are installed depends on the file system hierarchy standard (FHS). For more information, you can read here: http://www.pathname.com/fhs/ or check the man pages of the Fedora system:
$man hier
Part one: what do you want to build?
Now that we know which files are in the source file and where they are to be stored, let's take a look at the spec file. You can view the complete file here: https://src.fedoraproject.org/rpms/fpaste/blob/master/f/fpaste.spec.
This is the first part of the spec file:
Name: fpasteVersion: 0.3.9.2Release: 3% {? dist} Summary: A simple tool for pasting info onto sticky notes instancesBuildArch: noarchLicense: GPLv3+URL: https://pagure.io/fpasteSource0: https://pagure.io/releases/fpaste/fpaste-0.3.9.2.tar.gzRequires: python3%descriptionIt is often useful to be able to easily paste text to the FedoraPastebin at http://paste.fedoraproject.org and this simple scriptwill do that and return the resulting URL so that people mayexamine the output. This can hopefully help folks who are forsome reason stuck without X, working remotely, or any otherreason they may be unable to paste something into the pastebin
Name, Version, and so on are called tags, and they are defined in RPM. This means that you can't just write some tags at random, RPM can't understand them! The labels that need to be noted are:
Source0: tell RPM the location of the source code archive file for the software.
Requires: lists the runtime dependencies of the software. RPM can automatically detect many dependencies, but in some cases you must specify them manually. A runtime dependency is a function (usually a software package) that must be available on the system for the package to work. This is how dnf detects whether other packages need to be pulled when installing this package.
BuildRequires: lists the build-time dependencies for this software. These must usually be identified manually and added to the spec file.
BuildArch: this software is built for this computer architecture. If you omit this tag, the software will be built for all supported architectures. The value noarch indicates that the software is architecture-independent (for example, fpaste, which is written entirely in Python).
This section provides general information about fpaste: what it is, what version is being made into RPM, its license, and so on. If you have installed fpaste and viewed its metadata, you can see the following information contained in the RPM:
$sudo dnf install fpaste$ rpm-qi fpasteName: fpasteVersion: 0.3.9.2Release: 2.fc30.
RPM automatically adds some other tags to represent what it knows. At this point, we have general information about the software for which we want to build RPM. Next, we start telling RPM what to do.
Part two: prepare to build
The next section of the spec file is the preparation section, represented by% prep:
% prep%autosetup
For fpaste, the only command here is% autosetup. This simply extracts the tar archive to a new folder and prepares you for the next part of the build phase. You can do more here, such as applying patches, modifying files for different purposes, and so on. If you have checked the contents of Python's source RPM, you will see a lot of patches there. All of these will be applied in this section.
Typically, everything in a spec file with a% prefix is a macro or tag that RPM interprets in a special way. These are usually braced, such as% {example}.
Part III: building software
The next part is where to build the software, represented by% build. Now, because fpaste is a simple pure Python script, there is no need to build. So, here is:
% build#nothing required
However, in general, you will use build commands here, such as:
Configure; make
The build part is usually the hardest part of the spec file, because this is where the software is built from the source code. This requires you to know which build system the tool uses, which may be one of many build systems: Autotools, CMake, Meson, Setuptools (for Python), and so on. Each has its own command and syntax style. You need to know enough about this to build the software correctly.
Part IV: installation files
After the software is built, you need to install it in the% install section:
% installmkdir-p% {buildroot}% {_ bindir} make install BINDIR=% {buildroot}% {_ bindir} MANDIR=% {buildroot}% {_ mandir}
When building RPM, RPM will not modify your system files. The risk of adding, deleting, or modifying files on a functioning system is too high. What if something goes wrong? As a result, RPM creates and works on a purpose-built file system. This is called buildroot. So, in buildroot, we create the / usr/bin directory represented by the macro% {_ bindir}, and then install the files into it using the Makefile provided.
At this point, we have installed the build version of fpaste in the specially built buildroot.
Part V: list all the files to be included in the RPM
The following part of the spec file is the file section:% files. Here, we tell RPM which files are included in the archive created from the spec file. The file part of fpaste is very simple:
% files% {_ bindir} /% {name}% doc README.rst TODO% {_ mandir} / man1/% {name} .1.gz% license COPYING
Note that we do not specify buildroot here. All of these paths are relative paths. The% doc and% license commands do a little more, they create the required folders and remember where the files must be placed.
RPM is very clever. For example, if you install files in the% install section but do not list them, it will remind you.
Part VI: record all changes in the change log
Fedora is a community-based project. Many contributors maintain or jointly maintain software packages. Therefore, it is imperative not to be confused by the changes made by the package. To ensure this, the last part of the spec file contains the change log% changelog:
Changelog* Thu Jul 25 2019 Fedora Release Engineering
< ...>-0.3.9.2-3-Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild* Thu Jan 31 2019 Fedora Release Engineering
< ...>-0.3.9.2-2-Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild* Tue Jul 24 2018 Ankur Sinha-0.3.9.2-1-Update to 0.3.9.2 * Fri Jul 13 2018 Fedora Release Engineering
< ...>-0.3.9.1-4-Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild* Wed Feb 07 2018 Fedora Release Engineering
< ..>-0.3.9.1-3-Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild* Sun Sep 10 2017 Vasiliy N. Glazov
< ...>-0.3.9.1-2-Cleanup spec* Fri Sep 08 2017 Ankur Sinha-0.3.9.1-1-Update to latest release- fixes rhbz 1489605.
Each change in the spec file must have a change log entry. As you can see here, although I updated the spec file as a maintainer, others have made changes as well. Clearly recording the changes will help everyone know the current state of the spec file. For all packages installed on the system, you can use rpm to view their change logs:
$rpm-Q-changelog fpaste
Build RPM
Now we are ready to build the RPM package. If you want to continue with the following commands, be sure to follow the steps in the previous article to set up your system to build RPM. We put the spec file of fpaste in ~ / rpmbuild/SPECS and the source code archive file in ~ / rpmbuild/SOURCES/. Now we can create the source RPM:
$cd ~ / rpmbuild/SPECS$ wget https://src.fedoraproject.org/rpms/fpaste/raw/master/f/fpaste.spec$ cd ~ / rpmbuild/SOURCES$ wget https://pagure.io/fpaste/archive/0.3.9.2/fpaste-0.3.9.2.tar.gz$ cd ~ / rpmbuild/SOURCES$ rpmbuild-bs fpaste.specWrote: / home/asinha/rpmbuild/SRPMS/fpaste-0.3.9.2-3.fc30.src.rpm
Let's look at the results:
$ls ~ / rpmbuild/SRPMS/fpaste*/home/asinha/rpmbuild/SRPMS/fpaste-0.3.9.2-3.fc30.src.rpm$ rpm-qpl ~ / rpmbuild/SRPMS/fpaste-0.3.9.2-3.fc30.src.rpmfpaste-0.3.9.2.tar.gzfpaste.spec
We see that the source RPM has been built. Let's build both the source RPM and the binary RPM:
$cd ~ / rpmbuild/SPECS$ rpmbuild-ba fpaste.spec.
RPM will show you the complete build output and explain its work in detail in each of the sections we saw earlier. This build log is very important. When the build does not go as expected, our packager will spend a lot of time traversing them to track the complete build path to find out what the problem is.
okay! The RPM you are going to install should be located in the following location:
$ls ~ / rpmbuild/RPMS/noarch/
Fpaste-0.3.9.2-3.fc30.noarch.rpm
Generalization
We have covered the basics of how to build RPM from spec files. This is by no means an exhaustive document. In fact, it is not a document at all. It's just trying to explain how it works behind the scenes. A brief review:
There are two types of RPM: source RPM and binary RPM.
Binary RPM contains the files that you want to install to use the software.
The source RPM contains the information needed to build the binary RPM: the complete source code, as well as instructions in the spec file on how to build the RPM.
The spec file contains several sections, each with its own purpose. Here, we have built RPM locally in the installed Fedora system. Although this is a basic process, the RPM we get from the repository is built on a dedicated server with strict configuration and methods to ensure correctness and security. This Fedora packaging process will be discussed in a future article.
Do you want to start building software packages and help the Fedora community maintain a lot of the software we offer? You can add package collection maintainers from here.
On how to write RPM spec file to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.