summaryrefslogtreecommitdiff
path: root/games/uqm/uqm.SlackBuild
blob: 9f527f429968bc6239e5af4be10d6ad950434a42 (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
#!/bin/bash

# Slackware build script for uqm

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

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

# 20210304 bkw: update for v0.8.0. script changed a good bit, can't
# build older versions. Note to self: don't mix engine and content
# versions without testing thoroughly! 0.7.0 engine seemed to work
# with 0.8.0 content, but crashed when trying to enter the setup menu!

# 20201025 bkw: update build for new content pack 0.8.0. This mostly
# has fixes for typos in the in-game text strings. The game engine
# hasn't changed, so VERSION now has both versions. Also, moved
# the binary to /usr/games where it belongs.

PRGNAM=uqm
VERSION=${VERSION:-0.8.0}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

# Extract the tarball and content versions. If there's no + in
# VERSION, both these will end up equal to VERSION. Otherwise use a +
# to separate source and content versions (e.g. 0.7.0+0.8.0).
SRCVER=$(  echo $VERSION | sed 's,+.*,,' )
CONTVER=$( echo $VERSION | sed 's,.*+,,' )

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

# Starting with 0.8.0, we have options to use SDL2 and
# OpenAL. Upstream made SDL2 the default, so we'll use it if
# available (autodetect). However, OpenAL is labelled 'experimental'
# and disabled by default, so we'll require OPENAL=yes to enable it
# (if present).

if pkg-config --exists sdl2; then
  SDL2DEF=yes
else
  SDL2DEF=no
fi

SDL2=${SDL2:-$SDL2DEF}
OPENGL=${OPENGL:-yes}

case "$SDL2-$OPENGL" in
  yes-*)  GFX=sdl2   ;; # SDL2 builds always support OpenGL
  no-no)  GFX=pure   ;;
  no-yes) GFX=opengl ;;
  *) echo "*** Invalid SDL2 and/or OPENGL values, use only 'yes' or 'no'" 1>&2
     exit 1 ;;
esac

case "${OPENAL:-no}" in
  yes) SND=openal ;;
  no)  SND=mixsdl ;;
  *) echo "*** Invalid OPENAL value $OPENAL, use only 'yes' or 'no'" 1>&2
     exit 1 ;;
esac

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$SRCVER
tar xvf $CWD/$PRGNAM-$SRCVER-src.tgz
cd $PRGNAM-$SRCVER
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 {} \+

# Previously this script ran the interactive config, piping responses to it.
# This is a cleaner way to do it.
# WARNING: If you're updating this SlackBuild for a new version of
# uqm, check and make sure the config.state options haven't changed!
sed -e "s,@GFX@,$GFX," \
    -e "s,@SND@,$SND," \
       $CWD/config.state.in \
       > config.state

# reprocess_config creates build.vars based on choices in config.state
sh build.sh uqm reprocess_config

# For the other options in config.state, we take the defaults.
# It'd be more efficient to require a system-wide libmikmod instead of
# using the included (statically linked) one, but it's not that big
# a library, and this way we don't have any external dependencies.

# Use our flags.
sed -i "s/-O3/$SLKCFLAGS/" build.vars

# Actually compile the thing.
sh build.sh uqm

# "sh build.sh uqm install" would install it, but it doesn't look like
# DESTDIR works (?). Manual install does.

# Real game binary lives in libexec.
mkdir -p $PKG/usr/libexec/$PRGNAM
install -s -m0755 -oroot -groot $PRGNAM $PKG/usr/libexec/$PRGNAM

# Shell script wrapper tells the real binary where to find the content.
mkdir -p $PKG/usr/games
install -oroot -groot -m0755 $PRGNAM-wrapper $PKG/usr/games/$PRGNAM

# Include (mostly) empty content and addons dirs in the package.
mkdir -p $PKG/usr/share/$PRGNAM/content/{addons,packages}
cp content/version $PKG/usr/share/$PRGNAM/content

# Install the uqm content. Without this the binary is not useful.
cat $CWD/$PRGNAM-$CONTVER-content.uqm > \
    $PKG/usr/share/$PRGNAM/content/packages/$PRGNAM-$CONTVER-content.uqm

# Use upstream's man page (used to ship our own).
mkdir -p $PKG/usr/man/man6
gzip -9c doc/users/$PRGNAM.6 > $PKG/usr/man/man6/$PRGNAM.6.gz

# .desktop borrowed from Debian
mkdir -p $PKG/usr/share/applications
cat $CWD/$PRGNAM.desktop > $PKG/usr/share/applications/$PRGNAM.desktop

# icons converted from "src/res/darwin/The Ur-Quan Masters.icns",
# with icns2png.
for i in $CWD/icons/*.png; do
  size="$( basename $i .png )"
  dir="$PKG/usr/share/icons/hicolor/${size}x${size}/apps"
  mkdir -p "$dir"
  cat $i > $dir/$PRGNAM.png
done

# old-style icon
mkdir -p $PKG/usr/share/pixmaps
ln -s ../icons/hicolor/48x48/apps/$PRGNAM.png $PKG/usr/share/pixmaps/$PRGNAM.png

# dynamic slack-desc (for my own sanity!)
ldd $PKG/usr/libexec/$PRGNAM/$PRGNAM > ldd.out
if grep -q libSDL2 ldd.out; then
  RENDER="SDL-2.0"
elif grep -q libGL ldd.out; then
  RENDER="SDL-1.2 (OpenGL)"
else
  RENDER="SDL-1.2 (software rendering)"
fi

if grep -q "libopenal" ldd.out; then
  AUDIO="OpenAL"
else
  AUDIO="SDL"
fi

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp $PRGNAM.lsm AUTHORS BUGS COPYING ChangeLog Contributing README WhatsNew \
   doc/users/manual.txt $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
sed -e "s,@CONTVER@,$CONTVER," \
    -e "s,@RENDER@,$RENDER," \
    -e "s,@AUDIO@,$AUDIO," \
    $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:-tgz}