Make RPM package, can be convenient for future maintenance. Unify the standard
-
Yum Install Rpmdevtools
After installation, use the Rpmdev-setuptree command to create the directory structure of the RPM package. The default is under $home under Rmpbuild, or it can be configured by ~/.rpmmacros.
- Spec documentation is the core of making RPM packages.
- Here's the copy from Fedora.
-
create a new. spec file now, you need to~/rpmbuild/specs directory, create a new SPEC file. The file should be named"package name. Spec". The name is filled in according to the package name or generic name. However, the package naming rules must be adhered to. Templates and instance templates if you create a. spec file for the first time, vim or Emacs automatically generates the template: $ cd~/rpmbuild/SPECS $ vim Program.spec example (for reference only): Name:Version:Release:1%{?Dist} Summary:Group:License:URL:Source0:BuildRoot:%{_tmppath}/%{name}-%{version}-%{release}-root-% (%{__id_u}-N) Buildrequires:requires:%Description%Prep%setup-Q%Build%Configure Make%{?_smp_mflags}%InstallRM-rf%{BuildRoot} Make Installdestdir=%{BuildRoot}% CleanRM-rf%{BuildRoot}%Files%defattr (-,root,root,-)%Doc%changelog
- How to write the parameters inside:
-
The " # " character represents a comment, but you need to avoid commenting on the macro (to % begin with) because they are replaced first. Use %% annotation macros. Also, avoid using inline annotations in the same line of script commands.
The main labels are described below. Note %{name} , %{version} and %{release} represent Name, Version, and Release of these three tags. As soon as you change the label, the macro uses the new value.
- name: The package name should match the SPEC file name. Naming must conform to the package naming convention.
- Version: The upstream release number. Please review the version label rules. If you include non-numeric characters, you may want to include them in the Release label. If the upstream takes a date as the version number, consider the following:
yy.mm[dd] (for example, 2008-05-01 variable to 8.05 ) format as the version number.
- Release: Release number. The initial value is
1%{?dist} . Increment this number each time you make a new package. When a new version is published upstream, modify the version label and reset the release number to 1 . Refer to the Release label section in the packaging specification and Dist tag.
- Summary: A brief description of the package. Please use American English. do not add punctuation at the end!
- Group: Specifies the package group, such as "applications/engineering"; execute "to
less /usr/share/doc/rpm-*/GROUPS view the complete list of groups. Any sub-packages that contain documents, using the "Documentation" group (for example kernel-doc ). Note that this tag has been revoked after Fedora 17+. Spec File Reference manual is introduced
- License: The licensing agreement must be an open source license. Please do not use the old Copyright label. The protocol uses standard abbreviations (such as "
GPLv2+ ") and is clearly described (for example, " GPLv2+ " means GPL 2 and subsequent versions, not "" or "" or "" the inaccurate GPL GPLv2 notation). Refer to Licensing and Licensing guidelines. If a software uses multiple protocols, you can use " and and" or (for example, "" GPLv2 and BSD ) to describe it.
- URL: The software package's Project home page. Note: The source package URL should be specified using SOURCE0.
- Source0: The URL address of the software source package. "" and "" are the
Source Source0 same. It is strongly recommended to provide a full URL address for locating the SOURCES directory. If possible, it is recommended to use %{name} and %{version} replace the name/version in the URL so that the update will automatically correspond. When you download the source package, you need to keep the timestamp. If there are multiple source packages, please use Source1 , and Source2 so on, listed. If you need to add additional files, list them later. For more special cases (such as revision control), refer to the Source URL.
- Patch0: The name of the patch used for the source code. If you need to make changes to some code after the source package is unpacked, you should modify the code and use the diff command to generate the patch file and then place it in the
~/rpmbuild/SOURCES directory. A patch should only be modified, so it may contain multiple patch files.
- Buildarch: If the file you want to package does not depend on any schemas (such as shell scripts, data files), use "
BuildArch: noarch ". The RPM architecture will become " noarch ".
- buildroot: The file needs to be installed at this location in the%install phase (after the%build phase). Fedora does not require this tag, only EPEL5 needs it. By default, the root directory is "
%{_topdir}/BUILDROOT/ ".
- buildrequires: The list of dependent packages required to compile the package, separated by commas. This label can be specified more than once. Compilation dependencies are not automatically judged, so you need to list all the dependent packages required for compilation. A common package can be omitted, for example
gcc . If necessary, you can specify the minimum required version (example: " ocaml >= 3.08 "). If you need to find /EGGS the package containing the file, do " rpm -qf /EGGS ". If you need to find EGGS a package that contains a program, execute " rpm -qf `which EGGS` ". Keep the minimum dependency (for example, if you don't need Perl's functionality, you can use sed instead), but be aware that some programs will disable some features if they don't include dependencies; At this point, you need to add those dependencies. auto-buildrequirespackages may be helpful.
- Requires: A comma-delimited list of dependent packages required to install the package. Note that the buildrequires tag is a dependency required for compilation, while the Requires tag is the dependency required to install/run the program. In most cases,
rpmbuild dependencies are automatically detected, so Requires tags may not be required. However, you can also clearly indicate which packages are required, or you need to manually mark them because they do not automatically detect the required dependencies.
- %description: detailed/MultiRow description of the program, please use American English. Each line must be less than or equal to 80 characters. A blank line indicates the beginning of a new paragraph. The paragraph is reformatted when the software is installed using graphics, and lines that begin with a space are treated as formatted formats that are typically displayed in a wide font. Refer to RPM Guide.
- %prep: The package preparation phase executes some commands (for example, extracting source packages, patching, etc.) to start compiling. Generally only "
%autosetup "; if the source package needs to be decompressed and switched to the NAME directory, enter " %autosetup -n NAME ". Check out the%prep section for more information.
- %build: Contains the commands that are executed during the build phase, and the subsequent installation begins when the build is complete. The program should contain an introduction to how to compile. Check out the%build section for more information.
- %install: Contains the commands that are executed during the installation phase. command to install files from the
%{_builddir} directory to the %{buildroot} directory. Check out the%install section for more information.
- %check: Contains the commands that are executed during the test phase. This phase is executed after%install, usually containing the "
make test or" make check command. This phase is separated from%build so that the test is ignored when needed.
- %clean: The command to clean up the installation directory. This phase is superfluous in Fedora and is for EPEL only. Generally only includes:
RM-RF%{buildroot}
- %files: List of files that need to be packaged/installed. Check out the%files section for more information.
- %changelog: RPM Package change log. Please use the format in the example. Note that the change log is not the software itself.
- Excludearch: Excludes certain schemas. If the software does not compile or work properly on some schemas, it is listed by this tab.
- exclusivearch: Lists the schema that the package is exclusive to.
Place source Code
Put a devrpm-0.0.1.tar.gz source code compressed file into rpmbuild the root directory under the sources directory (note, make sure that the archive file after the extracted directory is devrpm-0.0.1, otherwise there will be a problem).
By the completion of this complete RPM packaging environment, we can start building binary and source RPM packages.
Building RPM Packages
Building RPM Packages is a command rpmbuild under the guidance of spec.
Start the build operation by first entering the Rpmbuild root directory of the current user (the directory environment mentioned above).
#cd ~/rpmbuild/
To execute the command,-BA represents build all, which generates all RPM packages including the binary package and the source package, and if normal, rpmbuild exits normally, and the corresponding RPM package is generated in the RPMs directory and Srpms directory.
#rpmbuild -ba SPECS/hellorpm.spec
Above reference: Https://fedoraproject.org/wiki/How_to_create_an_RPM_package/zh-cn#.E6.A8.A1.E6.9D.BF.E5.92.8C.E5.AE.9E.E4.BE.8B
http://segmentfault.com/a/1190000002539129
RPM Package Production