Run RPM.

Source: Internet
Author: User
Article Title: everyone is doing RPM. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
○ Preface
-= -=-
Creating your own operating system environment should be the dream of many Linux players. Nowadays, with the Red Hat Linux and RPM systems, the process of achieving your dreams does not seem so painful. If you are enjoying the warmth of planting trees and then enjoying the coolness of others, I hope you can share good things with friends 」? We look forward to the opportunity for this article to provide guidance functions to help more Linux on the Internet better and contribute together.
  
I. preparations
-= -=-
What is RPM?
If you do not know, or do not know, what is RPM, sorry, you should finish the following homework first:
1. I have read the RPM-HOWTO's introduction to RPM, and the translated RPM-HOWTO article can be obtained by The http://www.linux.org.tw/CLDP/RPM-HOWTO.html. Read the first three chapters.
2. the actual installation of Red Hat Linux is the best operating platform for the RPM system, and allows you to see the overall operation of the entire RPM.
  
Note: If you are already familiar with the dpkg system of Debian Linux, you can rest assured that RPM should be easier than dpkg and be familiar with Debian Linux, I believe it has already fully covered the above basic effort.
With your weapons, we are ready to go on the road. Therefore, you must check the following "portable weapons". if you are missing any of them, sorry, please make up the following:
1. at least one handy editor for programming.
2. familiar with the bash/ksh script syntax. its importance is really unspeakable.
3. familiar with tools such as grep, sed, awk, install, ldconfig, etc.
4. familiar with four basic functions of rpm program: install, upgrade, query, verify
5. Basic C language compilation skills, including at least Makefile writing concepts, diff, and patch usage.
  
Note: I cannot say exactly how many C language skills I should have. Strictly speaking, it is also a program idiot. So, depending on the situation. If you want to create a package file with high difficulty, the superb compilation and debugging skills are required. if the author of the original code has already prepared a perfect Makefile, directly make, make install, it is not a waste of effort. Some may be specialized in languages such as Perl, Python, Tk/Tcl, and Java. this is also a good thing, especially when creating package archives related to the "alternative language, you should feel more cordial. However, once again, shell script is the basic language of RPM, while C is the normal language of RPM. although Perl, Python, Tk/Tcl, and Java can solve almost all problems, but considering portability and program size, you have to think twice. In addition, don't underestimate the power of small tools such as grep, sed, and awk. they should be able to meet all RPM production needs.
  
II. References
-= -=-
Maybe the RPM-HOWTO should be the first document to be referenced, but it is suggested that you simply get the basic concept, or if you can read this document from scratch, october can also understand the content of the RPM-HOWTO, as I have tried in this article to repeat the key points of the RPM-HOWTO by imagining "a way that you can understand suction education. Of course, you can also complain that the English version of the RPM-HOWTO translated too bad, resulting in smart as you have to see did not understand. This statement, in the next really can experience, because the RPM-HOWTO is also translated by the writing below, to be honest, after the translation of me, do not dare to say that understand RPM.
Maximum RPM is the best reference for this book. it should be the most detailed and complete RPM book, which helps readers understand the RPM system. The book was originally published by Red Hat and written by Ed Bailey. he is enthusiastic and generous, with additional PostScript files available for download on the Internet, and let's offer our highest respect. If the entire PostScript file is printed out, a total of four hundred pages are collected. if you are interested in this article, you can print it. Otherwise, you can use ghostscript to read it online. If you want to buy books directly, you can go to http://www.redhat.com/query. Http: // www.rpm.org/And the RPM mailing list, all insiders know :-)
  
3. create an RPM process outline
-=-
The basic steps for creating an RPM package file are as follows:
1. confirm that your/etc/rpmrc meets the system requirements and complete the settings.
2. retrieve the source code to be built.
3. perform the required source file patch action so that we can build the entire program smoothly.
4. write a spec file for the package file.
5. confirm that each file is in the correct directory.
6. use RPM to build the entire package file.
  
/Etc/rpmrc file
RPM system control file. the system-wide configuration file is/usr/lib/rpmrc, while the customized configuration file is/etc/rpmrc. Generally, the content of the/usr/lib/rpmrc file does not need to be changed at all. if you have any new settings, write them in/etc/rpmrc, because it will "overwrite" the set value of/usr/lib/rpmrc. The following is an example of my/etc/rpmrc file:
#-=- = -#
#/Etc/rpmrc #
##
# Local mizmizations are made to override/usr/lib/rpmrc .#
#-=- = -#
Distribution: Manhattan
Require_distribution: 1
Vendor: twLUG
Require_vendor: 1
Packager: Penelope Marr
  
Additional important information
There are actually a lot of important details about the RPM Package File creation process, which must be kept in mind. please refer to [Building RPMs] in the RPM-HOWTO first.
  
4. a simple example
-=-
Let's start with a helloworld RPM Package File, which is easy to use. You can perform self-testing based on the entire example because they are small and simple and should not affect your system.
  
Our "pure" source
Hypothesis:
This helloworld-1.0-1.tgz file has only two files, one is README, the content is as follows (in fact the content is not important): Simple Example for RPM Package Building DEMO. one is helloworld. c. The content is as follows (it is easy to understand, but it is not important ):
Main ()
{
Printf ("Hello, World \ n ");
}
Okay, you must put this tgz file under/usr/src/redhat/SOURCES.
  
Write spec files
Helloworld-1.0-1.spec must be written under/usr/src/redhat/SPECS,
Content example:
Summary: Simple Example for RPM Building DEMO.
Name: helloworld
Version: 1.0
Release: 1
Copyright: Open Source
Group: Extensions/Chinese
Source: helloworld-1.0-1.tgz
Packager: Penelope Marr
% Description
This package is used as a demo for RPM building only.
% Changelog
* Thu Jul 16 1998 Penelope Marr
-Build for the first time.
% Prep
% Setup-c
% Build
Make helloworld
% Install
Install-m 755 helloworld/usr/local/bin/helloworld
% Files
% Doc README
/Usr/local/bin/helloworld
  
□Start rpm-ba...
Example # cd/usr/src/redhat/SPECS
Example # rpm-ba helloworld-1.0-1.spec 1>/tmp/out 2>/tmp/err
  
This method makes it easier for us to learn relevant information.
  
5. create a package file for "installation anywhere"
-=-
The so-called "relocatable package" is called "package files that can be installed everywhere". for details, see chapter 15th of Maximum RPM. With the Prefix setting function added, this type of package file is more flexible and practical, but it also increases the difficulty of creating the package file.
Content example:
Summary: Simple Example for RPM Building DEMO.
Name: helloworld
Version: 1.0
Release: 2
Copyright: Open Source
Group: Extensions/Chinese
Source: helloworld-1.0-1.tgz
Packager: Penelope Marr
Prefix:/usr/local
% Description
This package is used as a demo for RPM building only.
% Changelog
* Fri Jul 17 1998 Penelope Marr
-Make the relocatable package.
* Thu Jul 16 1998 Penelope Marr
-Build for the first time.
% Prep
% Setup-c
% Build
Make helloworld
% Install
Install-m 755 helloworld/usr/local/bin/helloworld
% Files
% Doc README
/Usr/local/bin/helloworld
  
□Start rpm-ba...
Example # cd/usr/src/redhat/SPECS
Example # rpm-ba helloworld-1.0-1.spec 1>/tmp/out 2>/tmp/err
Example # rpm-ba helloworld-1.0-1.spec 1>/tmp/out 2>/tmp/err
When installing the rpm file, you can add the -- prefix parameter so that it can be installed to other directories we want.
Example # rpm-Uvh-v -- prefix/root helloworld-1.0-1.i386.rpm
  
6. advanced skills
-= -=-
"Imitation" is very important. in particular, imitating others' classical works can often gain a lot of experience and inspire a lot. SRPM files are the best tool to learn and imitate. more than one thousand eight hundred SRPM files are collected next time. from other people's spec files, we can indeed clear many blind spots.
We have introduced only two simple examples to introduce the RPM production process, which is not difficult. Other advanced techniques, such as "other useful spec labels
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.