summaryrefslogtreecommitdiff
path: root/games/xu4/xu4.SlackBuild
blob: 443875df22dee50387361533279bc756bde392f3 (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash

# Slackware build script for xu4

# Written by B. Watson (yalhcru@gmail.com)

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

# 20211012 bkw: BUILD=3,
# - new-style icon.
# - binary in /usr/games.
# - man page in section 6.
# - disable Alt-x keystroke (it crashes the game).
# - "Press Alt-x to quit" => "Close window to quit".

# TODO: make Alt-x stop crashing the game. It seems to work correctly
# only at the main menu, not while playing. Disabled it for now.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=xu4
VERSION=${VERSION:-20130612_svn}
BUILD=${BUILD:-3}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

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

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

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
tar xvf $CWD/$PRGNAM-$VERSION.tar.xz
cd $PRGNAM-$VERSION
chown -R root:root .
find -L .  -perm /111 -a \! -perm 755 -a -exec chmod 755 {} \+ -o \
        \! -perm /111 -a \! -perm 644 -a -exec chmod 644 {} \+

# There actually are some executables in the lib dir. If there hadn't
# been, I would have left it as /usr/lib even on 64-bit, or better yet
# change to /usr/share. As it is, it has to be /usr/lib64 on 64-bit.
LIBDIR=/usr/lib$LIBDIRSUFFIX
PKGLIBDIR=$PKG/$LIBDIR

# Fix path to "profiles/" dir used by -p option. Patch makes it use
# ~/.xu4/profiles/ rather than ./profiles off the current dir.
patch -p1 < $CWD/profile_path.diff

# Fix hard-coded libdir. Ugh.
sed -i -e "s,/usr/lib,$LIBDIR," src/u4file.cpp

# Stop u4 from writing border.png in the current dir (it never *reads* it!)
sed -i -e '/border\.png/s,^,//,' src/imagemgr.cpp

# The libxml2 in Slack 14.2 is pickier than the one in 14.1, and fails to
# validate the game's XML files. So:
sed -i '/#define *DEFAULT_VALIDATE_XML/s,1,0,' src/settings.h

# Patch for GCC 7
patch -p1 < $CWD/gcc7.patch

# 20211012 bkw: work around a bug. Disable Alt-X as it crashes the
# game. Tell the user to close the window to quit, instead.
patch -p1 < $CWD/disable_alt_x.diff

# The -DNPERF stops u4 from creating a debug/ in the current dir.
make -C src DEBUGCXXFLAGS="-DNPERF $SLKCFLAGS" prefix=/usr libdir=$PKGLIBDIR
make -C src install prefix=$PKG/usr bindir=$PKG/usr/games libdir=$PKGLIBDIR

find $PKG | xargs file | grep -e "executable" -e "shared object" | grep ELF \
  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true

# If we have the official release rather than the "dragon" one, repackage
# it with the same layout as the dragon release. Note that the official
# release isn't the default because there's no direct download link for
# the .info file (the site requires javascript + registration).
if [ -e $CWD/UltimaIV.zip ]; then
  sh $CWD/repackage.sh $CWD/UltimaIV.zip
fi

# The game data. This is the zip file, not the self-extracting exe (the
# exe lacks the documentation, for one thing).
cat $CWD/ultima4.zip > $PKGLIBDIR/u4/ultima4.zip

# Replace stock .desktop file with one that validates.
cat $CWD/u4.desktop > $PKG/usr/share/applications/u4.desktop

# These files should be (but aren't) installed by "make install". Without
# them, we get no music!
install -m0644 mid/*.it $PKGLIBDIR/u4/music/

# Remove execute permission from data files. Grr.
chmod 644 $PKG/usr/share/pixmaps/* $PKG/usr/share/applications/*
find $PKGLIBDIR \
  -type f -a \
  \( -name \*.mid -o -name \*.vga -o -name \*.png -o \
     -name \*.xml -o -name \*.dtd -o -name \*.ogg \) \
  -print0 | xargs -0 chmod 644

# 20211012 bkw: new-style icon...
for i in $CWD/icons/*.png; do
  px=$( basename $i | cut -d. -f1 )
  size=${px}x${px}
  dir=$PKG/usr/share/icons/hicolor/$size/apps
  mkdir -p $dir
  cat $i > $dir/u4.png
done

rm -f $PKG/usr/share/pixmaps/u4.png
ln -s ../icons/hicolor/64x64/apps/u4.png $PKG/usr/share/pixmaps/u4.png

# Docs. N.B. we don't need border.png.
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION/developers
cp -a *.html AUTHORS COPYING README $PKG/usr/doc/$PRGNAM-$VERSION
cp -a doc/* $PKG/usr/doc/$PRGNAM-$VERSION/developers
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

# Include the upgrade (and extract its docs) if we have it.
if [ -e $CWD/u4upgrad.zip ]; then
  cat $CWD/u4upgrad.zip > $PKGLIBDIR/u4/u4upgrad.zip
  cd $PKG/usr/doc/$PRGNAM-$VERSION
  unzip $CWD/u4upgrad.zip Readme.txt
  mv Readme.txt Readme-Upgrade.txt
  cd -
fi

# Include the PDF docs, if we have them.
if [ -e $CWD/ultima4_scanned_docs.zip ]; then
  mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION/pdf
  cd $PKG/usr/doc/$PRGNAM-$VERSION/pdf
  unzip $CWD/ultima4_scanned_docs.zip '*.pdf'
  mv ultima4_scanned_docs/Ultima_IV_-_Cluebook_-_PC.pdf Hints.pdf
  mv ultima4_scanned_docs/Ultima_IV_-_Manual_-_PC.pdf History.pdf
  mv ultima4_scanned_docs/Ultima_IV_-_Spellbook_-_PC.pdf Wisdom.pdf
  rm -rf ultima4_scanned_docs
  cd -
fi

# Include the original Ultima IV docs.
cd $PKG/usr/doc/$PRGNAM-$VERSION
unzip $CWD/ultima4.zip '*.txt' '*.doc' '*.bmp' '*.jpg' || true

# These docs only apply to running the original game on DOS or Windows. Bye.
rm -f Readme.txt Readme.doc

# The Word versions of the docs don't really offer much improvement
# over the plain text ones, but here they are.
mkdir ms_word_docs
mv *.doc ms_word_docs

# Fix permissions and line endings.
[ -e Map.bmp ] && chmod 644 Map.bmp
[ -e Map.jpg ] && chmod 644 Map.jpg
chmod 644 *.txt ms_word_docs/*.doc
sed -i 's/\r//' *.txt
cd -

# I hate packages called "xfoo" whose binaries are called "foo".
ln -s u4 $PKG/usr/games/$PRGNAM

# I also hate binaries that take options but have no man pages, so here's
# the one I made. Enjoy.
mkdir -p $PKG/usr/man/man6
sed "s/@VERSION@/$VERSION/" $CWD/u4.6 | gzip -9c - > $PKG/usr/man/man6/u4.6.gz
ln -s u4.6.gz $PKG/usr/man/man6/$PRGNAM.6.gz

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

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