coolreader.SlackBuild 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #!/bin/bash
  2. # Slackware build script for CoolReader
  3. # Copyright 2011-2012 Fridrich von Stauffenberg <email removed>
  4. # Copyright 2020 B. Watson <urchlay@slackware.uk>
  5. # All rights reserved.
  6. #
  7. # Redistribution and use of this script, with or without modification, is
  8. # permitted provided that the following conditions are met:
  9. #
  10. # 1. Redistributions of this script must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. #
  13. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
  14. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  16. # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  19. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  20. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  21. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  22. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. # 20230111 bkw: BUILD=2, just to force a rebuild after libunibreak
  24. # update to 5.1.
  25. # 20220218 bkw: update for v3.2.59. To get it to build, had to disable
  26. # unrar support... which didn't exist in v3.2.57, so nobody will miss
  27. # it, I hope. Also, wxWidgets support fails to build, so that's now
  28. # disabled (and removed from the README).
  29. # 20210930 bkw: update for v3.2.57. This is not the latest release, but
  30. # 3.2.58 fails to build. Will revisit when the next release happens. If
  31. # you can't wait that long, send me a patch (does anyone even use this?)
  32. # - remove fribidi from DOWNLOAD, -current's is new enough now.
  33. # - remove libunibreak from DOWNLOAD, add to REQUIRES (SBo's libunibreak
  34. # is now new enough to use for coolreader).
  35. # - drop QT (qt4) GUI option since qt4's not on SBo (yet?).
  36. # - wxGTK3 build no longer works, for GUI=wx require wxPython 2.8.
  37. # 20210222 bkw: update for v3.2.54. Upstream no longer ships libunibreak
  38. # and fribidi source, so add them to DOWNLOAD. Replace qt4_settings_ui.diff
  39. # with a more robust sed command. Add -fpermissive. Sigh.
  40. # 20201102 bkw:
  41. # - update for v3.2.50.
  42. # - embiggen the default window size.
  43. # - make standard (since the 1980s!) keyboard accelerators work
  44. # (alt-f for file menu, alt-v for view, etc), in the qt4/5 UIs.
  45. # 20201019 bkw:
  46. # - update for v3.2.49, new homepage.
  47. # - allow for building qt4, qt5, wx UIs.
  48. # - replace useless/inaccurate man page with our own.
  49. # 20200126 bkw, BUILD=2:
  50. # - take over maintenance
  51. # - i486 => i586
  52. # - make .desktop file validate
  53. # - fix documetn => document typo
  54. # - add supported filetypes to README and slack-desc
  55. # - save/load settings (.ini file) to ~/.cr3, not /usr/share/cr3.
  56. cd $(dirname $0) ; CWD=$(pwd)
  57. PRGNAM=coolreader
  58. VERSION=${VERSION:-3.2.59}
  59. BUILD=${BUILD:-2}
  60. TAG=${TAG:-_SBo}
  61. PKGTYPE=${PKGTYPE:-tgz}
  62. if [ -z "$ARCH" ]; then
  63. case "$( uname -m )" in
  64. i?86) ARCH=i586 ;;
  65. arm*) ARCH=arm ;;
  66. *) ARCH=$( uname -m ) ;;
  67. esac
  68. fi
  69. if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  70. echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  71. exit 0
  72. fi
  73. TMP=${TMP:-/tmp/SBo}
  74. PKG=$TMP/package-$PRGNAM
  75. OUTPUT=${OUTPUT:-/tmp}
  76. if [ "$ARCH" = "i586" ]; then
  77. SLKCFLAGS="-O2 -march=i586 -mtune=i686"
  78. LIBDIRSUFFIX=""
  79. elif [ "$ARCH" = "i686" ]; then
  80. SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  81. LIBDIRSUFFIX=""
  82. elif [ "$ARCH" = "x86_64" ]; then
  83. SLKCFLAGS="-O2 -fPIC"
  84. LIBDIRSUFFIX="64"
  85. else
  86. SLKCFLAGS="-O2"
  87. LIBDIRSUFFIX=""
  88. fi
  89. set -e
  90. rm -rf $PKG
  91. mkdir -p $TMP $PKG $OUTPUT
  92. cd $TMP
  93. rm -rf $PRGNAM-cr$VERSION
  94. tar xvf $CWD/$PRGNAM-cr$VERSION.tar.gz
  95. cd $PRGNAM-cr$VERSION
  96. find -L . -perm /111 -a \! -perm 755 -a -exec chmod 755 {} \+ -o \
  97. \! -perm /111 -a \! -perm 644 -a -exec chmod 644 {} \+
  98. # FFS, it's 2020, we don't need GUI apps hardcoded to start at
  99. # 640x400 window size. Honestly we don't need them hardcoded at
  100. # all, but since that's what coolreader does, pick a size that's
  101. # bigger than a 3x5" index card on a modern screen...
  102. sed -i 's,\(<height>\)400,\11024,' cr3qt/src/mainwindow.ui
  103. sed -i 's,\(<width>\)600,\11280,' cr3qt/src/mainwindow.ui
  104. # Install the docs in the right place for Slackware.
  105. sed -i "s,share/doc/cr3,doc/$PRGNAM-$VERSION," cr3qt/CMakeLists.txt
  106. # The settings sed for qt4 was made by loading cr3qt/src/settings.ui
  107. # into Qt Designer and saving it again. Needed because upstream's
  108. # using a different (older?) version of qt4.
  109. if true; then
  110. # 20220218 bkw: only the qt5 UI works in 3.2.59, sorry.
  111. GUI=QT5
  112. UI=Qt5
  113. else
  114. # 20220218 bkw: wxWidgets is broken (for either 2.8 or 3.0),
  115. # this section of code can't run, it's left for reference.
  116. GUI=${GUI:-QT5}
  117. GUI="$( echo $GUI | tr a-z A-Z )"
  118. case "$GUI" in
  119. # 20210930 bkw: Qt4 disabled for now, unless/until SBo gets a qt4 build.
  120. #QT) UI=Qt4
  121. #sed -i '/<property name="currentText"/s,>, stdset="0">,' cr3qt/src/settings.ui
  122. #;;
  123. QT5) UI=Qt5 ;;
  124. WX) # Only 2.8.x works, be specific in the slack-desc.
  125. UI="wxWidgets 2.8"
  126. SLKCFLAGS+=" $( wx-config --version=2.8 --cflags )"
  127. SLKLDFLAGS="$( wx-config --version=2.8 --libs )" ;;
  128. *) echo "*** Unsupported GUI '$GUI', use one of: QT5 WX"
  129. exit 1 ;;
  130. esac
  131. fi
  132. # 20201103 bkw: Alt+F for the File menu, Alt+V for View, etc. This
  133. # has been a UI standard since before Windows 1.0 (MS-DOS apps had it),
  134. # and I'm not sure why upstream didn't include it. Only affects the
  135. # Qt4/5 UIs. Incomplete: you can't press Alt+F followed by O for
  136. # File -> Open... but you can use the arrow keys to navigate the
  137. # menus once one of them has been opened.
  138. sed -i 's,>\(File\|View\|Navigation\|Help\)<,>\&amp;\1<,' \
  139. cr3qt/src/mainwindow.ui
  140. # This is undocumented and exists purely for my own use. It gets rid
  141. # of the "Escape = minimize" keystroke, because I keep expecting Escape
  142. # to exit (like 3 or 4 other document readers I use regularly).
  143. # Only affects the Qt4/5 UIs.
  144. if [ "${NO_ESCAPE:-no}" = "yes" ]; then
  145. echo "=== Activating super-secret Urchlay mode"
  146. echo -e 'g/>Esc<\n-1,+1d\nw\nq' | ed cr3qt/src/mainwindow.ui
  147. fi
  148. echo "=== Building $UI GUI"
  149. mkdir -p build
  150. cd build
  151. cmake \
  152. -D CMAKE_EXE_LINKER_FLAGS="$SLKLDFLAGS" \
  153. -D USE_UNRAR=1 \
  154. -D CMAKE_C_FLAGS:STRING="$SLKCFLAGS" \
  155. -D CMAKE_CXX_FLAGS:STRING="$SLKCFLAGS -fpermissive" \
  156. -D CMAKE_INSTALL_PREFIX=/usr \
  157. -D LIB_SUFFIX=${LIBDIRSUFFIX} \
  158. -D CMAKE_BUILD_TYPE=Release \
  159. -D MAX_IMAGE_SCALE_MUL=2 \
  160. -D DOC_DATA_COMPRESSION_LEVEL=3 \
  161. -D DOC_BUFFER_SIZE=0x1400000 \
  162. -U USE_UNRAR \
  163. -D GUI=$GUI ..
  164. make VERBOSE=1
  165. make install/strip DESTDIR=$PKG
  166. cd ..
  167. # Upstream's man page doesn't document all the options, and incorrectly
  168. # refers to the (nonexistent) info page. It's also hardcoded to install
  169. # to /usr/share/man.
  170. rm -rf $PKG/usr/share/man
  171. mkdir -p $PKG/usr/man/man1
  172. gzip -9c < $CWD/cr3.1 > $PKG/usr/man/man1/cr3.1.gz
  173. # Tired of having to remember the binary's called something other than
  174. # the package and source name.
  175. ln -s cr3 $PKG/usr/bin/$PRGNAM
  176. ln -s cr3.1.gz $PKG/usr/man/man1/$PRGNAM.1.gz
  177. # This dir already exists with GUI=QT or QT5, but not WX.
  178. mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
  179. cp -a README.md cr3gui/COPYING $PKG/usr/doc/$PRGNAM-$VERSION
  180. cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
  181. mkdir -p $PKG/install
  182. sed "s,@UI@,$UI," $CWD/slack-desc > $PKG/install/slack-desc
  183. cat $CWD/doinst.sh > $PKG/install/doinst.sh
  184. cd $PKG
  185. /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE