Linux Qt rpm package production

Posted by Thoughtless on Fri, 17 Dec 2021 04:32:48 +0100

preface

Linux system software generally has deb and The installation package in rpm format, that is, the Linux system uses the "red hat package manager" red hat package manager, which can be packaged rpm installation package, which is described below Production of rpm. For more information deb package production, click "Debian Packager" package manager.

Making tools

Before production, rpmbuild and rpmdevtools need to be installed in the system environment. You can install them with the following command:

yum install rpmbuild
yum install rpmdevtools

Make rpm package

Here is an rpm package for Qt development software. This function is a small program to display the current time after startup. (program code at the bottom)

  • 1. First, execute rpmdev setuptree to generate the rpmbuild directory file. If rpmdevtools is not installed,
    mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
[root@localhost ~]# rpmdev-setuptree 
[root@localhost ~]# ls ~/rpmbuild/
BUILD  RPMS  SOURCES  SPECS  SRPMS
[root@localhost ~]# 
  • 2. Rename the directory where the program is located as: xxx-xxx-1.0 0 (xxx xxx is the name and cannot be capitalized, 1.0.0 represents the version number);
  • 3. Execute the command tar - zcvf show-timer-1.0 0.tar.gz show-timer-1.0. 0 / compress the file to tar GZ compressed package;
  • 4. Move the compressed file to ~ / rpmbuild/SOURCES, that is, the rpmbuild/SOURCES of the current user
[root@localhost desktop]# tar -zcvf show-timer-1.0.0.tar.gz show-timer-1.0.0/
show-timer-1.0.0/
show-timer-1.0.0/showTime.pro.user
show-timer-1.0.0/showTime.desktop
show-timer-1.0.0/main.cpp
show-timer-1.0.0/widget.ui
show-timer-1.0.0/widget.cpp
show-timer-1.0.0/widget.h
show-timer-1.0.0/showTime.pro
show-timer-1.0.0/.qmake.stash
[root@localhost desktop]# mv show-timer-1.0.0.tar.gz ~/rpmbuild/SOURCES/
[root@localhost desktop]# ls ~/rpmbuild/SOURCES/
show-timer-1.0.0.tar.gz
[root@localhost desktop]# 
  • 5. cd to ~ / rpmbuild directory and execute rpmdev newspec - O specs / show timer spec generation spec file,
    Without the rpmdev newspec command, you can actually copy other packages spec to change
[root@localhost rpmbuild]# cd ~/rpmbuild/
[root@localhost rpmbuild]# rpmdev-newspec -o SPECS/show-timer.spec
SPECS/show-timer.spec created; type minimal, rpm version >= 4.15.
[root@localhost rpmbuild]# ls SPECS/
show-timer.spec
[root@localhost rpmbuild]# 
  • 6. Modification spec file
[root@localhost rpmbuild]#  vim ~/rpmbuild/SPECS/show-timer.spec
[root@localhost rpmbuild]#  cat ~/rpmbuild/SPECS/show-timer.spec
%global debug_package  %{nil}
#Package name
Name:           show-timer
#Version number
Version:        1.0.0
#The release number of the package
Release:        1%{?dist}
#summary
Summary:        show-timer
#The software authorization method is usually GPL (free software) or GPLv2,BSD
License:        LGPLv2+ and GPLv2+
#Source zip package name
Source0:        show-timer-1.0.0.tar.gz
#Build and compile dependencies. If you write too much, it's useless, but you write it, you have to install it. If you don't install it, you can't compile it;
#If you write less, you can still compile in the current compilation environment. If you don't, you can compile. So it's better to write clearly.
BuildRequires: qt5-qtbase-devel,qt5-qtx11extras-devel,qt5-qttools-devel,qt5-qtsvg-devel,lightdm-qt5-devel
#describe
%description
show-timer
#Perform before installation
%prep
%autosetup
#The commands to be executed to compile the software package. This section is generally composed of multiple make commands.
%build
qmake-qt5
make
#Defines the command that will be executed when the package is installed, similar to the make install command. Used to define the configuration work to be performed after the software installation is completed.
%install
mkdir -p  %{buildroot}/usr/bin/
install -m 755 showTime %{buildroot}/usr/bin/
mkdir -p  %{buildroot}/etc/xdg/autostart/
install -m 755 showTime.desktop %{buildroot}/etc/xdg/autostart/
mkdir -p  %{buildroot}/usr/share/applications/
install -m 755 showTime.desktop %{buildroot}/usr/share/applications/
#Define the files contained in the package
#%{u bindir} is the macro definition, here is / usr/bin;% {_sysconfidir} is / etc;% {_datadir} is / usr/share
#All macros can be found in / usr/lib/rpm/macros
%files
%{_bindir}/showTime
%{_sysconfdir}/xdg/autostart/showTime.desktop
%{_datadir}/applications/showTime.desktop
#Each software update can be recorded here and saved in the released software package for query.
%changelog
* Thu Dec 16 2021 kuangchunhua <kuangchunhua@kylinos.cn> - 1.0.0
- show-timer
[root@localhost rpmbuild]# 
  • 7. Execute rpmbuild - BA specs / show timer Spec generates rpm binary package and src source package
[root@localhost rpmbuild]# ls SRPMS
show-timer-1.0.0-1.src.rpm
[root@localhost rpmbuild]# ls RPMS/x86_64/
show-timer-1.0.0-1.x86_64.rpm
[root@localhost rpmbuild]# 

rpm common commands

  • rpm -ivh show-timer-1.0.0-1.x86_64.rpm installation

  • rpm -e show-timer-1.0.0-1.x86_64.rpm unloading

  • rpm -ivh show-timer-1.0.0-1.src.rpm will generate ~ / rpmbuild / spec / show timer spec,
    Then execute rpmbuild - BP ~ / rpmbuild / spec / show timer Spec will generate ~ / rpmbuild / build / show-timer-1.0 0
    Program source code

  • rpmbuild -bb ~/rpmbuild/SPEC/show-timer.spec only generates binary, i.e. show-timer-1.0 0-1. x86_ 64.rpm package

  • rpmbuild -bs ~/rpmbuild/SPEC/show-timer.spec only generates the source package, i.e. show-timer-1.0 0-1. src. RPM source package

  • rpmbuild -ba ~/rpmbuild/SPEC/show-timer.spec generates binary and source packages

rpmbuild directory introduction

[root@localhost rpmbuild]# ls
BUILD  BUILDROOT  RPMS  SOURCES  SPECS  SRPMS
[root@localhost rpmbuild]# 
  • BUILD: execute rpmbuild - BP ~ / rpmbuild / spec / show timer The source code generated by spec is in this directory

  • BUILDROOT: This is a temporary build directory, which can be ignored

  • RPMS: the generated binary package is in this directory

  • SOURCES: the compressed source package and other source files are in this directory

  • SPECS: . The spec configuration file is in this directory

  • SRPMS: the generated source package is in this directory

Introduction to spec file parameters

The description of the corresponding parameters is simply marked above. If you are interested, you can check it online RPM build - SPEC file parameter parsing

showTime. Introduction to desktop file parameters

kch@kch:~/showTime/show-timer-1.0.0$ cat showTime.desktop 
[Desktop Entry]
Name=showTimer
Name[zh_CN]=current time 
Comment=Displays the current time
Comment[zh_CN]=Displays the current time
Exec=/usr/bin/showTime
Terminal=false
Type=Application
NoDisplay=false              
kch@kch:~/showTime/show-timer-1.0.0$ 

Test program code

Link: https://pan.baidu.com/s/1bdSS8p1c5-XEhrhmV4-s5w Password: nnn9

Topics: Linux Qt RPM