In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to write the spec file of RPM. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Typically, the source code package for Linux also provides a file called {software name}. Spec, the spec file. If a spec file is provided, the source code can also be compiled directly into a RPM package.
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 1: 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 to 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
On "how to write RPM spec file" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out 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.