summaryrefslogtreecommitdiffstats
path: root/games/adl/adl.SlackBuild
blob: 31274267771088e4b404bd8147e11e4d1fa106b2 (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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash

# Slackware build script for adl

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

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

# 93 (1993) is the timestamp of the tarball. Most of the files
# inside are stamped May 10 1991, and the copyright notice
# says 1987.

# In case anyone's wondering: compiled ADL files are NOT architecture
# independent. 32-bit adlcomp produces files that won't run on a 64-bit
# adlrun, and vice versa.

# 20180122 bkw: It turns out that adl development continued up
# through 2011, with a Windows and Linux binary release in 2003.
# The ADL language and bytecode formats were changed for the 2003
# binary release, and changed again afterwards. For maximum
# compatibility, I'm now including 3 versions of adl in the package.
# If the code in this script hurts your head, don't feel too bad,
# mine's aching right now.

# 20170621 bkw: add -j1 to the make commands. I got a mysterious
# build failure that I couldn't duplicate, hopefully this fixes it.

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

PRGNAM=adl
VERSION=${VERSION:-20110628}
BUILD=${BUILD:-1}
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 the variable PRINT_PACKAGE_NAME is set, then this script will report what
# the name of the created package would be, and then exit. This information
# could be useful to other scripts.
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}

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

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM
mkdir -p $PRGNAM
cd $PRGNAM

### First, the old 19930322 version, installed as adl93.
YEAR=93
tar xvf $CWD/$PRGNAM.tar.Z
cd $PRGNAM
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 640 -o -perm 600 -o -perm 444 \
  -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;

# Patch does this:
# - fix various compile errors (mostly relating to lack of ANSI prototypes).
# - remove 'extern char *malloc()' and such, include system headers instead.
# - add support for OPTFLAGS (instead of hard-coded -O in CFLAGS).
# - -DADL_NAME="/usr/games/adlrun93" (for adlcomp's emitted shebang lines).
# - stop adlrun from opening game files read/write: it never writes to them,
#   and the open fails for e.g. non-root user trying to run /usr/games/aard.
patch -p1 < $CWD/compilefixes$YEAR.diff

# 'make install' doesn't create directories.
mkdir -p $PKG/usr/games $PKG/usr/man/man6

make -j1 all install BIN=$PKG/usr/games OPTFLAGS="$SLKCFLAGS"

# the adltouch utility is broken, don't include in package.
# adldebug also seems like it might be broken, but it might just be that
# I'm using it wrong.
rm -f $PKG/usr/games/adltouch

# a couple of the samples are complete games, let's install them.
cp -a samples/aard/aard samples/mpu/mpu $PKG/usr/games

# we're going to install samples/ in /usr/doc, but not the compiled games.
make -j1 -C samples clean

# use reconstituted man pages instead of the preformatted ones in the
# source. See fixman.sh.
# Even though we're shipping 3 versions of adl, there's only one set
# of man pages because nobody ever updated them.
for page in $CWD/man/*.6; do
  gzip -9c < $page > $PKG/usr/man/man6/$( basename $page ).gz
done

DOCDIR=$PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM$YEAR
mkdir -p $DOCDIR
# rename this so no GUIs think it's a MS Word doc:
cp -a man/adl.doc $DOCDIR/adl.doc.txt
cp -a copyrigh readme samples $DOCDIR

# rename everything
for bin in adlcomp adlrun adldebug; do
  mv $PKG/usr/games/$bin $PKG/usr/games/$bin$YEAR
  ln -s $bin.6.gz $PKG/usr/man/man6/$bin$YEAR.6.gz
done

### Next, the 2003 binary-only release. No man pages, almost no docs,
#   and don't install compiled sample games. The "64-bit" binaries are
#   actually statified (static) 32-bit, which MUST NOT be stripped!
#   AFAICT, this is the most commonly used version in the ADL community,
#   so these get symlinked to the bare names (adlrun03 => adlrun).
YEAR=03
cd $TMP/$PRGNAM
tar xvf $CWD/${PRGNAM}_linux${BITS}_1_0.tar.gz
cd ADL_linux${BITS}_1_0
chown -R root:root .

# Bonus tutorial for hardcore SlackBuilders:
# The shebang line is hard-coded in adlcomp, but sed works on binaries,
# and we can use it to change the compiled-in string.
# The rules for doing this:
# 1. All occurrences of the text to replace will be changed, so make
#    sure either (a) it occurs only once, or else (b) you really do want
#    them all changed.
# 2. Replacement must be shorter than the original text.
# 3. Replacement must end with \x00. This is the famous NUL terminator
#    that C uses to terminate strings.
# 4. Only replace as many original characters as the replacement length,
#    including the NUL terminator.
# 5. The modified binary *must be* **exactly** the same size in bytes as
#    the original was. If not, you didn't follow rules 1-4 correctly!
# 6. If you're dealing with non-ASCII character encoding (e.g. UTF-8 or
#    UCS-2), make *damn sure* you know what you're doing! It's possible
#    but not necessarily straightforward. ASCII is easier (one byte is
#    one character).
# In the line below, the full original text was plain ASCII,
# "/users/cunniff/bin/adlrun". We only replace "/users/cunniff/bin/a". The
# \x00 terminates the string, replacing the "a", and the rest of the
# original text ("dlrun\x00") is left as-is in the binary (C code will
# ignore anything after the first \x00, so it just acts as padding).

sed -i 's,/users/cunniff/bin/a,/usr/games/adlrun03\x00,' adlcomp

# DO NOT strip these. The pseudo-64-bit binaries break if you do,
# because they're actually 32-bit pseudo-static, created by statifier.
# "file" shows them as "dynamically linked" but "ldd" says they're not,
# and strip gets powerfully confused by this state of affairs.
for bin in adlcomp adlrun adldebug; do
  install -m0755 -oroot -groot $bin $PKG/usr/games/$bin$YEAR
  ln -s $bin$YEAR $PKG/usr/games/$bin
  ln -s $bin.6.gz $PKG/usr/man/man6/$bin$YEAR.6.gz
done

DOCDIR=$PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM$YEAR
mkdir -p $DOCDIR
cp -a readme *.txt $DOCDIR

# The samples come from CVS, circa 2003
tar xvf $CWD/$PRGNAM$YEAR-samples.tar.gz
chown -R root:root $PRGNAM$YEAR-samples
cp -a $PRGNAM$YEAR-samples $DOCDIR/samples

### Last, the 2011 development version, from CVS. We install the docs
#   but not the man pages or compiled sample games.
YEAR=11
cd $TMP/$PRGNAM
tar xvf $CWD/$PRGNAM-$VERSION.tar.gz
cd $PRGNAM-$VERSION
chown -R root:root .

# Patch is similar to the one for adl93.
patch -p1 < $CWD/compilefixes$YEAR.diff

# Install the docs first, so we don't get the compiled samples/demos.
DOCDIR=$PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM$YEAR
mkdir -p $DOCDIR
chmod 644 doc/*.*
cp -a C* porting readme doc samples $DOCDIR

make -j1 all BIN=$PKG/usr/games OPTFLAGS="$SLKCFLAGS"

install -s -m0755 adlcomp/adlcomp $PKG/usr/games/adlcomp$YEAR
install -s -m0755 adlrun/adlrun $PKG/usr/games/adlrun$YEAR
install -s -m0755 misc/adldebug $PKG/usr/games/adldebug$YEAR

for bin in adlcomp adlrun adldebug; do
  ln -s $bin.6.gz $PKG/usr/man/man6/$bin$YEAR.6.gz
done

### OK, now regular SBo stuff from here on out.

cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
cat $CWD/README_versions.txt > $PKG/usr/doc/$PRGNAM-$VERSION/README_versions.txt
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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