rpm生成安装包相关知识点

一. 查询rpm当前构建路径

rpm --showrc|grep _topdir

二. 修改rpm的构建路径

我们可以通过修改topdir宏的值来自定义打包路径:

$ echo %_topdir $HOME/rpmbuild > ~/.rpmmacros   //eg:echo %_topdir %{_usrsrc}/redhat > ~/.rpmmacros  将构建路径还原成默认构建路径。

三. 编译.spec文件时,提示错误“Installed (but unpackaged) file(s) found:”

错误原因:必须使用正确的相对路径,否则编译时提示“Installed (but unpackaged) file(s) found:”

四.spec文件编写

Summary: MDJPOSScannerService-1.1

Name: MDJPOSScannerService

Version: 1

Release: 1

Source: MDJPOSScannerService-1.tar.gz

License: GPL

Packager: hejuan

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root

Group: System

Url:       http://www.linuxfly.org

Prefix:    %{_prefix}   #%{_prefix}指/usr

Prefix:    %{_sysconfdir}

%define    userpath /var/www/html/demo


%description
This is a JPOS scanner service!

%prep
%setup -c #%setup -n %{name}-%{version} 把源码包解压并放好
#tar -zxvf /home/andy/rpmbuild/SOURCES/MDJPOSScannerService-1.tar.gz
#tar xzf $RPM_SOURCES_DIR/MDJPOSScannerService-1.tar.gz


#安装 -- 相当于make install
%install

install -d $RPM_BUILD_ROOT%{userpath}
cp -a %{name}* $RPM_BUILD_ROOT%{userpath}
#rm -rf $RPM_BUILD_ROOT%{userpath}

#拷贝文件  
#install -d -m755 $RPM_BUILD_ROOT%{_prefix}/MDJPOSScannerService/jpos/res
#install -d -m755 $RPM_BUILD_ROOT%{_prefix}/MDJPOSScannerService/lib
#install -m 755 MdJpos.sh $RPM_BUILD_ROOT%{_prefix}/MDJPOSScannerService/
#install -m 644 libgetScannerData.so $RPM_BUILD_ROOT%{_prefix}/MDJPOSScannerService/lib/
#install -m 644 javax.usb.properties $RPM_BUILD_ROOT%{_prefix}/MDJPOSScannerService/
#install -m 644 jpos/res/jpos.properties $RPM_BUILD_ROOT%{_prefix}/MDJPOSScannerService/jpos/res/

#此段必须放在Clean之前,否则编译时提示“Installed (but unpackaged) file(s) found:”
%files   
%defattr(-,root,root)
%{userpath}
#%dir %{_prefix}/MDJPOSScannerService/
#%dir %{_prefix}/MDJPOSScannerService/lib/
#%dir %{_prefix}/MDJPOSScannerService/jpos/
#%dir %{_prefix}/MDJPOSScannerService/jpos/res/
#%defattr(0755,root,root,-)
#%{_prefix}/MDJPOSScannerService/MdJpos.sh
#%{_prefix}/MDJPOSScannerService/jpos/javax.usb.properties
#%{_prefix}/MDJPOSScannerService/lib/libgetScannerData.so
#%{_prefix}/MDJPOSScannerService/jpos/res/javax.usb.properties


%clean
rm -rf $RPM_BUILD_ROOT
rm -rf $RPM_BUILD_DIR/%{name}-%{version}
#rm -rf %{_tmppath/%{name}
#rm -rf %{_topdir}/BUILD%{name}


%changelog
* Thurs May 13 2018 Owner
- 1.1 r1 First release
 

你可能感兴趣的:(Linux)