downloadAndCrossCompile.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #!/bin/bash
  2. # Copyright (C) 2013 Tomasz Olszak <olszak.tomasz@gmail.com>
  3. # All rights reserved.
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. # 1. Redistributions of source code must retain the copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # 2. Redistributions in binary form must reproduce the copyright
  10. # notice, this list of conditions and the following disclaimer in the
  11. # documentation and/or other materials provided with the distribution.
  12. # 3. The name of the author may not be used to endorse or promote products
  13. # derived from this software without specific prior written permission.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. #
  26. set -e
  27. if [ -z "$TIZEN_VERSION" -o -z "$COMPILER_DIRNAME" -o -z "$COMPILER_PREFIX" \
  28. -o -z "$DEVICE" ]; then
  29. echo "You must set all obligatory input variables: TIZEN_VERSION, COMPILER_DIRNAME, COMPILER_PREFIX, DEVICE"
  30. fi
  31. set +e
  32. isEmulator=$(echo $DEVICE | grep -c emulator)
  33. set -e
  34. export TIZEN_VERSION
  35. if [ "$isEmulator" == "1" ]; then
  36. export CROSS_COMPILE_FOR=emulator
  37. else
  38. export CROSS_COMPILE_FOR=device
  39. fi
  40. function usage {
  41. echo -e "\n"
  42. echo "Script for Qt for tizen compilation. "
  43. echo "Set Parameters or environment variables with absolute paths"
  44. echo ""
  45. echo "Usage:"
  46. echo "sudo [MAKE_THREADS=numberOfCPUCores] STANDARD_USER=$USER [TIZENSDKCOMPILERDIR=tizen/compiler] [TIZENSYSROOT=tizenSysroot] [HOSTPREFIX=qtHostInstallDir] ./downloadAndBuildAll.sh"
  47. echo ""
  48. echo "STANDARD_USER - your standard user, without superuser privileges"
  49. echo "TIZENSDKCOMPILERDIR - should be set to tizen-sdk/tools/$COMPILER_DIRNAME "
  50. echo "QT5SRCDIR - directory with qt5 sources"
  51. echo "TIZENSYSROOT - sysroot created from emulator devel headers and libraries - by default qt will be installed in \$TIZENSYSROOT/opt/usr/qt5"
  52. echo "HOSTPREFIX - here qmake and other host binaries will be installed"
  53. echo "If you want to download qt source, tizen packages and autoomatically build just pass STANDARD_USER as first parameter(\$USER)"
  54. echo "If corresponding environment variables are set then script can be invoked without parameters"
  55. echo "set MAKE_THREADS environment variable to number of your CPU cores to fast up compilation step"
  56. echo ""
  57. cd $CURRENT_DIR
  58. exit 0;
  59. }
  60. if [ "$1" == "-h" -o "$1" == "--help" ]; then
  61. usage
  62. fi
  63. CURRENT_USER=$(whoami)
  64. if [ $CURRENT_USER != "root" ]; then
  65. echo "run this script with superuser privileges"
  66. usage
  67. fi
  68. if [ "$STANDARD_USER" == "" ]; then
  69. echo "STANDARD_USER variable was not set"
  70. usage
  71. fi
  72. set +e
  73. type rpm2cpio &> /dev/null
  74. if [ "$?" != "0" ]; then
  75. echo "rpm2cpio is needed for creating rootfs - install rpm2cpio"
  76. exit 1
  77. fi
  78. type cpio &> /dev/null
  79. if [ "$?" != "0" ]; then
  80. echo "cpio is needed for creating rootfs - install cpio"
  81. exit 1
  82. fi
  83. id $STANDARD_USER &> /dev/null
  84. if [ "$?" != "0" ]; then
  85. echo "there is no user $STANDARD_USER in the system"
  86. exit 1
  87. fi
  88. set -e
  89. if [ "$TIZENSDKCOMPILERDIR" == "" ]; then
  90. if [ -f $HOME/tizen-sdk/tools/$COMPILER_DIRNAME/bin/$COMPILER_PREFIX-g++ ]; then
  91. TIZENSDKCOMPILERDIR=$HOME/tizen-sdk/tools/$COMPILER_DIRNAME
  92. echo "Setting TIZENSDKCOMPILERDIR to $TIZENSDKCOMPILERDIR"
  93. fi
  94. fi
  95. if [ "$TIZENSYSROOT" == "" ]; then
  96. TIZENSYSROOT=$PWD/rootfs
  97. echo "Setting TIZENSYSROOT to $TIZENSYSROOT"
  98. fi
  99. if [ "$QT5SRCDIR" == "" ]; then
  100. QT5SRCDIR=$PWD/qt5.gitorious
  101. echo "Setting QT5SRCDIR to $QT5SRCDIR"
  102. fi
  103. if [ "$HOSTPREFIX" == "" ]; then
  104. HOSTPREFIX=$PWD/qt5hostInstall
  105. echo "Setting HOSTPREFIX to $HOSTPREFIX"
  106. fi
  107. if [ -z "$STANDARD_USER" -o -z "$QT5SRCDIR" -o -z "$TIZENSYSROOT" \
  108. -o -z "$TIZENSDKCOMPILERDIR" -o -z "$HOSTPREFIX" ]; then
  109. usage
  110. fi
  111. if [ "$TIZENSYSROOT" == "$PWD/rootfs" ]; then
  112. if [ ! -d repos ]; then
  113. echo "getting tizen repositories"
  114. su -m -l $STANDARD_USER -c "../common/download_repos.sh"
  115. fi
  116. mkdir -p rootfs
  117. if [ ! -d rootfs/usr/lib ]; then
  118. cd rootfs
  119. for rpmFile in `find ../repos -name "*.rpm"`;
  120. do
  121. rpm2cpio $rpmFile | cpio -imdv -R $STANDARD_USER:$STANDARD_USER;
  122. done
  123. cd ..
  124. else
  125. echo "Looks like rootfs is already prepared - rootfs/usr/lib exists"
  126. fi
  127. fi
  128. if [ "$QT5SRCDIR" == "$PWD/qt5.gitorious" ]; then
  129. if [ ! -d qt5.gitorious ]; then
  130. su $STANDARD_USER -c "git clone -b release https://git.gitorious.org/qt/qt5.git qt5.gitorious"
  131. cd qt5.gitorious
  132. su $STANDARD_USER -c "git clone -b wip/tizen https://git.gitorious.org/qt/qtquickcontrols-tizen.git"
  133. su $STANDARD_USER -c "./init-repository --http --no-webkit --module-subset=qtactiveqt,qtbase,qtdeclarative,qtdoc,qtgraphicaleffects,qtimageformats,qtjsbackend,qtmultimedia,qtquickcontrols,qtsensors,qtserialport,qtsvg,qttools,qttranslations,qtxmlpatterns"
  134. cd qtquickcontrols
  135. su $STANDARD_USER -c "git checkout wip/tizen"
  136. cd ../
  137. cd qtbase
  138. su $STANDARD_USER -c "git checkout wip/tizen"
  139. cd ../../
  140. else
  141. echo "Looks like qt5.gitorious directory exists"
  142. fi;
  143. fi;
  144. su $STANDARD_USER -c "mkdir -p buildQt5"
  145. cd buildQt5
  146. echo "================================================="
  147. echo "Configuration:"
  148. echo "STANDARD_USER=$STANDARD_USER"
  149. echo "QT5SRCDIR=$QT5SRCDIR"
  150. echo "TIZENSYSROOT=$TIZENSYSROOT"
  151. echo "TIZENSDKCOMPILERDIR=$TIZENSDKCOMPILERDIR"
  152. echo "HOSTPREFIX=$HOSTPREFIX"
  153. echo "================================================="
  154. export PKG_CONFIG_LIBDIR=$TIZENSYSROOT/usr/lib
  155. export PKG_CONFIG_SYSROOT_DIR=$TIZENSYSROOT
  156. export PKG_CONFIG_PATH=$TIZENSYSROOT/usr/lib/pkgconfig
  157. su $STANDARD_USER -c "$QT5SRCDIR/configure -hostprefix $HOSTPREFIX -v \
  158. -release -opengl es2 -opensource \
  159. -confirm-license -device $DEVICE \
  160. -device-option CROSS_COMPILE=$TIZENSDKCOMPILERDIR/bin/$COMPILER_PREFIX- \
  161. -prefix /opt/usr/apps/Qt5Install -sysroot $TIZENSYSROOT -nomake examples \
  162. -qpa xcb -system-libpng -qt-xcb -no-widgets -no-eglfs -no-pch -no-sql-mysql"
  163. MAKE_ARGS=""
  164. if [ "$MAKE_THREADS" != "" ]; then
  165. echo "setting make thread"
  166. MAKE_ARGS="-j $MAKE_THREADS"
  167. fi
  168. echo make $MAKE_ARGS
  169. su $STANDARD_USER -c "make $MAKE_ARGS"
  170. echo make install $MAKE_ARGS
  171. su $STANDARD_USER -c "make install $MAKE_ARGS"
  172. if [ -d $QT5SRCDIR/qtquickcontrols-tizen ]; then
  173. su $STANDARD_USER -c "mkdir -p qtquickcontrols-tizen"
  174. cd qtquickcontrols-tizen
  175. su $STANDARD_USER -c "$HOSTPREFIX/bin/qmake $QT5SRCDIR/qtquickcontrols-tizen"
  176. su $STANDARD_USER -c "make $MAKE_ARGS"
  177. su $STANDARD_USER -c "make install $MAKE_ARGS"
  178. fi