summaryrefslogtreecommitdiffstats
path: root/multimedia/munt/munt.SlackBuild
blob: 96d924674170588c05fc9fd0707475576c10ff18 (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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/bin/bash

# Slackware build script for munt

# Copyright 2017 Dugan Chen Canada
# Copyright 2023 B. Watson
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# 20230410 bkw:
# - new maintainer.
# - update for v2.7.0 (sourceforge => github).
# - include (some of) the ROMs in the package.
# - add the mt32emu_alsadrv binaries (mt32d, xmt32).
# - patch everything to use /usr/share/munt/roms/ as default path.
#   user can still change this in the UI as needed, I just don't want
#   it defaulting to ~/roms/ (need this so we can package the ROMs).
# - add doinst.sh, since the new version has icons and a .desktop.
# - add setcap stuff for jack.
# - update README to document jack optional dep and the fact that the
#   ROMs are included. also mention the actual binary names, since
#   neither one's called "munt".

# TODO someday: man pages.

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

PRGNAM=munt
VERSION=${VERSION:-2.7.0}
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 [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

# 20230411 bkw: The various components have separate version numbers,
# and it looks like upstream's tags are named after whichever
# component was released last. The mt32emu_qt_1_11_1 tag includes
# the previous release (2.7.0) of mt32emu. This is kinda confusing,
# but whatever.
GIT_TAG=${GIT_TAG:-mt32emu_qt_1_11_1}

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-$GIT_TAG
tar xvf $CWD/$PRGNAM-$GIT_TAG.tar.gz
cd $PRGNAM-$GIT_TAG
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 {} \+

# 20230411 bkw: Patch mt32emu-qt, mt32emu-smf2wav, mt32d, xmt32 to
# look for ROMs in a systemwide directory (which is where we'll place
# the ROMs, below).
patch -p1 < $CWD/system_rom_path.diff

# Allow mt32d, xmt32 to build in-tree, without the library already
# installed. Also apply our SLKCFLAGS.
sed -i \
    -e "s,-O2,$SLKCFLAGS -I../build/mt32emu/include," \
    -e "s,-lmt32emu,-L../build/mt32emu -lmt32emu," \
    mt32emu_alsadrv/Makefile

# 20230411 bkw: fix desktop-file-validate nitpick (a "hint", not an error).
sed -i '/^Categories/s,$,Audio;,' mt32emu_qt/res/mt32emu-qt.desktop

# 20230411 bkw: cmake accepts and ignores (!) -DCMAKE_INSTALL_DOCDIR.
# Also there's no way to disable jack, if it's autodetected.
mkdir -p build
cd build
  cmake \
    -DCMAKE_C_FLAGS:STRING="$SLKCFLAGS" \
    -DCMAKE_CXX_FLAGS:STRING="$SLKCFLAGS" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DLIB_INSTALL_DIR=/usr/lib${LIBDIRSUFFIX} \
    -DCMAKE_BUILD_TYPE=Release .. \
    -Dlibmt32emu_SHARED=ON
  make
  make install/strip DESTDIR=$PKG
cd ..

# This stuff isn't built by cmake. It's considered outdated, but at least
# the mt32d binary might be useful for a headless/console-only system.
make -C mt32emu_alsadrv
install -s -m0755 mt32emu_alsadrv/{mt32d,xmt32} $PKG/usr/bin

### Extract and install the ROMs.

PKGROMS=$PKG/usr/share/$PRGNAM/roms
mkdir -p $PKGROMS

# The ROM zip files have at least 2 possible names each, depending on
# what was used to download them. The URLs have spaces in them. The
# spec says spaces have to be hex-escaped as %20. Plus, we can't have
# spaces in the URLs in our .info files anyway: it would break every
# tool that parses .info files, plus it would prevent curl from being
# able to download them (it refuses to accept spaces in URLs).

# So DOWNLOAD has the %20's in the URLs. But wget will "helpfully"
# transform them back into spaces. On the other hand, "curl -O"
# will save them as-is. I don't know what various browsers do, but
# hopefully I've covered it here...

ok=0
for i in \
  'Roland - CM32L - CONTROL.1989-12-05.v1.02.ROM.zip' \
  'Roland%20-%20CM32L%20-%20CONTROL.1989-12-05.v1.02.ROM.zip'
do
  if [ -e "$CWD/$i" ]; then
    unzip -p "$CWD/$i" \
      "Roland - CM32L - CONTROL.1989-12-05.v1.02.ROM" \
      > $PKGROMS/CM32L_CONTROL.ROM
    ok=1
    break
  fi
done

[ "$ok" = "0" ] && echo "*** can't find CM32L control ROM zip file" && exit 1

ok=0
for i in \
  'Roland - CM32L - PCM Maskrom.ROM.zip' \
  'Roland%20-%20CM32L%20-%20PCM%20Maskrom.ROM.zip'
do
  if [ -e "$CWD/$i" ]; then
    unzip -p "$CWD/$i" \
      "Roland - CM32L - PCM Maskrom.ROM" \
      > $PKGROMS/CM32L_PCM.ROM
    ok=1
    break
  fi
done

[ "$ok" = "0" ] && echo "*** can't find CM32L PCM ROM zip file" && exit 1

# We need 3 files from this one, and 2 of them have to be
# interleaved... wrote a little tool to do the job. Only
# including the v1.0.7 control ROM; it's the newest version
# in the zip file. Also, in case something saves the file with
# the ( character hex-escaped, allow for it.
ok=0
for i in \
  'Roland MT32 (various OS _ extra ROMs.zip' \
  'Roland%20MT32%20(various%20OS%20_%20extra%20ROMs.zip' \
  'Roland%20MT32%20%28various%20OS%20_%20extra%20ROMs.zip'
do
  if [ -e "$CWD/$i" ]; then
    unzip -p "$CWD/$i" r15449121.ic37.bin > $PKGROMS/MT32_PCM.ROM
    unzip "$CWD/$i" mt32_1.0.7.ic26.bin mt32_1.0.7.ic27.bin

    # The ROMs are stored on 2 chips, one with the even-numbered
    # addresses and one with the odd. In theory, munt can use them
    # as-is (the source called them "Mux0" and "Mux1" ROMs), but
    # I couldn't get that to work. Easy enough to merge them together.
    gcc -Wall -O2 -o interleave "$CWD/interleave.c"
    ./interleave mt32_1.0.7.ic27.bin mt32_1.0.7.ic26.bin $PKGROMS/MT32_CONTROL.ROM

    ok=1
    break
  fi
done

[ "$ok" = "0" ] && echo "*** can't find MT32 ROM zip file" && exit 1

### ROMs extracted/installed, back to regular SBo style stuffs.

PKGDOC=$PKG/usr/doc/$PRGNAM-$VERSION
mkdir -p $PKG/usr/doc
mv $PKG/usr/share/doc/$PRGNAM $PKGDOC
rm -rf $PKG/usr/share/doc
cp -a README* $PKGDOC
mkdir -p $PKGDOC/mt32emu_alsadrv
cp -a mt32emu_alsadrv/*.txt $PKGDOC/mt32emu_alsadrv
cat $CWD/$PRGNAM.SlackBuild > $PKGDOC/$PRGNAM.SlackBuild

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

WITHJACK=WITHOUT

# Only add capability stuff if not disabled, and if JACK support was
# included.
if pkg-config --exists jack && [ "${SETCAP:-yes}" = "yes" ]; then
  WITHJACK=WITH
  cat $CWD/setcap.sh >> $PKG/install/doinst.sh
  # Only allow execution by audio group
  chown root:audio $PKG/usr/bin/mt32emu-qt
  chmod 0750 $PKG/usr/bin/mt32emu-qt
fi

sed "s,@WITHJACK@,$WITHJACK," < $CWD/slack-desc > $PKG/install/slack-desc

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