1. 首先得确保工程的qmake编译没有问题
2. 其次需要产生可以被rpmbuild读取的源码包:
对于git工程可以用如下命令:
export VERSION_SHORT=1.1.0
git archive --format=tar HEAD | gzip > qt-example-${VERSION_SHORT}-src.tar.gz
对于svn工程,可以用如下命令:
PROJ='yourproj' &&
URL='http://svn.example.com/svn/repo/$PROJ' &&
REV=`svn info $URL | fgrep Revision | cut -d ' ' -f 2` &&
cd ~/tmp &&
svn export $URL $PROJ &&
tar czv -f $PROJ.r$REV.tar.gz $PROJ &&
rm -r $PROJ.r$REV
3. 建立rpmbuild需要的目录结构
export WORKSPACE=$(mktemp -d)
mkdir -p $WORKSPACE/{BUILD,RPMS,SOURCES,SPECS,SRPMS,tmp}
echo Working in $WORKSPACE
4. 建立Qt的编译环境
export BITS=$(getconf LONG_BIT)
export QMAKESPEC=linux-g++-$BITS
export QTDIR=/opt/Trolltech/5.12.6
export PATH=$QTDIR/bin:$PATH
echo -- QTDIR set to "$QTDIR"
echo -- QMAKESPEC set to "$QMAKESPEC"
echo -- PATH set to "$PATH"
5. 建立rpmbuild需要的版本信息和spec文件、源码等
export VERSION_MAJOR=1
export VERSION_MINOR=0
export VERSION_REVISION=20
export VERSION_BUILD=$(git log --pretty=format:'%h' -n 1)
export VERSION_SHORT=${VERSION_MAJOR}${VERSION_MINOR}${VERSION_REVISION}${VERSION_BUILD}
export VERSION_LONG=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}.${VERSION_BUILD}
echo -- Major $VERSION_MAJOR
echo -- Minor $VERSION_MINOR
echo -- Revision $VERSION_REVISION
echo -- Build $VERSION_BUILD
将源代码压缩包和spec文件分别拷贝到对应的目录:
ARCHIVE=$(find `pwd` -name 'qt-example-*-src.tar.gz' -type f | head -1)
SPEC=$(find `pwd` -name 'qt-example.spec' -type f | head -1)
cp $ARCHIVE $WORKSPACE/SOURCES
cp $SPEC $WORKSPACE/SPECS
6. 运行rpmbuild生成rpm包:
# Change to workspace
cd $WORKSPACE
# Make RPM
rpmbuild --define "_topdir ${WORKSPACE}" -ba -vv $WORKSPACE/SPECS/qt-example*.spec
7. 附录.spec文件的写法
%define VERSION_LONG %(echo $VERSION_LONG)
%define VERSION_SHORT %(echo $VERSION_SHORT)
%define VERSION_MAJOR %(echo $VERSION_MAJOR)
%define VERSION_MINOR %(echo $VERSION_MINOR)
%define VERSION_REVISION %(echo $VERSION_REVISION)
%define VERSION_BUILD %(echo $VERSION_BUILD)
#
# Qt Example
#
Summary: An example application compiled with QMake that was turned into an RPM.
Name: qt-example
Version: %{VERSION_LONG}
Release: %{VERSION_BUILD}
License: MIT
Group: Applications
Source: http://corpration.domain/not/path/to/application/qt-example-%{VERSION_SHORT}-src.tar.gz
URL: http://corpration.domain
Vendor: http://corpration.domain
Packager: Author Name<author.name@copration.com>
%description
Application that exists purely to exemplify how to build an RPM package.
%prep
%setup -n source
%build
qmake -r
make -f Makefile.$QMAKESPEC all
%install
INSTALL_ROOT=%{buildroot}/usr make -f Makefile.$QMAKESPEC install
%post
%postun
%files
%{_bindir}/*
%{_libdir}/*
%changelog
网友评论