Production (medium)
An RPM package description file can generate only one parent package or one sub-package, or one parent package and multiple sub-packages. By setting the sub-package option, you can use the standard "software name-Sub-package name" for the generated sub-package, or use your own name for the generated sub-package. A sub-package is usually packaged by merging the files according to their purpose or type. As the preceding Lze description file is simple, it includes all files in the parent package. We can also classify files into sub-packages, such as Lze-bin and Lze-config) and instructions (Lze-Doc ). We can also separate only one configuration file sub-package (Lze-config), and all other files are inserted into the parent package (Lze ). Detailed classification helps you manage software packages, avoid unnecessary installation, and upgrade.
To create a sub-software package, you must describe the following:
1.% package:
Use this section to create a sub-package. Its name is controlled by the sub-package option. The sub-package option is "[-N] sub-package name". If-N is not selected, the generated sub-package file is "software name-Sub-package name-version number-Release number. system. when "-n" is selected, the generated sub-package file is "sub-package name-version number-Release number. system. rpm ". The application format is:
% Package sub-package options |
2. Summary
This field must be under % package, which defines the sub-Package function introduction (in one sentence ). Format:
Summary: Introduction to sub-packages |
3. Group
This field must be under % package and define the Software category to which the sub-package belongs (for software categories, see <proficient in RPM 5-query> ). Format:
4.% description:
The content of this description section is a more detailed sub-Package function introduction, which is in the text form, the format is not required, can be any line break or segment. Format:
% Description sub-package options ... Introduces the sub-Package function... |
5.% files:
The content of this file segment is the list of files to be included in the sub-package. In the file list, a file occupies one row and multiple file modifiers can be used. (For details, see <7 proficient in rpm -- production (part I)>)
The application format of the segment name is:
% Files sub-package option [-f file name] |
Note: The sub-package option format used in the preceding % description and % files segments must be the same as that used in the % package. Otherwise, they do not define the same sub-package, an error will be reported during RPM check and exit. If % package name is defined, % description name must be used for the description segment name, and % files name must be used for the file segment name. % Description-n name cannot be used, and % files-n name cannot be used.
The sub-packages can also use seven optional functional segments, including % pre, % post, % preun, % postun, % triggerin, % triggerun, and % triggerpostun, because they can all use the sub-package options. When the sub-package option is used, their segment content is the script program used to manage the sub-software package. Note that the sub-package option format used by these segments must be the same as that used by the % package segment.
Use of conditional statements
In the software package description file, conditional statements can be flexibly used with no location restrictions. These statements are used to determine the current system and operating system. When the condition is true or false, RPM will reference the corresponding description.
Conditional statements have two formats:
1. {% ifarch, % ifnarch, % ifos, % ifnos} value 1 [value 2]... Description % Endif |
Note: {} is one of the mandatory content. [] is optional. Each value is separated by a space. % endif indicates that the condition statement ends.
The meaning of this statement is:
1) When % ifarch is used, it indicates that if the current system is a value of 1 or a value of 2..., the description is referenced.
2) When % ifnarch is used, it indicates that if the current system is not set to 1 or a value of 2..., the description is referenced.
3) When % ifos is used, the description is referenced if the current operating system is 1 or 2.
4) When % ifnos is used, it indicates that if the current operating system is not set to 1 or a value of 2..., the description is referenced.
If you want to add a file segment that is only applicable to the Linux System in the LZE package description file. lze and/etc/iSCSI. ime, you can add the following statement in the file segment:
% Ifarch iSCSI /Etc/iSCSI. lze /Etc/iSCSI. ime % Endif |
After this is done, if the current system is iSCSI, the RPM will add the two files during packaging.
2. {% ifarch, % ifnarch, % ifos, % ifnos} value 1 [value 2]... Description 1 % Else Description 2 % Endif |
Note: {} is one of the mandatory content. [] is optional. Values are separated by spaces. % else indicates another situation. % endif indicates that the condition statement ends.
The meaning of this statement is:
1) When % ifarch is used, it indicates that if the current system is a value of 1 or a value of 2..., the reference description content 1; otherwise, the reference description content 2.
2) When % ifnarch is used, it indicates that if the current system is not set to 1 or a value of 2..., the description 1 is referenced; otherwise, the description 2 is referenced.
3) When % ifos is used, it indicates that if the current operating system is set to 1 or a value of 2..., the description 1 is referenced; otherwise, the description 2 is referenced.
4) When % ifnos is used, it indicates that if the current operating system is not set to 1 or a value of 2..., the description 1 is referenced; otherwise, the description 2 is referenced.
To determine the LZE package Name based on the current operating system, you can use the following statement in the description file header to define the Name field:
% Ifos linux Name: lzeforlinux % Else% Ifos aix Name: lzeforaix % Else Name: lzeforothersys % Endif % Endif |
The nested Condition Statement is used in this example. It indicates that if the operating system is linux, the software name is lzeforlinux. If the operating system is aix, the software name is lzeforaix, if not, the software name is lzeforothersys.
How to use a macro (macros) in the description file)
1. What is a macro?
Anyone who has learned the C language knows That Macros are used to replace text. After macro names and macros are defined, all macro names in the file will be replaced by macros during preprocessing. Using macros can reduce the input amount of text and facilitate programmers. Using Macros in the software package description file is also based on this purpose, but this macro is different from the macro definition format in C language.
2. macro definition
The macro definition format in the description file is:
Note: [] is optional. The macro name can contain letters, numbers, and underscores (_), and the minimum length is 3. Opts is one or more options, and each option is not separated. The option is in the form required by the getopt function, that is, the option is a single character. If an option requires a parameter, you need to add a colon (:) after this option (:). Is a macro, And the null characters around it will be deleted. The content of the macro must be on one line.
If no macro definition is available:
% Define aaa "This is my software" |
For example, the macro definition with only one option is as follows:
% Define xxx (p: Z) echo % {-p: % {-p * }}% {-Z} |
3. Use of macros
Macro format:
% [Opt1] [opt2]... [arg1] [arg2]... |
Or
% { } [Opt1] [opt2]... [arg1] [arg2]... |
Note: [] is optional; Is the macro name of the application. The macro name can be included in {}; opt1, opt2... it must begin with a minus sign (-). If the option requires a parameter, you must provide an option parameter; arg1, arg2... is the macro parameter.
As defined above, the xxx macro can be used as follows:
% Xxx-p zhsoft hello world < |
Br>
In this example, the xxx macro uses an option-p, zhsoft is the parameter of the-p option, and there are two macro parameters hello and world.
Note: It is best to change one more line when using a macro (that is, a blank line under the macro), because the macro does not wrap after expansion, so if there are not many line breaks, if there is any content in the following line, the extended macro content is merged with the content of the following line, which is very prone to errors. This is also one of the problems I found in RPM macros. There is another problem. If a macro exists on the comment line, the macro will also be extended. Wrong! This is because annotations should be ignored, and macros do not need to be extended. Both of these issues need to be noticed by the RPM developers and solved.
4. Macros for macros
The following special macros can be used in a macro: (Macros in SHELL format)
1) % 0: indicates the macro name of the macro;
2) % *: All macro parameters;
3) % #: Number of macro parameters;
4) % {-f}: indicates that if the macro uses the-f option, it indicates-f and its option parameters;
5) % {-f *}: indicates the-f parameter if the macro uses the-f option;
6) % {-f: X}: indicates that if the macro uses the-f option, it indicates X;
7) % {! -F: Y}: indicates that if the macro does not use the-f option, it indicates Y;
8) % 1, % 2,...: Indicates macro parameter 1, parameter 2...
For example, when the xxx macro is executed in the preceding example, if the macro contains the above dedicated macro, the dedicated Macro will be extended:
1) % 0 is extended to xxx;
2) % * extended to hello world;
3) % # extended to 2;
4) % {-p} is extended to-p zhsoft;
5) % {-p *} is extended to zhsoft;
6) % {-p: good} is extended to good;
7) % {! -Z: bad} is extended to bad (because the-Z option is not used in the xxx macro)
8) % 1 is hello, % 2 is world, and no other parameters exist.
5. built-in macros
The built-in macros of the system can be divided into the following three types:
5.1 Definition class
1) % define...: defines a macro. (originally, % define is also a macro)
2) % undefine...: cancels a macro. (After the macro is canceled, the description file below this statement cannot use this macro any more. Even if it is used, the macro will not be extended)
5.2 debugging
1) % trace: prints debugging information before and after macro expansion;
2) % dump: prints the macro (macro name and macro) of the activity );
3) % {echo:...}: print... to the standard error device;
4) % {warn:...}: print... to the standard error device;
5) % {error:...}: print... to the standard error device and return the BADSPEC value;
5.3 Special classes
The default values of these macros are usually stored in the/usr/lib/rpm/macros file. You can edit the. rpmmacros file (~ /. Rpmmacros), you can redefine this type of macro and change its default value for RPM to use its own definition during software package creation, installation, and query.
The Definition Format of these macros is:
Note: The macro name.
1) % packager, % vendor, % distribution:
These three macros are used to define the default domain values of the three optional fields in the description file: Packager, Vendor, and Distribution. That is, if any of the three fields is not defined in the description file, and its corresponding macro is defined, RPM will use its corresponding macro.
For example, my ~ The/. rpmmacros file contains the following three lines:
% Vendor vertical and horizontal software production center % Packager Yu Yiqi % Distribution Xiao Zhao '2001 |
In this way, the three fields no longer need to be defined in the software package description file. During the query, the Packager and the Vendor) and the release version (Distribution.
2) % buildroot, % _ provides:
These two macros define the root directory used for package creation and the features provided by the package. They are not actively used by RPM like the Three macros above during packaging, but must write several lines in the description file. That is:
% Vendor vertical and horizontal software production center % Packager Yu Yiqi % Distribution Xiao Zhao '2001 Buildroot: % buildroot Provides: % _ provides |
3) % _ topdir, % _ builddir, % _ rpmdir, % _ sourcedir, % _ specdir, % _ srcrpmdir:
These six macros are used when RPM is used to create software packages. Their default values in the/usr/lib/rpm/macros file are:
% _ Topdir % {_ usrsrc}/dist % _ Builddir % {_ topdir}/BUILD % _ Rpmdir % {_ topdir}/RPMS % _ Sourcedir % {_ topdir}/SOURCES % _ Specdir % {_ topdir}/SPECS % _ Srcrpmdir % {_ topdir}/SRPMS |
The % _ topdir macro defines the top-level directory of the directory used when the RPM software package was created. It is generally/usr/src/dist (the value of % {_ usrsrc} macro is/usr/src ). There are five subdirectories under the top-level directory:
- The directory used to compile and connect the source program, which is defined by the % _ builddir macro and commonly used BUILD;
- Directory of the generated RPM execution package, defined by the % _ rpmdir macro, commonly used RPMS;
- Directory of the software source program, defined by the % _ sourcedir macro, commonly used SOURCES;
- Directory where the software package description file is stored, defined by the % _ specdir macro, commonly used SPECS;
- The directory where the generated RPM source package is stored, defined by the % _ srcrpmdir Macro. SRPMS is commonly used.
Due to the recursion of macros, we can change the five macros, such as % _ builddir, by defining only the % _ topdir macro. (Note: If there are no special requirements for the macros such as % _ builddir, do not change them. They are standard definitions and should be used.) This is of great significance to common users. The default top-level directory/usr/src/dist of RPM is not accessible to all users. Common users want to use RPM to create software packages in all their directories. I also have this idea, so in ~ /. Add the following line to the rpmmacros file:
At the same time, the subdirectory required for RPM is created under the directory defined in this macro. The command is:
$ Cd/usr/zzz $ Mkdir-p rpm/{BUILD, RPMS/i386, SOURCES, SPECS, SRPMS} $ |
The i386 in the command is the default system name of RPM. The execution package generated by RPM is stored in the "RPMS/system name" directory. After doing so, I can create an RPM package in my own directory, as free as a Super User.
4) % _ excludedocs, % _ ftpport, % _ ftpproxy, % _ httpport, % _ httpproxy, % _ netsharepath:
These six macros are used to install and query the RPM software package.
- % _ Excludedocs: If the value is defined as 1, when RPM is used to install the software package, the default practice of this document is not to install;
- % _ Ftpport: This macro is used to define the default FTP port of RPM;
- % _ Ftpproxy: This macro is used to define the default FTP Proxy Server of RPM;
- % _ Httpport: This macro is used to define the default HTTP port of RPM;
- % _ Httpproxy: This macro is used to define the default HTTP Proxy Server of RPM;
- % _ Netsharepath: This macro is used to define the default network shared directory of the RPM for network file systems (NFS ).
6. A special macro
This macro is used as follows:
% (SHELL command and its parameters) |
The result is the standard output result of the specified SHELL command as part of the content of the description file. If you need to add the current date to a part of the package description file, you can use:
After the macro is executed, it is extended to date data similar to 2001-10-31. Try adding the following two lines in the pre-processing Section (% prep) of your description file:
% (Date + % Y-% m-% d) Exit 1 |
Note: exit 1 is used to stop RPM execution.
Description file template
All the following description file templates take the LZE software package as an example. The software package is generated based on the files generated after the field compilation of the source program. Description files generally only describe the necessary parts. In addition, if all files in the file segment already exist in the system and you want to directly use the package, you can remove the Source domain and the RPM package creation function segment (% prep, % build, % install, % clean ).
1. Only the parent package exists, and no child package exists:
For more information about this description file, see <proficient in RPM 7-production (part I)>. This file can also remove several optional functional segments, such as % pre, % post, % preun, % postun, % triggerin, % triggerun, % triggerpostun. These segments have no substantive purpose in this file. When executed, only the information about executing a script program starting with RPM is displayed. This description file generates only the package lze-6.0-2.i386.rpm (parent package ).
2. There are Parent and Child packages:
The description file is as follows:
1 # file name: lze-6.0-2.spec1
2 # file function: lze Software Package Description
3 # Author: Zhao Jianli, graduate Team 2, yuyiqi National Defense University, China software production center
4 # modification time: 2001.10.31
5
6 Name: lze
7 Version: 6.0
8 Release: 2
9 Summary: Xiao Zhao full-screen multi-window multi-functional editor in Chinese and English (applicable to LINUX/UNIX systems)
10 Group: Applications/Editors
11 License: Share
12 Source: http://zhsoft.myetang.com/lze-6.0-2.src.tgz
13
14% description
Editor Xiao Zhao is a full-screen Multi-Window Design designed for users using sco unix and LINUX multi-user systems.
16 multi-functional editors in Chinese and English.
17 it mainly has the following ten features: 1. Full Screen Menu operations. 2. diverse display methods. 3. Rich block operations. 4. 10
The 18-word tabulation feature is powerful. 5. Flexible multi-window operations. 6. Complete file operations. 7. Explain that the output function is unique
19 colors. 8. built-in Chinese Input Method (enhanced five strokes and enhanced pinyin), practical and convenient. 9. hexadecimal editing, such as Tiger
20 wings. 10. Instant translation.
21 In short, Xiao Zhao editor will be a good helper for programming and writing General documents on UNIX and LINUX systems.
22. It will help you at work, so you can easily get involved!
23
24% prep
25 echo "the pre-processing script program (PREP) starts to execute"
26% setup
27
28% build
29 echo "compile the connection script program (build) to start execution"
30 make
31
32% install
33 echo "Install the script program to start execution"
34 make install
35
36 # configuration file sub-Package
37% package config
38 Summary: configuration file of Lze in Xiao Zhao Editor
39 group: Applications/Editors
40
41% description config
42. The configuration file used by Xiao Zhao editor includes the function key definition file and
43. The input method control file can be modified according to the actual situation.
44
45% files config
46% config/etc/funkey. Def
47% config/etc/inputme. Def
48
49 # plaintext sub-Package
50% package Doc
51 Summary: Instructions for Lze in Xiao Zhao Editor
52 group: Applications/Editors
53
54% description doc
55 Xiao Zhao editor instructions, detailed introduction to the editor
56.
57 users are familiar with Xiao Zhao editor.
58
59% files doc
60% doc/usr/doc/lze-6.0/README
61% doc/usr/doc/lze-6.0/LICENSE
62
63 # parent package file segment
64% files
65% defattr (-, root, root)
66/usr/bin/lze
67/usr/bin/lzeime. py
68/usr/bin/lzeime. wb
69/etc/wbzc. dat
70
This description file generation package includes: lze-6.0-2.i386.rpm (parent package), lze-config-6.0-2.i386.rpm (configuration file sub-package), and lze-doc-6.0-2.i386.rpm (plain text sub-package ).
3. No parent package, only child package:
If no parent package exists, the description file does not contain the file segment (% files) of the parent package. See the following description file:
1 # file name: lze-6.0-2.spec2
2 # file function: lze Software Package Description
3 # Author: Zhao Jianli, graduate Team 2, yuyiqi National Defense University, China software production center
4 # modification time: 2001.10.31
5
6 name: Lze
7 version: 6.0
8 release: 2
9 Summary: Xiao Zhao full-screen multi-window multi-functional editor in Chinese and English (applicable to Linux/Unix systems)
10 group: Applications/Editors
11 License: Share
12 Source: http://zhsoft.myetang.com/lze-6.0-2.src.tgz
13
14% description
Editor Xiao Zhao is a full-screen Multi-Window Design designed for users using sco unix and LINUX multi-user systems.
16 multi-functional editors in Chinese and English.
17 it mainly has the following ten features: 1. Full Screen Menu operations. 2. diverse display methods. 3. Rich block operations. 4. 10
The 18-word tabulation feature is powerful. 5. Flexible multi-window operations. 6. Complete file operations. 7. Explain that the output function is unique
19 colors. 8. built-in Chinese Input Method (enhanced five strokes and enhanced pinyin), practical and convenient. 9. hexadecimal editing, such as Tiger
20 wings. 10. Instant translation.
21 In short, Xiao Zhao editor will be a good helper for programming and writing General documents on UNIX and Linux systems.
22. It will help you at work, so you can easily get involved!
23
24% prep
25 echo "the pre-processing script program (PREP) starts to execute"
26% setup
27
28% build
29 echo "compile the connection script program (build) to start execution"
30 make
31
32% install
33 echo "install the script program to start execution"
34 make install
35
36 # configuration file sub-Package
37% package config
38 summary: configuration file of LZE in Xiao Zhao Editor
39 group: Applications/Editors
40
41% description config
42. The configuration file used by Xiao Zhao editor includes the function key definition file and
43. The input method control file can be modified according to the actual situation.
44
45% files config
46% config/etc/funkey. def
47% config/etc/inputme. def
48
49 # plaintext sub-Package
50% package doc
51 summary: Instructions for LZE in Xiao Zhao Editor
52 group: Applications/Editors
53
54% description doc
55 Xiao Zhao editor instructions, detailed introduction to the editor
56.
57 users are familiar with Xiao Zhao editor.
58
59% files Doc
60% DOC/usr/doc/lze-6.0/readme
61% DOC/usr/doc/lze-6.0/license
62
63 # execution Program Sub-Package
64% package Bin
65 Summary: Execution program of Lze in Xiao Zhao Editor
66 group: Applications/Editors
67
68% description Bin
69. The execution program of Xiao Zhao editor is Lze, and the five-stroke input method server executes the program.
70 is lzeime. WB, And the Pinyin Input Method server executes the lzeime. py program.
71
72% files Bin
73% defattr (-, root, root)
74/usr/bin/Lze
75/usr/bin/lzeime. py
76/usr/bin/lzeime. WB
77/etc/wbzc. dat
78
This profile generates three packages: lze-config-6.0-2.i386.rpm (profile package), lze-doc-6.0-2.i386.rpm (plain text package), lze-bin-6.0-2.i386.rpm (executable package ).