Package source code into an rpm installation package under CentOS
Platform: centos6.5
First, build the environment:
[Cpp] view plaincopyprint?
- [Root @ localhostbinbin] # yuminstall-yrpm-build </span>
[Cpp] view plaincopyprint?
- [Root @ localhostbinbin] # yuminstallredhat-rpm-config
There will be an rpmbuild directory under the/root directory.
[Cpp] view plaincopyprint?
- [Root @ localhostrpmbuild] # pwd
- /Root/rpmbuild </span>
Go to the directory, which contains five folders: BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
It was empty at the beginning.
[Html] view plaincopyprint?
- [Root @ localhostrpmbuild] # ls
- BUILDBUILDROOTRPMSSOURCESSPECSSRPMS
If you do not have these directories, you can manually add and create
The functions of these six directories are as follows:
BUILD: rpmbuild directory for software compilation
BUILDROOT:
RPMS: rpmbuild creates the directory where binary RPM is stored
SOURCES: directory for storing source code
SPECS: directory for storing spec files
SRPMS: rpmbuild creates the directory where souce RPM is stored
First, package the folders with source code. Here my folder is named login-1.0
[Cpp] view plaincopyprint?
- Using root@localhostbinbin1_tarzcvflogin-1.0.tar.gz login-1.0
- [Root @ localhostbinbin] # ls
- Login-1.0.tar.gzlogin-1.0
Copy login-1.0.tar.gz to the rpmbuild/SOUCES directory.
[Html] view plaincopyprint?
- Export root@localhostbinbin]#cplogin-1.0.tar.gz/root/rpmbuild/SOURCES
- [Root @ localhostSOURCES] # ls
- Login-1.0.tar.gz
Go to the SPEC directory and write the SPEC file (this step is the key step to package the rpm package)
[Html] view plaincopyprint?
- [Root @ localhostSOURCES] # cd ../SPECS
- [Root @ localhostSPECS] # touchlogin. spec
- [Root @ localhostSPECS] # ls
- Login. spec
- [Root @ localhostSPECS] # vimlogin. spec
[Html] view plaincopyprint?
- # Name
- Name: login
- # Version number
- Version: 1.0
- # Compilation order
- Release: 1
- # One-sentence introduction package (up to 50 characters)
- Summary: istest
- Group: Applications/Communications
- License: GPL
- URL: www.ciis.com
- # Source file of the compressed package to be installed
- Source: login-1.0.tar.gz
- BuildRoot: % {_ tmppath}/% {name}-% {version}-root
- % Description
- Atest
- # Pre-build handling
- % Prep
- # -- Decompress: extract the source code to the system directory during building. Here, $ RPM_BUILD_DIR is used.
- # During setup-c decompression, a new directory with the same name as the compressed package will be generated; setup-ndirname specifies a new directory to decompress setup-q and directly decompress it without creating a new directory.
- % Setup-q
- # -- Generate: This mainly refers to the compilation and generation of binary files when building Binary packages.
- % Build
- Make
- # -- Installation: Install the current file to the system directory $ RPM_BUILD_ROOT/During build, and install the file in the/root directory during binary installation.
- % Install
- # Makeinstall # use makefile's install for convenience
- # 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/
- # Subsequent installation: processing script after Binary Package Installation
- % Post
- Chmod + x/usr/bin/% {name}-% {version}/confAgent
- Chmod + x/usr/bin/% {name}-% {version}/check_confAgent.sh
- # Subsequent processing scripts after uninstallation: processing scripts after uninstallation of Binary packages
- % Postun
- Rm-fr/usr/bin/% {name}-% {version}
- # Cleanup: After the build package is completed
- % Clean
- Rm-rf $ RPM_BUILD_ROOT
- # File list: indicates which files should be installed in the system and the installed directory;
- # When creating a package, the file or directory in the file list must be consistent with the file or directory in the virtual directory RPM_BUILD_ROOT; otherwise
- # The system prompts that the file cannot be found.
- % Files
- % Defattr (-, root, root)
- /Usr/bin/% {name}-% {version}
- % Changelog
Save and exit. Run the packaging command.
[Html] view plaincopyprint?
- [Root @ localhostSPECS] # rpmbuild-balogin.spec </span>
There will be a corresponding rpm package under the RPMS/i686 directory, here is the login-1.0-1.i686.rpm
[Html] view plaincopyprint?
- [Root @ localhostSPECS] # cd ../RPMS/i686
- [Root @ localhosti686] # pwd
- /Root/rpmbuild/RPMS/i686
- [Root @ localhosti686] # ls
- Login-1.0-1.i686.rpm
Test installation
[Html] view plaincopyprint?
- [Root @ localhostbinbin] # ls
- Login-1.0-1.i686.rpm
- [Root @ localhostbinbin] # rpm-ivhlogin-1.0-1.i686.rpm
- [Root @ localhostbinbin] #/usr/bin/login-1.0/demo
You can run the client.