mupdf.SlackBuild 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. #!/bin/bash
  2. # Slackware build script for mupdf
  3. # Originally written by Hubert Hesse (email removed).
  4. # Heavily modified by B. Watson (urchlay@slackware.uk).
  5. # Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.
  6. # 20230117 bkw: update for 1.21.1.
  7. # - Again, this script can't build older versions.
  8. # - There's a gumbo-parser SlackBuild now, so build with it instead of
  9. # upstream's bundled version.
  10. # - tesseract builds work, so make that an option.
  11. # - Include pre-scaled PNG icons.
  12. # 20201020 bkw: update for 1.18.0. See notes, below.
  13. # 20200217 bkw: update for 1.16.1.
  14. # 20180623 bkw: BUILD=2, add patch for dynamic linking. Thanks
  15. # to Thomas Morper for pointing me in the right direction.
  16. # 20180615 bkw: update for 1.13.0, move old change comments to ChangeLog.old
  17. # 20180101 bkw: update for 1.12.0.
  18. # 20170711 bkw: update for 1.11.
  19. # 20170621 bkw: fix build with -current's newer openjpeg, BUILD=2.
  20. # 20170122 bkw: update for 1.10a.
  21. # Notes for 1.18.0:
  22. # - This script can no longer build older versions, too many changes.
  23. # - Upstream *finally* supports building as a shared library, so I and
  24. # all other distro packagers can stop patching it... except the
  25. # shared lib is unversioned, which means upgrades would cause more
  26. # breakage than they should. So there's still some trickery here to
  27. # build a versioned solib.
  28. # - I've got rid of the STATIC=yes option and now only build shared libs.
  29. # As a side effect, libmupdf-third is gone, but I've included a
  30. # placeholder so stuff that links with it, will work without patching.
  31. # - gumbo (HTML parser) is now a hard dep. The source is bundled, so
  32. # there's no need to create a new gumbo SlackBuild, but it does mean
  33. # the mupdf shared lib has grown in size.
  34. # - mupdf-gl uses freeglut. The version we have in 14.2 is new enough to
  35. # build with, but old enough that you can't copy text from mupdf-gl.
  36. # So we build the bundled version here.
  37. # - API docs are now included in the package.
  38. # - Now using upstream's icons, including scalable SVG.
  39. # - Add missing doinst.sh
  40. # - There's now the option to build with tesseract and leptonica,
  41. # but it's disabled in this script. I have yet to get it to
  42. # actually *do* anything other than fail to build (when using
  43. # upstream's tesseract/leptonica forks) or complain about being
  44. # unable to load eng.traineddata (using SBo tesseract/leptonica,
  45. # and yes eng.traineddata is fine). Until I work out what's wrong,
  46. # or upstream releases a new version, this script doesn't support
  47. # building with tesseract. Don't contact me about this before March
  48. # 1, 2021, unless you actually have a patch that fixes it. After
  49. # that, if this message is still here, feel free to remind me to
  50. # revisit it.
  51. # - Slackware 14.2's libcrypto (from openssl) is too old for mupdf,
  52. # and there's no bundled souce for it. So currently mupdf is being
  53. # built without libcrypto. Hope that's OK.
  54. cd $(dirname $0) ; CWD=$(pwd)
  55. PRGNAM=mupdf
  56. VERSION=${VERSION:-1.21.1}
  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. # Building mupdf seems to work OK if an older version is installed,
  89. # but I only tested 1.21.1 when 1.18.0 was installed (doesn't mean
  90. # it works for all versions).
  91. print_failed_message() {
  92. if pkg-config --exists mupdf; then
  93. cat 1>&2 <<EOF
  94. **************************************************************************
  95. * The build failed. This might have happened because you had an existing *
  96. * (older) mupdf package installed. Run "removepkg mupdf" and try again. *
  97. **************************************************************************
  98. EOF
  99. fi
  100. exit 1
  101. }
  102. # 20230117 bkw: tesseract builds work fine in 1.21.1, but tesseract
  103. # doesn't get autodetected. Help it out a little.
  104. TESS=no
  105. [ "${TESSERACT:-yes}" = "yes" ] && pkg-config --exists tesseract && TESS=yes
  106. rm -rf $PKG
  107. mkdir -p $TMP $PKG $OUTPUT
  108. cd $TMP
  109. rm -rf $PRGNAM-$VERSION-source
  110. tar xvf $CWD/$PRGNAM-$VERSION-source.tar.lz
  111. cd $PRGNAM-$VERSION-source
  112. chown -R root:root .
  113. find -L . -perm /111 -a \! -perm 755 -a -exec chmod 755 {} \+ -o \
  114. \! -perm /111 -a \! -perm 644 -a -exec chmod 644 {} \+
  115. # Hard-code the version number so it'll stop trying to use git to retrieve
  116. # it and spewing harmless but scary 'fatal: Not a git repository' errors.
  117. sed -i "/^VERSION/s,=.*,= $VERSION," Makefile
  118. # As of 1.18.0, we don't actually have to patch the Makefile
  119. # to do a versioned shared lib, but we do have to override some
  120. # variables. SOMAJOR is the mupdf major and zero-padded minor version
  121. # jammed together (e.g. 113 for 1.13.0, 203 for 2.3.0). SOMINOR is the
  122. # mupdf micro version (e.g. 0 for 1.13.0).
  123. SOMAJOR=$(echo $VERSION | cut -d. -f1-2 | sed -e 's,\.[0-9]$,0&,' -e 's,\.,,g')
  124. SOMINOR=$(echo $VERSION | cut -d. -f3- | sed 's,\.,,g' )
  125. SOVER=$SOMAJOR.$SOMINOR
  126. # Build against system libs instead of bundled ones, where possible.
  127. # Upstream recommends using their bundled lcms2 and mujs, I'll go with that.
  128. # Also, we *still* (in Slack 15.0) have to use the bundled freeglut
  129. # to get copy/paste working in mupdf-gl.
  130. # C++ (XCXXFLAGS) is only actually used if building with tesseract.
  131. make verbose=yes \
  132. shared=yes \
  133. LIB_LDFLAGS="-shared -Wl,-soname -Wl,libmupdf.so.$SOMAJOR" \
  134. USE_SYSTEM_LIBS=yes \
  135. USE_SYSTEM_GLUT=no \
  136. tesseract=$TESS \
  137. build=release \
  138. prefix=/usr \
  139. libdir=/usr/lib$LIBDIRSUFFIX \
  140. mandir=/usr/man \
  141. docdir=/usr/doc/$PRGNAM-$VERSION \
  142. DESTDIR=$PKG \
  143. all install || print_failed_message
  144. # bins and libs are already stripped.
  145. gzip -9 $PKG/usr/man/man1/*.1
  146. # 20230117 bkw: fix up the lib dir.
  147. cd $PKG/usr/lib$LIBDIRSUFFIX
  148. # 20230117 bkw: AFAIK, we have to list every shared lib this one
  149. # depends on in the .pc file. This rather odd-looking bit of code
  150. # creates the list.
  151. PCLIBS="-lmupdf $(
  152. objdump -p libmupdf.so | \
  153. perl -ne 'next unless /NEEDED/;
  154. chomp;
  155. s,.* lib([^.]*)\.so.*,\1,;
  156. print "-l$_ " unless /^(c|gcc_s)$/;'
  157. )"
  158. WITHTESS=WITHOUT
  159. echo "$PCLIBS" | grep -q ltesseract && WITHTESS=WITH
  160. echo "==> PCLIBS='$PCLIBS'"
  161. # 20230117 bkw: the library is versioned, but the filename isn't...
  162. chmod 755 libmupdf.so
  163. mv libmupdf.so libmupdf.so.$SOVER
  164. ln -s libmupdf.so.$SOVER libmupdf.so
  165. ln -s libmupdf.so.$SOVER libmupdf.so.$SOMAJOR
  166. # .pc file taken from debian and parameterized.
  167. mkdir -p pkgconfig/
  168. sed -e "s,@LIB@,lib$LIBDIRSUFFIX,g" \
  169. -e "s,@VERSION@,$VERSION,g" \
  170. -e "s,@PCLIBS@,$PCLIBS,g" \
  171. $CWD/$PRGNAM.pc > pkgconfig/$PRGNAM.pc
  172. # Historically, mupdf has included two libraries: libmupdf itself,
  173. # and libmupdf-third, containing all the bundled third party code
  174. # included with the source. In version >=1.18.0, when building a
  175. # shared lib, no libmupdf-third gets created (all the code ends up in
  176. # libmupdf.so). However, most projects that link with libmupdf expect
  177. # this library to exist. This will probably change in the future as
  178. # those projects get updated for the changes in mupdf, but for now,
  179. # to be compatible with older mupdf versions, we include an empty
  180. # libmupdf-third for stuff to link with.
  181. ar crs libmupdf-third.a
  182. cd -
  183. # Compatibility symlinks. Older versions, the binary is just "mupdf".
  184. ln -s $PRGNAM-x11 $PKG/usr/bin/$PRGNAM
  185. for i in x11 x11-curl gl; do
  186. [ -e $PKG/usr/bin/$PRGNAM-$i ] && \
  187. ln -s $PRGNAM.1.gz $PKG/usr/man/man1/$PRGNAM-$i.1.gz
  188. done
  189. # .desktop taken from debian and modified:
  190. # - make it validate.
  191. # - add mime types for cbz and xps.
  192. mkdir -p $PKG/usr/share/applications
  193. cat $CWD/$PRGNAM.desktop > $PKG/usr/share/applications/$PRGNAM.desktop
  194. # Use shipped SVG icon, make PNGs at various sizes.
  195. mkdir -p $PKG/usr/share/pixmaps $PKG/usr/share/icons/hicolor/scalable/apps
  196. svg=docs/logo/mupdf-logo.svg
  197. for i in 16 22 32 48 64 128; do
  198. px=${i}x${i}
  199. dir=$PKG/usr/share/icons/hicolor/$px/apps
  200. mkdir -p $dir
  201. rsvg-convert --width=$i --height=$i -o $dir/$PRGNAM.png $svg
  202. done
  203. cat $svg > $PKG/usr/share/icons/hicolor/scalable/apps/$PRGNAM.svg
  204. ln -s ../icons/hicolor/48x48/apps/$PRGNAM.png $PKG/usr/share/pixmaps/$PRGNAM.png
  205. # 'make install' already installed most of the docs.
  206. cp -a CONTRIBUTORS docs/api $PKG/usr/doc/$PRGNAM-$VERSION
  207. cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
  208. mkdir -p $PKG/install
  209. sed "s,@WITHTESS@,$WITHTESS," < $CWD/slack-desc > $PKG/install/slack-desc
  210. cat $CWD/doinst.sh > $PKG/install/doinst.sh
  211. cd $PKG
  212. /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE