SPEC文件如下
##############################
# JayWan@xxx.com 2014-xx-xx
##############################
#自定义宏, 或者重定义宏
%define _softbase /usr/local
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Name: openssl
Version: 0.9.8zc
Release: CentOS5%{?dist}
Summary: openssl
#软件组别, 有个分类的, 我这里写的是公司名字
Group: xxxx
#此软件属于哪个开原协议
License: xxxx
#此软件的url
URL: http://www.xxxx.com/
#源码文件,只接受.tar.gz的压缩包
Source0: %{name}-%{version}.tar.gz
#构建目录
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
#标明构建时需要哪些软件以及版本
#BuildRequires: glibc >= 2.2.5
#运行时需要哪些软件
#Requires:
#此域用于指示RPM是否自动查找软件所需的共享库与其提供的共享库。仅当域值为no
#或0时,RPM不执行find-requires与find-provides两个程序。此域相当于同时设定Autoreq
#与Autoprov域值为指定之值。
#AutoReqProv: no
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#description段=============================
%description
#
#--------------------------------------------------------------
#prep段,config之前的预操作=================
%prep
%setup -q
#-------------------------------------------------------------
#build段, =================================
%build
./config shared --prefix=%{_softbase}/%{name}-%{version}
make %{?_smp_mflags}
#-------------------------------------------------------------
#install段, 主要是make install=============
%install
make install DESTDIR=$RPM_BUILD_ROOT
#-------------------------------------------------------------
#clean段, make install之后的清理===========
%clean
rm -rf $RPM_BUILD_ROOT
#-------------------------------------------------------------
#files段 ==================================
%files
#文件权限
%defattr(-,root,root,-)
%doc
%{_softbase}/%{name}-%{version}
#-------------------------------------------------------------
#脚本执行 =================================
#rpm安装前执行的脚本
%pre
export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:$PATH
if [[ "`cat /etc/redhat-release`" =~ "CentOS release 5." ]];then : ;else echo -e "\033[49;31;5m -- Error: 本RPM包仅限安装于CentOS 5.x --\033[0m" ; exit 1;fi
##rpm安装后执行的脚本
%post
export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:$PATH
cd %{_softbase}/ && ln -s %{name}-%{version} %{name}
if [ -d %{_softbase}/%{name}/lib ];then
echo "%{_softbase}/%{name}/lib" > /etc/ld.so.conf.d/%{name}.conf
fi
nohup ldconfig > /dev/null 2>&1 &
#chmod 755 /etc/init.d/nginx
#chkconfig --add nginx
##rpm卸载前执行的脚本
%preun
export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:$PATH
##rpm卸载后执行的脚本
%postun
export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:$PATH
rm -f /etc/ld.so.conf.d/%{name}.conf
#-------------------------------------------------------------
#changelog段 ==============================
%changelog
#-------------------------------------------------------------配置文件完
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# rpmbuild -v -bb --clean openssl.spec
报错:
make[2]: Leaving directory `/root/rpmbuild/BUILD/openssl-0.9.8zc/crypto/pqueue'
make[1]: Leaving directory `/root/rpmbuild/BUILD/openssl-0.9.8zc/crypto'
error: Bad exit status from /var/tmp/rpm-tmp.2886 (%build)
build宏出错了, 里面config都没问题, 应该是make问题, 去掉make后面的参数继续, 报错如下
+ /usr/lib/rpm/redhat/brp-compress
/usr/lib/rpm/redhat/brp-compress: line 8: cd: /var/tmp/openssl-0.9.8zc-Boyaa_CentOS5-root-root: No such file or directory
+ /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
find: /var/tmp/openssl-0.9.8zc-Boyaa_CentOS5-root-root: No such file or directory
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
find: /var/tmp/openssl-0.9.8zc-Boyaa_CentOS5-root-root: No such file or directory
+ /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
find: /var/tmp/openssl-0.9.8zc-Boyaa_CentOS5-root-root: No such file or directory
+ /usr/lib/rpm/brp-python-bytecompile
find: /var/tmp/openssl-0.9.8zc-Boyaa_CentOS5-root-root: No such file or directory
+ /usr/lib/rpm/redhat/brp-java-repack-jars
find: /var/tmp/openssl-0.9.8zc-Boyaa_CentOS5-root-root: No such file or directory
Processing files: openssl-0.9.8zc-Boyaa_CentOS5
error: File not found: /var/tmp/openssl-0.9.8zc-Boyaa_CentOS5-root-root/usr/local/openssl-0.9.8zc
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/openssl-0.9.8zc-Boyaa_CentOS5-root-root
RPM build errors:
Macro %debug_package has empty body
File not found: /var/tmp/openssl-0.9.8zc-Boyaa_CentOS5-root-root/usr/local/openssl-0.9.8zc
原来openssl的make比较非主流, 用INSTALL_PREFIX变量指定安装到哪里去, 而不是
DESTDIR
so %install下面的内容写成这样 即可
%install
rm -rf $RPM_BUILD_ROOT
grep -F 'INSTALL_PREFIX=' Makefile > /dev/null 2>&1
if [ $? -eq 0 ];then
make install INSTALL_PREFIX=$RPM_BUILD_ROOT
else
make install DESTDIR=$RPM_BUILD_ROOT
fi