static-build.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/bin/bash
  2. # This file is part of wkhtmltopdf.
  3. #
  4. # wkhtmltopdf is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # wkhtmltopdf is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with wkhtmltopdf. If not, see <http:#www.gnu.org/licenses/>.
  16. # This script will compile static versions of wkhtmltopdf for linux and for windows (it must run in linux)
  17. # It requires build-essential and wine to run. Please note that it will take quite a while
  18. #Configuration for the static build
  19. QT=qt-all-opensource-src-4.5.1
  20. MIRROR=kent
  21. MINGWFILES="binutils-2.19.1-mingw32-bin.tar.gz mingw32-make-3.81-20080326-3.tar.gz \
  22. gcc-g++-3.4.5-20060117-3.tar.gz gcc-core-3.4.5-20060117-3.tar.gz w32api-3.13-mingw32-dev.tar.gz \
  23. mingwrt-3.15.2-mingw32-dev.tar.gz mingwrt-3.15.2-mingw32-dll.tar.gz"
  24. OPENSSL=openssl-0.9.8h-1-lib.zip
  25. UPX=upx-3.03-i386_linux
  26. #Helper functions
  27. function get() {
  28. [ -f $2.download ] || (rm -rf $2; wget $1 -O $2 && touch $2.download)
  29. }
  30. function unpack() {
  31. [ -f $1.unpack ] || (echo "unpacking $1"; (tar -xf $1 || unzip $1) && touch $1.unpack)
  32. }
  33. function applypatch() {
  34. cmp $1 $2 && return 0;
  35. [ -f $2 ] && patch -R -p1 < $2;
  36. patch -p1 < $1 && cp $1 $2;
  37. }
  38. function exportHere() {
  39. rm -rf wkhtmltopdf
  40. local HERE=${PWD}
  41. cd $BASE || exti 1
  42. git checkout-index --prefix=${HERE}/wkhtmltopdf/ -a -f || exit 1
  43. cd $HERE
  44. }
  45. BUILD=/tmp/build
  46. #Create static build directory
  47. mkdir -p $BUILD
  48. cat ./src/qt-patches/qt-*.patch > $BUILD/qt.patch
  49. cat static_qt_conf_base static_qt_conf_win | sed -re 's/#.*//' | sed -re '/^[ \t]*$/d' | sort -u > $BUILD/conf_win
  50. cat static_qt_conf_base static_qt_conf_linux | sed -re 's/#.*//' | sed -re '/^[ \t]*$/d' | sort -u > $BUILD/conf_linux
  51. BASE=${PWD}
  52. cd ${BUILD}
  53. #Fetch most recent version of qt
  54. get http://download.qtsoftware.com/qt/source/${QT}.tar.bz2 $QT.tar.bz2 || exit 1
  55. #Fetch and unpack upx
  56. get http://upx.sourceforge.net/download/${UPX}.tar.bz2 ${UPX}.tar.bz2 || exit 1
  57. unpack ${UPX}.tar.bz2 || exit 1
  58. if [[ "$1" == "all" ]] || [[ "$1" == "linux" ]]; then
  59. cd ${BUILD}
  60. mkdir -p linux
  61. cd linux
  62. ln -s ${BUILD}/${QT}.tar.bz2 .
  63. unpack ${QT}.tar.bz2 || exit 1
  64. cd ${QT}
  65. if ! cmp ${BUILD}/conf_linux conf_linux; then
  66. (yes yes | ./configure `cat ${BUILD}/conf_linux` -prefix "${BUILD}/linux/qt" && cp ${BUILD}/conf_linux conf_linux) || exit 1
  67. fi
  68. applypatch ${BUILD}/qt.patch qt.patch || exit 1
  69. if ! make -j5 -q; then
  70. make -j5 || exit 1
  71. make install || exit 1
  72. fi
  73. cd ..
  74. exportHere
  75. cd wkhtmltopdf
  76. ../qt/bin/qmake || exit 1
  77. make -j5 || exit 1
  78. strip wkhtmltopdf || exit 1
  79. rm -rf ${BASE}/wkhtmltopdf
  80. ${BUILD}/${UPX}/upx --best wkhtmltopdf -o ${BASE}/wkhtmltopdf || exit 1
  81. fi
  82. if [[ "$1" == "all" ]] || [[ "$1" == "win" ]]; then
  83. export WINEPREFIX=`pwd`/mingw
  84. #Setup configuration for mingw
  85. ln -s / "mingw/dosdevices/z:"
  86. cat <<EOF > tmp
  87. REGEDIT4
  88. [HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment]
  89. "PATH"="C:\\\\windows;C:\\\\windows\\\\system32;C:\\\\mingw\\\\bin"
  90. "INCLUDE"="C:\\\\mingw\\\\include;C:\\\\mingw\\\\include\\\\c++\\\\3.4.5"
  91. "LIB"="C:\\\\mingw\\\\lib"
  92. EOF
  93. wine regedit tmp || exit 1
  94. rm -f tmp
  95. #Allowing the build to access files in the unix fs, is a bad idee.
  96. rm -rf "mingw/dosdevices/z:"
  97. echo "Building windows vertion of qt"
  98. #Install mingw
  99. mkdir -p mingw/drive_c/mingw
  100. cd mingw/drive_c/mingw
  101. for file in ${MINGWFILES}; do
  102. get http://${MIRROR}.dl.sourceforge.net/sourceforge/mingw/${file} ${file} || exit 1
  103. unpack ${file} || exit 1
  104. done
  105. get http://downloads.sourceforge.net/gnuwin32/${OPENSSL} ${OPENSSL} || exit 1
  106. unpack ${OPENSSL} || exit 1
  107. #Unpack, configure and build windows qt
  108. unset CPLUS_INCLUDE_PATH
  109. unset C_INCLUDE_PATH
  110. cd ${BUILD}/mingw/drive_c
  111. ln -s ${BUILD}/${QT}.tar.bz2 .
  112. unpack ${QT}.tar.bz2 || exit 1
  113. mkdir -p qt
  114. cp -r ${QT}/mkspecs qt
  115. cd ${QT}
  116. if ! cmp ${BUILD}/conf_win conf_win; then
  117. (yes | wine configure.exe `cat ${BUILD}/conf_win` -prefix "C:\qt" && cp ${BUILD}/conf_win conf_win) || exit 1
  118. fi
  119. applypatch ${BUILD}/qt.patch qt.patch || exit 1
  120. if ! wine mingw32-make -j5 -q; then
  121. wine mingw32-make -j5 || exit 1
  122. wine mingw32-make install || exit 1
  123. fi
  124. cd ..
  125. exportHere
  126. cd wkhtmltopdf
  127. wine ../qt/bin/qmake.exe wkhtmltopdf.pro -o Makefile -spec win32-g++ || exit 1
  128. wine mingw32-make -j5 || exit 1
  129. wine strip.exe release/wkhtmltopdf.exe || exit 1
  130. rm -rf ${BASE}/wkhtmltopdf.exe
  131. ${BUILD}/${UPX}/upx --best release/wkhtmltopdf.exe -o ${BASE}/wkhtmltopdf.exe || exit 1
  132. fi
  133. if [[ "$1" != "all" ]] && [[ "$1" != "linux" ]] && [[ "$1" != "win" ]]; then
  134. echo "please specify what static binary you want build (linux, win or all)"
  135. exit 1
  136. fi