Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to package the software source code into RPM under CentOS

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to package the software source code into RPM under CentOS". In daily operation, I believe that many people have doubts about how to package the software source code into RPM under CentOS. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "how to package the software source code into RPM under CentOS". Next, please follow the editor to study!

Platform: centos6.5

The first is to build the environment:

The code is as follows:

[cpp] view plaincopyprint?

[root@localhost binbin] # yum install-y rpm-build

[cpp] view plaincopyprint?

[root@localhost binbin] # yum install redhat-rpm-config

Then there will be a rpmbuild directory under the / root directory

The code is as follows:

[cpp] view plaincopyprint?

[root@localhost rpmbuild] # pwd

/ root/rpmbuild

Enter this directory and there are five folders called BUILD BUILDROOT RPMS SOURCES SPECS SRPMS.

At first, it was all empty.

The code is as follows:

[html] view plaincopyprint?

[root@localhost rpmbuild] # ls

BUILD BUILDROOT RPMS SOURCES SPECS SRPMS

If you don't have these directories, you can add and create them manually.

The functions of these six directories are:

BUILD: the directory where rpmbuild compiles software

BUILDROOT:

RPMS: rpmbuild creates the directory where binary RPM is stored

SOURCES: the directory where the source code is stored

SPECS: the directory where the spec files are stored

SRPMS: rpmbuild creates the directory where souce RPM is stored

The first is to package the folder where the source code is placed. Here my folder is named login-1.0

The code is as follows:

[cpp] view plaincopyprint?

[root@localhost binbin] # tar zcvf login-1.0.tar.gz login-1.0

[root@localhost binbin] # ls

Login-1.0.tar.gz login-1.0

Copy login-1.0.tar.gz to the rpmbuild/SOUCES directory

The code is as follows:

[html] view plaincopyprint?

[root@localhost binbin] # cp login-1.0.tar.gz / root/rpmbuild/SOURCES

[root@localhost SOURCES] # ls

Login-1.0.tar.gz

At this point, go to the SPEC directory and write the SPEC file (this is a key step in packaging the rpm package)

The code is as follows:

[html] view plaincopyprint?

[root@localhost SOURCES] # cd.. / SPECS

[root@localhost SPECS] # touch login.spec

[root@localhost SPECS] # ls

Login.spec

[root@localhost SPECS] # vim login.spec

[html] view plaincopyprint?

# first name

Name: login

# version number

Version:1.0

# order of compilation

Release:1

# one-sentence introduction package (no more than 50 characters)

Summary: is test

Group: Applications/Communications

License: GPL

URL: www.ciis.com

# compressed package source files to be installed

Source: login-1.0.tar.gz

BuildRoot:% {_ tmppath} /% {name} -% {version}-root

% description

A test

# processing before building a package

% prep

#-decompress: here is mainly to extract the source code to the system directory during construction. Here is $RPM_BUILD_DIR.

# setup-c will generate a new directory with the same name as the compressed package when it is decompressed; setup-n dirname specifies a new directory to extract setup-Q and directly decompress it without generating a new directory

% setup-Q

#-Generation: here, the compilation is performed to generate binaries when the binary package is built

% build

Make

#-installation: install the current files to the system directory $RPM_BUILD_ROOT/ when building, and install the files to / root directory during binary installation

% install

# make install # it is convenient to use makefile's install

# No makefile, custom installation script

Rm-rf $RPM_BUILD_ROOT/*

Mkdir-p $RPM_BUILD_ROOT/usr/bin/

Cp-r $RPM_BUILD_DIR/% {name} -% {version} $RPM_BUILD_ROOT/usr/bin/

# follow-up of installation: processing script after installation of binary package

% post

Chmod + x / usr/bin/% {name} -% {version} / confAgent

Chmod + x / usr/bin/% {name} -% {version} / check_confAgent.sh

# after the uninstall is completed: the processing script after the uninstall of the binary package

% postun

Rm-fr / usr/bin/% {name} -% {version}

# cleanup: post-processing after the completion of the build package

% clean

Rm-rf $RPM_BUILD_ROOT

# File list: indicates which files should be installed on the system and the directory in which they are installed

# when building a package, the file or directory of the file list must be the same as the file or directory in the virtual directory RPM_BUILD_ROOT, otherwise it will

# prompt file not found

% files

% defattr (-, root,root)

/ usr/bin/% {name} -% {version}

% changelog

Save exit and execute the package command

The code is as follows:

[html] view plaincopyprint?

[root@localhost SPECS] # rpmbuild-ba login.spec

After that, there will be a corresponding rpm package in the RPMS/i686 directory. Here is login-1.0-1.i686.rpm.

The code is as follows:

[html] view plaincopyprint?

[root@localhost SPECS] # cd.. / RPMS/i686

[root@localhost i686] # pwd

/ root/rpmbuild/RPMS/i686

[root@localhost i686] # ls

Login-1.0-1.i686.rpm

Test installation

The code is as follows:

[html] view plaincopyprint?

[root@localhost binbin] # ls

Login-1.0-1.i686.rpm

[root@localhost binbin] # rpm-ivh login-1.0-1.i686.rpm

[root@localhost binbin] # / usr/bin/login-1.0/demo

You can run the client

At this point, the study on "how to package the software source code as RPM under CentOS" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report