<commit_before>#!/bin/bash
# This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
set -e # -x

SCRIPTNAME=`basename $0`
function die  { [ -n "$*" ] && echo "$SCRIPTNAME: $*" >&2; exit 127 ; }

# parse options
KEEPTMP=false
while [ $# -gt 0 ] ; do
  case "$1" in
    -k)	KEEPTMP=true ;;
    *)	die "unknown option: $1"
  esac
  shift
done

# clear ./tmpdeb/
$KEEPTMP || rm -rf ./tmpdeb/

# helper
git_clone()
{
  URL="$1" ; REPO="$2" ; COMMIT="$3"
  if test -e ./tmpdeb/$REPO/.git ; then
      (cd ./tmpdeb/$REPO && git checkout master && git pull)
  else
    unset CLONE_REFERENCE
    test -r ../$REPO/.git/index && CLONE_REFERENCE="--dissociate --reference ../$REPO/.git"
    git clone $CLONE_REFERENCE "$URL" ./tmpdeb/$REPO
  fi
  test -z "$COMMIT" || (cd ./tmpdeb/$REPO && git checkout "$COMMIT")
}

build_checked()
{
  REPO="$1" && shift
  CONFIGURE="$1" && shift
  ( cd ./tmpdeb/$REPO
    $CONFIGURE "$@"
    nice -n15 make -j`nproc`
    make check
    make install "DESTDIR=$DESTDIR"
    make installcheck "DESTDIR=$DESTDIR"
  )
}

# create 0755 dirs by default
umask 022

# run in beast/
test -e ./acbeast.m4 || die "failed to detect ./acbeast.m4"

# TODO: add /usr/share/icons/hicolor/48x48/apps/beast.png ./usr/share/icons/hicolor/scalable/apps/beast.svg
# TODO: add /usr/share/icons/hicolor/scalable/mimetypes/application-bse.svg

# build in ./tmpdeb/
BEASTDIR=/opt/$(misc/mkbuildid.sh -p | sed -r 's/^([0-9]+)\.([0-9]+).*/beast-\1-\2/')
DESTDIR=`pwd`/tmpdeb/destdir
RAPICORNPREFIXDIR=$DESTDIR$BEASTDIR
DEBDOCDIR=$DESTDIR$BEASTDIR/doc
DEBIAN=$DESTDIR/DEBIAN
rm -rf $DEBIAN
mkdir -p $DEBIAN

export PATH="$RAPICORNPREFIXDIR/bin:$PATH"
export LD_LIBRARY_PATH="$RAPICORNPREFIXDIR/lib"
export PKG_CONFIG_PATH=$RAPICORNPREFIXDIR/lib/pkgconfig
export PKG_CONFIG_RAPICORN_PREFIX=$RAPICORNPREFIXDIR
export PKG_CONFIG_RAPICORN_17_PREFIX=$RAPICORNPREFIXDIR
export PKG_CONFIG_BSE_BEASTDESTDIR=$DESTDIR
export AIDACC_DESTDIR=$DESTDIR

echo "DISPLAY=$DISPLAY LDFLAGS=$LDFLAGS"
echo "CC=$CC CFLAGS=$CFLAGS"
echo "CXX=$CXX CXXFLAGS=$CXXFLAGS"
echo "BEASTDIR=$BEASTDIR"
echo "DESTDIR=$DESTDIR"
echo "RAPICORNPREFIXDIR=$RAPICORNPREFIXDIR"
echo "PATH=$PATH"
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH"
echo "PKG_CONFIG_RAPICORN_PREFIX=$PKG_CONFIG_RAPICORN_PREFIX"
echo "PKG_CONFIG_RAPICORN_17_PREFIX=$PKG_CONFIG_RAPICORN_17_PREFIX"
echo "PKG_CONFIG_BSE_PREFIX=$PKG_CONFIG_BSE_PREFIX"
echo "AIDACC_DESTDIR=$AIDACC_DESTDIR"
echo "DEBIAN=$DEBIAN"

BEASTEXE=$BEASTDIR/bin/beast
REBUILD=false
[ -x $DESTDIR/$BEASTEXE ] || REBUILD=true
if $REBUILD ; then

    # clone/update and build rapicorn
    R=https://github.com/tim-janik/rapicorn.git
    R=../rapicorn/.git/
    test -d $R || R=git://github.com/tim-janik/rapicorn.git
    git_clone $R rapicorn 496351a0798f5ea0eb3eb2419d8d1249853afbc6 # 17.0.0
    build_checked rapicorn ./autogen.sh --prefix="$BEASTDIR"

    # clone/update and build beast
    R=https://github.com/tim-janik/beast.git
    R=`pwd`/.git
    git_clone $R beast
    build_checked beast ./autogen.sh --with-pkgroot=/opt --prefix=/usr
fi
[ -x $DESTDIR/$BEASTEXE ] || die "failed to build Beast executable: $BEASTEXE"

NAME="beast"
VERSION=$(./tmpdeb/beast/misc/mkbuildid.sh -p)
GITCOMMIT=`git rev-parse --verify HEAD`
ARCH=$(dpkg --print-architecture)
DUSIZE=$(cd $DESTDIR && du -k -s .)
unset D
D="libc6 (>= 2.15)"
D="$D, libstdc++6 (>= 5.2), zlib1g, libpython2.7, python2.7"
D="$D, libasound2, libflac8 (>= 1.2.1), libfluidsynth1 (>= 1.0.6), libmad0"
D="$D, libogg0, libvorbis0a (>= 1.3.2), libvorbisenc2, libvorbisfile3"
D="$D, libglib2.0-0 (>= 2.32.3), libpango-1.0-0 (>= 1.14.0)"
D="$D, libgdk-pixbuf2.0-0, libgtk2.0-0 (>= 2.12.12), libgnomecanvas2-0 (>= 2.4.0)"
# D="$D, librapicorn-17-0 (>= 17.0.0~rc1), python-rapicorn, rapicorn, librapicorn-dev"

# DEBIAN/control
cat >$DEBIAN/control <<-__EOF
	Package: $NAME
	Version: $VERSION
	License: GNU LGPL v2.1+
	Section: sound
	Priority: optional
	Maintainer: <NAME> <<EMAIL>>
	Homepage: https://beast.testbit.eu
	Installed-Size: ${DUSIZE%.}
	Architecture: $ARCH
	Depends: $D
	Description: Music Synthesizer and Composer
	 Beast is a free software music composer and modular synthesizer.
	 .
	 It supports a wide range of standards in the field, such as MIDI,
	 FLAC/WAV/AIFF/MP3/OggVorbis audio files and LADSPA modules.
	 It allows for multitrack editing, unlimited undo/redo support,
	 real-time synthesis support, 32bit audio rendering and MMX/SSE
	 utilisation for synthesis plugins.
	 .<commit_msg>MISC: make-deb.sh: executing beast requires librsvg2-2<commit_after>#!/bin/bash
# This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
set -e # -x

SCRIPTNAME=`basename $0`
function die  { [ -n "$*" ] && echo "$SCRIPTNAME: $*" >&2; exit 127 ; }

# parse options
KEEPTMP=false
while [ $# -gt 0 ] ; do
  case "$1" in
    -k)	KEEPTMP=true ;;
    *)	die "unknown option: $1"
  esac
  shift
done

# clear ./tmpdeb/
$KEEPTMP || rm -rf ./tmpdeb/

# helper
git_clone()
{
  URL="$1" ; REPO="$2" ; COMMIT="$3"
  if test -e ./tmpdeb/$REPO/.git ; then
      (cd ./tmpdeb/$REPO && git checkout master && git pull)
  else
    unset CLONE_REFERENCE
    test -r ../$REPO/.git/index && CLONE_REFERENCE="--dissociate --reference ../$REPO/.git"
    git clone $CLONE_REFERENCE "$URL" ./tmpdeb/$REPO
  fi
  test -z "$COMMIT" || (cd ./tmpdeb/$REPO && git checkout "$COMMIT")
}

build_checked()
{
  REPO="$1" && shift
  CONFIGURE="$1" && shift
  ( cd ./tmpdeb/$REPO
    $CONFIGURE "$@"
    nice -n15 make -j`nproc`
    make check
    make install "DESTDIR=$DESTDIR"
    make installcheck "DESTDIR=$DESTDIR"
  )
}

# create 0755 dirs by default
umask 022

# run in beast/
test -e ./acbeast.m4 || die "failed to detect ./acbeast.m4"

# TODO: add /usr/share/icons/hicolor/48x48/apps/beast.png ./usr/share/icons/hicolor/scalable/apps/beast.svg
# TODO: add /usr/share/icons/hicolor/scalable/mimetypes/application-bse.svg

# build in ./tmpdeb/
BEASTDIR=/opt/$(misc/mkbuildid.sh -p | sed -r 's/^([0-9]+)\.([0-9]+).*/beast-\1-\2/')
DESTDIR=`pwd`/tmpdeb/destdir
RAPICORNPREFIXDIR=$DESTDIR$BEASTDIR
DEBDOCDIR=$DESTDIR$BEASTDIR/doc
DEBIAN=$DESTDIR/DEBIAN
rm -rf $DEBIAN
mkdir -p $DEBIAN

export PATH="$RAPICORNPREFIXDIR/bin:$PATH"
export LD_LIBRARY_PATH="$RAPICORNPREFIXDIR/lib"
export PKG_CONFIG_PATH=$RAPICORNPREFIXDIR/lib/pkgconfig
export PKG_CONFIG_RAPICORN_PREFIX=$RAPICORNPREFIXDIR
export PKG_CONFIG_RAPICORN_17_PREFIX=$RAPICORNPREFIXDIR
export PKG_CONFIG_BSE_BEASTDESTDIR=$DESTDIR
export AIDACC_DESTDIR=$DESTDIR

echo "DISPLAY=$DISPLAY LDFLAGS=$LDFLAGS"
echo "CC=$CC CFLAGS=$CFLAGS"
echo "CXX=$CXX CXXFLAGS=$CXXFLAGS"
echo "BEASTDIR=$BEASTDIR"
echo "DESTDIR=$DESTDIR"
echo "RAPICORNPREFIXDIR=$RAPICORNPREFIXDIR"
echo "PATH=$PATH"
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH"
echo "PKG_CONFIG_RAPICORN_PREFIX=$PKG_CONFIG_RAPICORN_PREFIX"
echo "PKG_CONFIG_RAPICORN_17_PREFIX=$PKG_CONFIG_RAPICORN_17_PREFIX"
echo "PKG_CONFIG_BSE_PREFIX=$PKG_CONFIG_BSE_PREFIX"
echo "AIDACC_DESTDIR=$AIDACC_DESTDIR"
echo "DEBIAN=$DEBIAN"

BEASTEXE=$BEASTDIR/bin/beast
REBUILD=false
[ -x $DESTDIR/$BEASTEXE ] || REBUILD=true
if $REBUILD ; then

    # clone/update and build rapicorn
    R=https://github.com/tim-janik/rapicorn.git
    R=../rapicorn/.git/
    test -d $R || R=git://github.com/tim-janik/rapicorn.git
    git_clone $R rapicorn 496351a0798f5ea0eb3eb2419d8d1249853afbc6 # 17.0.0
    build_checked rapicorn ./autogen.sh --prefix="$BEASTDIR"

    # clone/update and build beast
    R=https://github.com/tim-janik/beast.git
    R=`pwd`/.git
    git_clone $R beast
    build_checked beast ./autogen.sh --with-pkgroot=/opt --prefix=/usr
fi
[ -x $DESTDIR/$BEASTEXE ] || die "failed to build Beast executable: $BEASTEXE"

NAME="beast"
VERSION=$(./tmpdeb/beast/misc/mkbuildid.sh -p)
GITCOMMIT=`git rev-parse --verify HEAD`
ARCH=$(dpkg --print-architecture)
DUSIZE=$(cd $DESTDIR && du -k -s .)
unset D
D="libc6 (>= 2.15)"
D="$D, libstdc++6 (>= 5.2), zlib1g, libpython2.7, python2.7"
D="$D, libasound2, libflac8 (>= 1.2.1), libfluidsynth1 (>= 1.0.6), libmad0"
D="$D, libogg0, libvorbis0a (>= 1.3.2), libvorbisenc2, libvorbisfile3"
D="$D, libglib2.0-0 (>= 2.32.3), libpango-1.0-0 (>= 1.14.0), librsvg2-2 (>= 2.40.5)"
D="$D, libgdk-pixbuf2.0-0, libgtk2.0-0 (>= 2.12.12), libgnomecanvas2-0 (>= 2.4.0)"
# D="$D, librapicorn-17-0 (>= 17.0.0~rc1), python-rapicorn, rapicorn, librapicorn-dev"

# DEBIAN/control
cat >$DEBIAN/control <<-__EOF
	Package: $NAME
	Version: $VERSION
	License: GNU LGPL v2.1+
	Section: sound
	Priority: optional
	Maintainer: <NAME> <<EMAIL>>
	Homepage: https://beast.testbit.eu
	Installed-Size: ${DUSIZE%.}
	Architecture: $ARCH
	Depends: $D
	Description: Music Synthesizer and Composer
	 Beast is a free software music composer and modular synthesizer.
	 .
	 It supports a wide range of standards in the field, such as MIDI,
	 FLAC/WAV/AIFF/MP3/OggVorbis audio files and LADSPA modules.
	 It allows for multitrack editing, unlimited undo/redo support,
	 real-time synthesis support, 32bit audio rendering and MMX/SSE
	 utilisation for synthesis plugins.
	 .
{'fraction_non_alphanumeric': 0.15909840571742717, 'fraction_numerical': 0.032985156679494226, 'mean_word_length': 4.236614853195164, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 34, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2307894', 'n_tokens_mistral': 3991, 'n_tokens_neox': 3737, 'n_words': 769}