summaryrefslogtreecommitdiffstats
path: root/office/mupdf/mupdf.SlackBuild
blob: bccd04f5cbfb5e2a2caa890f740deae2ee14dcdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/sh

# Slackware build script for mupdf

# Originally written by Hubert Hesse (email removed).
# Heavily modified by B. Watson (yalhcru@gmail.com).

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

# 20180623 bkw: BUILD=2, add patch for dynamic linking. Thanks
#               to Thomas Morper for pointing me in the right direction.
# 20180615 bkw: update for 1.13.0, move old change comments to ChangeLog.old
# 20180101 bkw: update for 1.12.0.
# 20170711 bkw: update for 1.11.
# 20170621 bkw: fix build with -current's newer openjpeg, BUILD=2.
# 20170122 bkw: update for 1.10a.

PRGNAM=mupdf
VERSION=${VERSION:-1.13.0}
BUILD=${BUILD:-2}
TAG=${TAG:-_SBo}

if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i586 ;;
    arm*) ARCH=arm ;;
       *) ARCH=$( uname -m ) ;;
  esac
fi

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

if [ "$ARCH" = "i586" ]; then
  SLKCFLAGS="-O2 -march=i586 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
else
  SLKCFLAGS="-O2"
  LIBDIRSUFFIX=""
fi
set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION-source
tar xvf $CWD/$PRGNAM-$VERSION-source.tar.gz
cd $PRGNAM-$VERSION-source

# don't find/chown/chmod until after the thirdparty junk is removed.

# Build against system libs instead of bundled ones. If we didn't do this,
# libmupdf would be useless for building anything else.

# Everything removed from thirdparty/ has to be installed systemwide, and must
# either be a Slackware core pkg, or mentioned in REQUIRES= in the .info
# file... except mujs, which is mupdf's javascript support lib. If missing,
# we end up with a mupdf with no JS support, which is probably a good idea
# for the default build. If you want javascript, MUJS=yes in the env.

MUJS="${MUJS:-no}"

if [ "$MUJS" = "yes" ]; then
  mv thirdparty/mujs .keep
  rm -rf thirdparty/*
  mv .keep thirdparty/mujs
  WITH=with
else
  rm -rf thirdparty/*
  sed -i 's,murun\.o,,' Makefile
  sed -i 's,pdf_drop_js.*,;,' source/pdf/pdf-xref.c
  sed -i '/murun_main/d' source/tools/mutool.c
  WITH=without
fi

chown -R root:root .
find -L . \
 \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 -o -perm 511 \) \
 -exec chmod 755 {} \+ -o \
 \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \
 -exec chmod 644 {} \+

# ref https://bugs.ghostscript.com/show_bug.cgi?id=697175
sed -i '/#define *OPJ_STATIC/d' source/fitz/load-jpx.c

# Hard-code the version number so it'll stop trying to use git to retrieve
# it and spewing harmless but scary 'fatal: Not a git repository' errors.
sed -i "/^VERSION/s,=.*,= $VERSION," Makefile

# 20180623 bkw: Finally, dynamic linking again. Patch is based on
# http://www.linuxfromscratch.org/patches/blfs/svn/mupdf-1.13.0-shared_libs-1.patch
# but I added versioned sonames. See README_shared.txt for the gory details.
STATIC=${STATIC:-no}

if [ "$STATIC" != "yes" ]; then
  patch -p1 < $CWD/shared_libs.diff
  LIBTYPE=shared
else
  LIBTYPE=static
fi

make verbose=yes \
  XCFLAGS="$SLKCFLAGS -DJBIG_NO_MEMENTO" \
  HAVE_MUJS="$MUJS" \
  build=release \
  prefix=/usr \
  libdir=/usr/lib$LIBDIRSUFFIX \
  mandir=/usr/man \
  docdir=/usr/doc/$PRGNAM-$VERSION \
  DESTDIR=$PKG \
  all extra-apps install

# 1.12.0 used to install this stuff with 'make install', 1.13.0 doesn't:
for i in mjsgen muraster mupdf-x11-curl; do
  [ -e build/release/$i ] && install -s -m0755 build/release/$i $PKG/usr/bin
done

strip $PKG/usr/bin/*

find $PKG/usr/man -type f -exec gzip -9 {} \;
for i in $( find $PKG/usr/man -type l ) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done

# Compatibility symlinks. Older versions, the binary is just "mupdf".
# Separate -curl binary exists in 1.5 but not 1.4.
ln -s $PRGNAM-x11 $PKG/usr/bin/$PRGNAM
ln -s $PRGNAM.1.gz $PKG/usr/man/man1/$PRGNAM-x11.1.gz
[ -e $PKG/usr/bin/$PRGNAM-x11-curl ] && \
  ln -s $PRGNAM.1.gz $PKG/usr/man/man1/$PRGNAM-x11-curl.1.gz

# mujstest is useless if we don't have JS support. Also libmupdfthird.a
# ends up 8 bytes long & has no object code in it.
[ "$MUJS" = "yes" ] || \
  rm -f $PKG/usr/bin/mujstest \
        $PKG/usr/lib$LIBDIRSUFFIX/libmupdfthird.a

# Installed permissions are atrocious (everything 755).
find $PKG -type f | xargs chmod 644
chmod 755 $PKG/usr/bin/*
if [ "$STATIC" != "yes" ]; then
  chmod 755 $PKG/usr/lib$LIBDIRSUFFIX/lib*.so.*.*
fi

# .desktop taken from debian and modified:
# - make it validate.
# - add mime types for cbz and xps.
mkdir -p $PKG/usr/share/applications
cat $CWD/$PRGNAM.desktop > $PKG/usr/share/applications/$PRGNAM.desktop

# Icon converted from platform/x11/mupdf.ico, with icotool.
mkdir -p $PKG/usr/share/pixmaps
cat $CWD/$PRGNAM.png > $PKG/usr/share/pixmaps/$PRGNAM.png

# .pc file taken from debian and parameterized.
PCLIBS="-l$PRGNAM -lfreetype -lharfbuzz -ljbig2dec -ljpeg -lcrypto -lopenjp2 -lz -lm"
[ "$MUJS" = "yes" ] && PCLIBS="$PCLIBS -lmupdfthird"

mkdir -p $PKG/usr/lib$LIBDIRSUFFIX/pkgconfig/
sed -e "s,@LIB@,lib$LIBDIRSUFFIX,g" \
    -e "s,@VERSION@,$VERSION,g" \
    -e "s,@PCLIBS@,$PCLIBS,g" \
    $CWD/$PRGNAM.pc > $PKG/usr/lib$LIBDIRSUFFIX/pkgconfig/$PRGNAM.pc

# 'make install' already installed most of the docs.
cp -a CONTRIBUTORS $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

# slack-desc will conveniently say whether javascript is built in,
# and whether libs are shared or static.
mkdir -p $PKG/install
sed -e "s,@WITH@,$WITH," \
    -e "s,@LIBTYPE@,$LIBTYPE," \
    $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}