summaryrefslogtreecommitdiffstats
path: root/games/commandergenius/commandergenius.SlackBuild
blob: 796719cef0361133cd228d15c6423fa356a7a69a (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
#!/bin/sh

# Slackware build script for commandergenius

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

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

# 20171222 bkw: updated for 1.9.9.8beta
# 20170826 bkw: updated for 1.9.9.5beta
# 20170725 bkw: updated for 1.9.9.2beta
# 20170301 bkw:
# - updated for 1.9.8.7beta
# - fix the build for the case where SDL2 is installed but SDL2_image is not.
# - update man page (level= option, correct author's full name)
# - use github long-form URL
# 20170122 bkw: updated for 1.9.8.1beta.

PRGNAM=commandergenius
VERSION=${VERSION:-2.0.0.0}
BUILD=${BUILD:-1}
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}

# note that upstream has -O3 hardcoded *after* the specified flags,
# so the -O2 here doesn't actually do anything. The -fPIC and arch/tune
# stuff still applies though.
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

# I wish upstream would pick a name and stick with it... they also use
# ~/.CommanderGenius for user data, and their README mentions CGenius.
SRCNAM="Commander-Genius"
EXENAME="CGeniusExe"
DESKTOP="cgenius.desktop"

# the real VERSION is from version.h in the source. the tarball names
# omit the dots.

if echo "$VERSION" | grep -q beta; then
	# This works for the 1.9.x.x betas:
	SRCVER="$( echo $VERSION | sed 's,\.,,g' )"
else
	# Now upstream's actual version number is 2.0.0.0 but the tarball/dir
	# name only has two zeroes in it:
	SRCVER="200Release"
fi

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $SRCNAM-$SRCVER
tar xvf $CWD/$SRCNAM-$SRCVER.tar.gz
cd $SRCNAM-$SRCVER
chown -R root:root .

# Why doesn't upstream include this in his release tarball? Probably
# because it's autogenerated & github doesn't automagically include
# submodules. It's a bit of a PITA to deal with this, appears impossible
# to find the correct commit of GsKit to use without cloning the
# Commander-Genius repo (which kinda defeats the purpose of having
# release tarballs...)
GSVER=${GSVER:-f925d1362f0bc99598141a97d5a200d5e6a41391}
tar xvf $CWD/GsKit-$GSVER.tar.gz
rm -rf GsKit
mv GsKit-$GSVER GsKit

# permissions are blethcherous, please don't revert to template here.
find -L . -type f -a -exec chmod 644 '{}' '+'
find -L . -type d -a -exec chmod 755 '{}' '+'

# placate desktop-file-validate
sed -i 's,Application;,,' share/$DESKTOP

# SDL 2 is optional. I prefer it, others may not.
SDLOPT="-DUSE_SDL2=no"
SDLVER=1
if pkg-config --exists sdl2 SDL2_image && [ "${SDL2:-yes}" != "no" ]; then
  SDLOPT="-DUSE_SDL2=yes"
  SDLVER=2
fi

echo "=== Building with $SDLOPT"

mkdir -p build
cd build
  cmake \
    $SDLOPT \
    -DGAMES_SHAREDIR:STRING=/usr/share/games \
    -DCMAKE_C_FLAGS:STRING="$SLKCFLAGS" \
    -DCMAKE_CXX_FLAGS:STRING="$SLKCFLAGS" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DLIB_SUFFIX=${LIBDIRSUFFIX} \
    -DMAN_INSTALL_DIR=/usr/man \
    -DCMAKE_BUILD_TYPE=Release ..
  make VERBOSE=1
  make install/strip DESTDIR=$PKG
cd ..

# upstream installs 2 identical-looking (but not byte-identical) icons
rm -f $PKG/usr/share/icons/hicolor/512x512/apps/CGLogo.png
ln -s ../../../../games/$PRGNAM/cglogo512.png \
      $PKG/usr/share/icons/hicolor/512x512/apps/CGLogo.png

# grrrr. don't force command-line users to remember the name is CGeniusExe
ln -s $EXENAME $PKG/usr/games/$PRGNAM

# the High Quality Pack. this is redundant for Keen 1 and 4 (just download
# the Special versions of these games), so we only install the data for
# 2 and 3. strace shows the files are being loaded, but TBH I haven't
# played these games enough to notice the difference with/without the HQP.
rm -rf hqp/games/keen1 hqp/games/keen4
cp -a hqp/* $PKG/usr/share/games/$PRGNAM

# man page written for this SlackBuild.
mkdir -p $PKG/usr/man/man6
gzip -9c < $CWD/$PRGNAM.6 > $PKG/usr/man/man6/$PRGNAM.6.gz
ln -s $PRGNAM.6.gz $PKG/usr/man/man6/$EXENAME.6.gz

# upstream installs most of the docs in /usr/share/games/$PRGNAM...
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a COPYRIGHT $PKG/usr/doc/$PRGNAM-$VERSION
for i in README changelog.txt Readme_hqp.txt; do
  ln -s ../../share/games/$PRGNAM/$i $PKG/usr/doc/$PRGNAM-$VERSION
done
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
sed "s,@SDLVER@,$SDLVER," < $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}