static-build.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 vertions 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. BUILD=/tmp/build
  39. #Create static build directory
  40. mkdir -p $BUILD
  41. cat qt-*.patch > $BUILD/qt.patch
  42. cat static_qt_conf_base static_qt_conf_win | sed -re 's/#.*//' | sed -re '/^[ \t]*$/d' | sort -u > $BUILD/conf_win
  43. cat static_qt_conf_base static_qt_conf_linux | sed -re 's/#.*//' | sed -re '/^[ \t]*$/d' | sort -u > $BUILD/conf_linux
  44. BASE=${PWD}
  45. cd ${BUILD}
  46. #Fetch most the vertion of qt
  47. get http://download.qtsoftware.com/qt/source/${QT}.tar.bz2 $QT.tar.bz2 || exit 1
  48. #Fetch an unpack upx
  49. get http://upx.sourceforge.net/download/${UPX}.tar.bz2 ${UPX}.tar.bz2 || exit 1
  50. unpack ${UPX}.tar.bz2 || exit 1
  51. if [[ "$1" == "all" ]] || [[ "$1" == "linux" ]]; then
  52. cd ${BUILD}
  53. mkdir -p linux
  54. cd linux
  55. ln -s ${BUILD}/${QT}.tar.bz2 .
  56. unpack ${QT}.tar.bz2 || exit 1
  57. cd ${QT}
  58. if ! cmp ${BUILD}/conf_linux conf_linux; then
  59. (yes yes | ./configure `cat ${BUILD}/conf_linux` -prefix "${BUILD}/linux/qt" && cp ${BUILD}/conf_linux conf_linux) || exit 1
  60. fi
  61. applypatch ${BUILD}/qt.patch qt.patch || exit 1
  62. if ! make -j5 -q; then
  63. make -j5 || exit 1
  64. make install || exit 1
  65. fi
  66. cd ..
  67. rm -rf wkhtmltopdf
  68. svn export ${BASE} wkhtmltopdf --force || exit 1
  69. cd wkhtmltopdf
  70. ../qt/bin/qmake || exit 1
  71. make -j5 || exit 1
  72. strip wkhtmltopdf || exit 1
  73. rm -rf ${BASE}/wkhtmltopdf
  74. ${BUILD}/${UPX}/upx --best wkhtmltopdf -o ${BASE}/wkhtmltopdf || exit 1
  75. fi
  76. if [[ "$1" == "all" ]] || [[ "$1" == "win" ]]; then
  77. export WINEPREFIX=`pwd`/mingw
  78. #Setup configuration for mingw
  79. ln -s / "mingw/dosdevices/z:"
  80. cat <<EOF > tmp
  81. REGEDIT4
  82. [HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment]
  83. "PATH"="C:\\\\windows;C:\\\\windows\\\\system32;C:\\\\mingw\\\\bin"
  84. "INCLUDE"="C:\\\\mingw\\\\include;C:\\\\mingw\\\\include\\\\c++\\\\3.4.5"
  85. "LIB"="C:\\\\mingw\\\\lib"
  86. EOF
  87. wine regedit tmp || exit 1
  88. rm -f tmp
  89. #Allowing the build to access files in the unix fs, is a bad idee.
  90. rm -rf "mingw/dosdevices/z:"
  91. echo "Building windows vertion of qt"
  92. #Install mingw
  93. mkdir -p mingw/drive_c/mingw
  94. cd mingw/drive_c/mingw
  95. for file in ${MINGWFILES}; do
  96. get http://${MIRROR}.dl.sourceforge.net/sourceforge/mingw/${file} ${file} || exit 1
  97. unpack ${file} || exit 1
  98. done
  99. get http://downloads.sourceforge.net/gnuwin32/${OPENSSL} ${OPENSSL} || exit 1
  100. unpack ${OPENSSL} || exit 1
  101. #Unpack, configure and build windows qt
  102. unset CPLUS_INCLUDE_PATH
  103. unset C_INCLUDE_PATH
  104. cd ${BUILD}/mingw/drive_c
  105. ln -s ${BUILD}/${QT}.tar.bz2 .
  106. unpack ${QT}.tar.bz2 || exit 1
  107. mkdir -p qt
  108. cp -r ${QT}/mkspecs qt
  109. cd ${QT}
  110. if ! cmp ${BUILD}/conf_win conf_win; then
  111. (yes | wine configure.exe `cat ${BUILD}/conf_win` -prefix "C:\qt" && cp ${BUILD}/conf_win conf_win) || exit 1
  112. fi
  113. applypatch ${BUILD}/qt.patch qt.patch || exit 1
  114. if ! wine mingw32-make -j5 -q; then
  115. wine mingw32-make -j5 || exit 1
  116. wine mingw32-make install || exit 1
  117. fi
  118. cd ..
  119. rm -rf wkhtmltopdf
  120. svn export ${BASE} wkhtmltopdf --force || exit 1
  121. cd wkhtmltopdf
  122. wine ../qt/bin/qmake.exe wkhtmltopdf.pro -o Makefile -spec win32-g++ || exit 1
  123. wine mingw32-make -j5 || exit 1
  124. wine strip.exe release/wkhtmltopdf.exe || exit 1
  125. rm -rf ${BASE}/wkhtmltopdf.exe
  126. ${BUILD}/${UPX}/upx --best release/wkhtmltopdf.exe -o ${BASE}/wkhtmltopdf.exe || exit 1
  127. fi
  128. if [[ "$1" != "all" ]] && [[ "$1" != "linux" ]] && [[ "$1" != "win" ]]; then
  129. echo "please specify what static binary you want build (linux, win or all)"
  130. exit 1
  131. fi