coolreader.SlackBuild 7.4 KB

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