2008年11月17日星期一

Archlinux上编译自己的QT

Arch更新频繁,为了保持稳定和可控,决定自己编译该死的QT。

首先chroot到移动硬盘上的测试系统

sudo chroot /mnt/ /bin/su - foo
qt的源码包比较大(99M),建议单独用下载工具下载,下载PKGBUILD,修改以符合自己需要,我这里去掉了几个快捷方式(desktop文件)以及安装(make install)后的处理,同时编译demos、examples和docs:
# $Id$
# Maintainer: Pierre Schmitz

pkgname=qt
pkgver=4.4.3
pkgrel=2
_qtcopyver=880178
pkgdesc="The QT gui toolkit."
arch=('i686' 'x86_64')
url="http://www.trolltech.com/products/qt"
license=('GPL3')
options=('!libtool' '!docs')
depends=('libpng' 'libxi' 'mesa' 'fontconfig' 'libxrandr' 'glib2' 'libtiff' 'libmng' 'sqlite3' 'dbus' 'libxcursor' 'libxinerama')
optdepends=('postgresql-libs' 'libmysqlclient' 'unixodbc')
makedepends=('inputproto' 'postgresql-libs' 'mysql' 'unixodbc' 'cups' 'libxfixes')
provides=("qt4=${pkgver}")
replaces=('qt4')
conflicts=('qt4')
_pkgfqn=qt-x11-opensource-src-$pkgver
# svn export -r -${_qtcopyver} svn://anonsvn.kde.org/home/kde/trunk/qt-copy/patches/ qt-copy-patches-${_qtcopyver}
source=("ftp://ftp.trolltech.com/qt/source/${_pkgfqn}.tar.bz2"
"ftp://ftp.archlinux.org/other/qt/qt-copy-patches-${_qtcopyver}.tar.bz2")
md5sums=('00e00c6324d342a7b0d8653112b4f08c'
'd3a40d783528a86174b62ecfc136b031')

build() {
# 按源码的INSTALL文件,其实不需要为编译设置变量
unset QMAKESPEC
export QT4DIR=$srcdir/$_pkgfqn
export PATH=${QT4DIR}/bin:${PATH}
export LD_LIBRARY_PATH=${QT4DIR}/lib:${LD_LIBRARY_PATH}

cd $srcdir/$_pkgfqn
for i in $srcdir/qt-copy-patches-${_qtcopyver}/*; do
echo "applying $i"
patch -p0 -i $i || return 1
done

# remove unwanted mkspecs
cd mkspecs/
find . -maxdepth 1 -regextype posix-egrep -type d ! -regex "./linux.*|./common|./features|./qws" -exec rm -rf "{}" \;
cd qws
find . -maxdepth 1 -regextype posix-egrep -type d ! -regex "./linux.*" -exec rm -rf "{}" \;
cd ../../

sed -i 's|-cp -P -f|-cp -L -f|' qmake/Makefile.unix
sed -i "s|-O2|$CXXFLAGS|" mkspecs/common/g++.conf
# fix postgres build
sed -e '/pg_config --libs/d' -i configure
# do not compile demos, examples and docs

# prefix很重要,qt严重依赖,且以后不能更改
./configure -confirm-license \
-prefix /home/foo/qt4.4.3 \
-no-exceptions \
-plugin-sql-{psql,mysql,sqlite,odbc} \
-system-sqlite \
-dbus-linked \
-webkit \
-no-separate-debug-info \
-assistant-webkit \
-system-libpng \
-system-libjpeg \
-system-zlib \
-openssl-linked \
-cups \
-reduce-relocations \
-xinerama \
-xcursor \
-xfixes \
-optimized-qmake || return 1

make || return 1
make INSTALL_ROOT=$pkgdir install || return 1
}
开始编译:
makepkg -s -r
人品不好,一开始就报错
/dev/null: Permission Denied
knoppix的wiki上有详细的说明,简单说就是,mount的时候需要dev参数:
mount -o remount,dev /dev/hda1
接下来,就一切顺利了,2个多小时后,顺利生成qt-4.4.3-2-i686.pkg.tar.gz,你可以使用pacman -U安装,不过我是解压后移动到相应目录。

没有评论: