RPM Production Guide (3)

Source: Internet
Author: User
Article title: RPM Production Guide (3 ). 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.
Author: Yu Yiqi and Zhao Jianli
  
To create a software package in RPM format, use the following command format:
Rpm-bX [create option 1 Create option 2...] description file 1 description file 2...
Note:-bX can be replaced with-tX, with different effects: when using-B, you must specify the package description file on the command line. when using-t, on the command line, you must specify not a package description file, but a package file in TAR format containing the description file (which must be compressed using gzip). when RPM is preparing a software package, the description file is automatically extracted from the package file, and a software package in RPM format is generated based on the package creation instructions. Note: This description file must be suffixed with. spec, which must have the Source field, and the Source program package defined in this field must be stored in the current directory. otherwise, RPM will return an error and exit.
Note that when-bX and X in-tX take different values, RPM will perform different operations :( The following examples all operate on the LZE's description file lze-6.0-2.spec, some use the pipeline technology and use the nl command to add a line number to the output for explanation)
1) X = p indicates that RPM executes the script program of the preprocessing segment (% prep) in the description file. This script is generally used to extract the source program package, patch the source program, and upgrade the source program.
# Rpm-bplze-6.0-2.spec2> & 1 | nl
1 Executing: % prep
2 + umask022
3 + cd/usr/src/dist/BUILD
4 + echo 'start executing the pre-processing script (prep'
5. the pre-processing script Program (prep) starts execution.
6 + cd/usr/src/dist/BUILD
Rm-rflze-6.0 7 +
8 +/bin/gzip-dc/usr/src/dist/SOURCES/lze-6.0-2.src.tgz
9 + tar-xvvf-
10drwxr-xr-xroot/root02001-11-0216: 02lze-6.0/
11-rw ------- root/root2462262001-11-0216: 00lze-6.0/lze. c
12-rw ------- root/root982492001-11-0216: 00lze-6.0/lzeime. wb. c
13-rw ------- root/root3399022001-11-0216: 00lze-6.0/lzeime. py. c
14-rw-r -- r -- root/root12832001-11-0216: 00lze-6.0/funkey. def
15-rwxr -- r -- root/root2502001-11-0216: 00lze-6.0/inputme. def
16-rw-r -- r -- root/root8132742001-11-0216: 00lze-6.0/wbzc. dat
17-rw ------- root/root4742001-11-0216: 02lze-6.0/makefile
18 + STATUS = 0
19 + '['0-ne0']'
Cdlze-6.0 20 +
21 ++/usr/bin/id-u
22 + '['0 = 0']'
23 +/bin/chown-Rhfroot.
24 ++/usr/bin/id-u
25 + '['0 = 0']'
26 +/bin/chgrp-Rhfroot.
27 +/bin/chmod-RF + rX, g-w, o-w.
28 + exit0
#
Note: The "Executing: % prep" shown in row 1st in this example indicates that RPM starts Executing the script program of the preprocessing segment. In this example, the rows starting with the plus sign (+) after the row number are the commands of the script program in the preprocessing segment, and other contents are the results output by the command execution. From the commands executed by the script program in the preprocessing segment, we can see what RPM is doing:
Row 3: Set the file creation mask;
Row 3: go to the default RPM compiling directory;
Row 4th: Echo string. this is the start of the script program in the pre-processing segment written by the user. line 2 and 3 are the instructions added by RPM;
Line 6-27: The commands extended by % setup and their execution results. you can see that RPM uses the gzip command to decompress the LZE source program package (line 8 ), then run the tar command to expand the source program package (line 1 ).
Row 28th: Exits normally. the returned value is 0.
2) X = l indicates RPM to check the file segment (% files) and check whether the file exists. If it does not exist, the RPM will return an error and exit.
# Rpm-bl-vvlze-6.0-2.spec | nl
1 Processingfiles: lze
2D: File0: 0100644root. root/etc/funkey. def
3D: File1: 0100644root. root/etc/inputme. def
4D: File2: 0100644root. root/usr/doc/lze-6.0-2/README
5 Filenotfound:/usr/doc/lze-6.0-2/LICENSE
6D: File3: 0100555root. root/usr/bin/lze
7D: File4: 01001_root. root/usr/bin/lzeime. py
8D: File5: 01001_root. root/usr/bin/lzeime. wb
9D: File6: 0100644root. root/etc/wbzc. dat
10 Provides: lze-edit
11 PreReq:/bin/sh
12 Requires:/bin/sh
#
Note: In this example, General option-vv is used to output debugging information (starting with line number and D:) during RPM check ).
From the above we can see that RPM checks all files in the file segment one by one, find the file shows its permissions, owner and group information, the results found that/usr/doc/lze-6.0-2.LICENSE file does not exist, therefore, an error is returned (File not found) (see Row 5th ). After checking the file, RPM also displays the features required by the description file (Provides) and required features (Requires) provided by LZE ).
3) when X = c, instruct RPM to execute the script programs of the pre-processing segments (% prep) and compilation segments (% build) in sequence. The script program in the compilation section is used to compile the source program connected to the software and generate executable programs. generally, a make command is sufficient. Because a programmer with good habits will write the Makefile (program maintenance file) so that other programmers can compile the software. If a software does not maintain files, you can either write a Makefile yourself or write the software compilation and connection commands in the compilation section.
4) when X = I, it indicates that RPM executes the script programs of the pre-processing segments (% prep), compilation segments (% build), and installation segments (% install) in sequence. The script program task of the installation section is to copy the compiled and connected execution programs to the appropriate directory (such as/bin,/usr/bin and other public execution directories) for packaging or execution. Generally, the command is make install.
5) when X = B, instruct RPM to execute the script programs of the pre-processing segments (% prep), compilation segments (% build), and installation segments (% install) in sequence, then, package the file according to the file list of the file segment (% files), generate the RPM execution package, and finally execute the cleanup Segment (% clean ).
# Rpm-bblze-6.0-2.spec2> & 1 | nl
1 Executing: % prep
2 + umask022
3 + cd/usr/src/dist/BUILD
4 + echo 'start executing the pre-processing script (prep'
5. the pre-processing script Program (prep) starts execution.
6 + cd/usr/src/dist/BUILD
Rm-rflze-6.0 7 +
8 + tar-xvvf-
9 +/bin/gzip-dc/usr/src/dist/SOURCES/lze-6.0-2.src.tgz
10drwxr-xr-xroot/root02001-11-0217: 04lze-6.0/
11-rw ------- root/root2462262001-11-0216: 00lze-6.0/lze. c
12-rw ------- root/root982492001-11-0216: 00lze-6.0/lzeime. wb. c
13-rw ------- root/root3399022001-11-0216: 00lze-6.0/lzeime. py. c
14-rw-r -- r -- root/root12832001-11-0216: 00lze-6.0/funkey. def
15-rwxr -- r -- root/root2502001-11-0216: 00lze-6.0/inputme. def
16-rw-r -- r -- root/root8132742001-11-0216: 00lze-6.0/wbzc. dat
17-rw ------- root/root4742001-11-0216: 02lze-6.0/makefile
18-rw-r -- r -- root/root12552001-11-0217: 04lze-6.0/getinputme. c
19 + STATUS = 0
20 + '['0-ne0']'
20 + cdlze-6.0
22 + +/usr/bin/id-u
23 + '['0 = 0']'
24 +/bin/chown-Rhfroot.
25 + +/usr/bin/id-u
26 + '['0 = 0']'
27 +/bin/chgrp-Rhfroot.
28 +/bin/chmod-RF + rX, g-w, o-w.
29 + exit0
30 Executing: % build
31 + umask022
32 + cd/usr/src/dist/BUILD
Cdlze-6.0 33 +
34 + echo 'compile and run the connection script program (build'
35. Compile the connection script program (build) and start execution.
36 + make
37cc-fwritable-strings-DUSE_AS_LZE-DFOR_LINUX-s-I/usr/zzz/src/include-DFOR_LZE_INPUTME-olze/usr/zzz/src/li-
38 bsrc/mycurses. clze. cgetinputme. c/usr/zzz/src/my.
39cc-DFOR_LINUX-s-I/usr/zzz/src/include-olzeime.wbgetinputme.clzeime.wb.c/usr/zzz/src/my.
40lzeime. wb. c: Infunction 'do _ service ':
41lzeime. wb. c: 1409: warning: passingarg5of 'bsearch' fromincompatiblepointertype
42cc-DFOR_LINUX-s-I/usr/zzz/src/include-olzeime.pygetinputme.clzeime.py.c/usr/zzz/src/my.
43 + exit0
44 Executing: % install
45 + umask022
46 + cd/usr/src/dist/BUILD
Cdlze-6.0 47 +
48 + echo 'Install the script program to start execution'
49 install the script program
50 + makeinstall
51installing...
52 done
53 + exit0
54 Processingfiles: lze
55 FindingProvides :( using/usr/lib/rpm/find-provides )...
56 FindingRequires :( using/usr/lib/rpm/find-requires )...
57 Provides: lze-edit
58 PreReq:/bin/sh
59 Requires:/bin/shld-linux.so.2libc.so.6libc.so.6 (GLIBC_2.0) libc. so.6 (GLIBC_2.1)
60 Wrote:/usr/src/dist/RPMS/i386/lze-6.0-2.i386.rpm
61 Executing: % clean
62 + umask022
63 + cd/usr/src/dist/BUILD
64 + cdlze-6.0
65 + echo 'after the package is created, the script program (clean) is started to execute'
66. after the package is created, the script program (clean) is cleaned and executed.
67 + exit0
#
Note: In this example, each row is interpreted as follows:
Row 1st: displays the pre-processing segments (% prep) started by RPM );
Line 2-29: The Command and result executed by the script program in the pre-processing segment (% prep). there is a plus sign (+) before the command, and there is no result before it. The LZE source program package is decompressed (gzip-dc) and the package is expanded (tar-xvvf), thus laying the foundation for compiling the source program;
Row 30th: RPM indicates the start of the compilation section (% build );
Line 31-43: The Command and result executed by the Compile (% build) script. The make Maintenance Command executed by the script program. The command executes the cc compilation program to compile and connect the LZE software;
Row 44th: RPM indicates that the installation section (% install) is started );
Line 45-53: The Command and result executed by the installation section (% install) script. This program runs the makeinstall command to copy files such as the LZE execution program to the system directory;
Row 54th: RPM Display: start to process the LZE File (content in the % files File segment );
Line 5-59: RPM uses the/usr/lib/rpm/find-provides program to find the features provided by LZE, use/usr/lib/rpm/find-requires to find the LZE dependency function to set the LZE dependency;
Row 60th: the LZE execution package, named lze-6.0-2.i386.rpm, in the/usr/src/dist/RPMS/i386 directory;
Row 61st: RPM: run the cleanup section (% clean) script. this section is used to clear temporary files;
Line 62-67: The Command and
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.