qt4桌面和交叉编译统一脚本

2019-07-13 03:50发布

由于要经常编译各种版本的qt库,每次都configure --help挺麻烦,于是写了个脚本来简化配置和编译。另外还写了两个脚本又来提取和替换私有头文件。
配置和编译脚本buildqt4.sh 脚本支持编译桌面版和嵌入式linux,已经测试的mkspec有linux-g++, qws/linux-armv6-g++, qws/linux-x86-g++,qt版本支持4.7.4, 4.8.0,其他未测试。 如果源码不是放在qt-everywhare-opensource-x.x.x这样的目录,那么你需要设定脚本开头处的QT__VERSION值。 若交叉编译设置脚本开头处的XPLATFORM值,如qws/linux-armv6-g++,否则留空或注释掉。 默认安装到/opt/QtSDK相应的位置
运行方法 ./buildqt4.sh [configure绝对或相对路径]

若脚本放在qt源码目录qt-everywhare-opensource-x.x.x,则可直接./buildqt4.sh。当然比较推荐源码和构建分开。
#!/bin/bash ############################################################################# ## ## Copyright (C) 2012 Wangbin ## All rights reserved. ## Contact: Wangbin (wbsecg1@gmail.com) ## ## Script to build qt4 for desktop and embedded linux ## Tested version: 4.8.0, 4.7.4 ## Tested mkspecs: linux-g++, qws/linux-armv6-g++, qws/linux-x86-g++ ## ## GNU General Public License Usage ## This file may be used under the terms of the GNU General ## Public License version 3.0 as published by the Free Software Foundation ## and appearing in the file LICENSE.GPL included in the packaging of this ## file. Please review the following information to ensure the GNU General ## Public License version 3.0 requirements will be met: ## http://www.gnu.org/copyleft/gpl.html. ## ## ############################################################################# QT__VERSION= #e.g. 4.7.4, 4.8.0. if empty, we will guess the version XPLATFORM=qws/linux-armv6-g++ #e.g. qws/linux-armv6-g++ config_path=`readlink -f ${1:-./configure}` #check $config_path to guess qt version. suppose the src dir is qt-everywhare-opensource-x.x.x #check changes-x.x.x? src_dir=$(dirname $config_path) QT__VERSION=${src_dir##*-} if [ "x$XPLATFORM" = "x" ]; then INSTALL_DIR=/opt/QtSDK/Desktop/Qt/$QT__VERSION/gcc #llvm, clang? QTMODULE_OPTIONS="$QTMODULE_OPTIONS -opengl es2" else EMBEDDED=`echo $XPLATFORM |cut -d- -f2` XPLATFORM=" -embedded $EMBEDDED -xplatform $XPLATFORM" INSTALL_DIR=/opt/QtSDK/Embedded/$QT__VERSION/armel fi QT474_OPTIONS=" -qt-mouse-pc -qt-mouse-linuxinput -qt-mouse-linuxtp -qt-gfx-transformed -qt-gfx-linuxfb -qt-kbd-linuxinput" if [ "$QT__VERSION" = "4.8.0" ]; then [ -z "$XPLATFORM" ] && QT480_OPTIONS="-qpa -graphicssystem raster" #-qpa arm -silent else QT474_OPTIONS="$QT474_OPTIONS -qt-gif" fi QTMODULE_OPTIONS="-webkit -dbus -qt-sql-sqlite -no-qt3support -declarative -no-declarative-debug -script -scripttools -svg -multimedia -phonon $QTMODULE_OPTIONS" QTPLUGINS_OPTIONS="-qt-libpng -qt-libjpeg -qt-libtiff -qt-libmng -qt-zlib" QTPART_OPTIONS="-nomake demos -nomake examples -nomake docs" QT3RDPARTY_OPTIONS="-freetype -openssl -no-cups -no-iconv" #older qt: -depths 8,16,24,32 ALL_CONFIG="-prefix $INSTALL_DIR -opensource $XPLATFORM -little-endian -release -shared -fast -pch -optimized-qmake -continue -largefile -stl $QT474_OPTIONS $QT480_OPTIONS $QTMODULE_OPTIONS $QTPLUGINS_OPTIONS $QTPART_OPTIONS $QT3RDPARTY_OPTIONS -audio-backend -no-separate-debug-info -no-qvfb" cat <<-EOF qt version: $QT__VERSION install: $INSTALL_DIR configure: $config_path $ALL_CONFIG EOF $config_path $ALL_CONFIG << EOF yes EOF time make -j2 2>&1 |tee /tmp/buildqt4.log [ $? -eq 0 ] && make install
私有头文件提取 make install之后私有头文件内容都仅仅是包含源码目录里的头文件,我们需要把源码目录实际的头文件提取出来替换安装目录这些文件。写了两个脚本get_p.sh和put_p.sh来完成此事,需要安装7z。 先将脚本get_private.sh放到编译目录下的inlude下运行,然后把生成的QtXXX_private.7z复制到安装目录include下,put_private.sh也放于次,运行put_private.sh 如果安装目录下私有头文件已经正确,你可以从那里提取出来供其他目录下的qt库使用,此时运行 ./get_private.sh here
脚本内容: get_private.sh #!/bin/bash # # wbsecg1@gmail.com 2012-02-03 # get private headers from in build dir from source dir # get_private.sh must be in $QT_SRC_DIR/include # put_private.sh must be in $QTDIR/include # cd $QT_SRC_DIR/include; ./get_private.sh # mv Qt*_private.7z $QTDIR/include # cd $QTDIR/include # ./put_private.sh # QT_MODULES=`find . -xtype d -maxdepth 1 |sed 's/.///g' |grep -v "."` if [ "x$1" = "xhere" ]; then for qtmodule in $QT_MODULES do echo "Getting private headers for $qtmodule... $PWD" cd $qtmodule if [ -d private ]; then [ -f private.7z ] && rm private.7z cd private 7z a ../private.7z * cd .. fi cd .. [ -f $qtmodule/private.7z ] && mv $qtmodule/private.7z ${qtmodule}_private.7z done exit 0 fi for qtmodule in $QT_MODULES do echo "Getting private headers for $qtmodule..." cd $qtmodule if [ -d private ]; then cat private/*.h |sed 's/#include "../(.*)"/1/g' >private.list #rdir=`head -n 1 private.list |sed 's/(.*src).*/1/'` #echo "$rdir" [ -f private.7z ] && rm private.7z 7z a private.7z @private.list rm private.list fi cd .. [ -f $qtmodule/private.7z ] && mv $qtmodule/private.7z ${qtmodule}_private.7z done
put_private.sh #!/bin/bash # # wbsecg1@gmail.com 2011-12-18 # get private headers from in build dir from source dir # get_private.sh must be in $QT_SRC_DIR/include # put_private.sh must be in $QTDIR/include # cd $QT_SRC_DIR/include; ./get_private.sh # mv Qt*_private.7z $QTDIR/include # cd $QTDIR/include # ./put_private.sh # for qtmodule_p in *_private.7z do qtmodule=${qtmodule_p/_p*/} echo "Putting private headers into $qtmodule" mkdir -p $qtmodule/private 7z x $qtmodule_p -o$qtmodule/private -y done

最后附上我编译好的一些qt库 http://code.google.com/p/qtbuild/downloads/list