#!/bin/sh
#
# source: ftp://ftp.musicbrainz.org/pub/musicbrainz/libmusicbrainz-3.0.3.tar.gz
#
# maintainer: gmg (monpontet.gerard@neuf.fr)
#

#------------------Set Some Variables

soft='libmusicbrainz3'
softversion='3.0.3'
packageversion='72.1'

arch='i486'
cpu='i686'

buildir=$(pwd)
srcpkg="$buildir/libmusicbrainz-$softversion.tar.gz"
src="$buildir/libmusicbrainz-$softversion"
package="$soft-$softversion-$arch-$packageversion"
PKG="/tmp/$package"

cd $buildir
rm -rf $src
tar -xvzf $srcpkg
rm -f $PKG.txz
rm -rf $PKG

cd $src
chown -R root:root .
find . \
 \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
 -exec chmod 755 {} \; -o \
 \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \
 -exec chmod 644 {} \;
CFLAGS="-O2 -march=$arch -mtune=$cpu"
CXXFLAGS="-O2 -march=$arch -mtune=$cpu"
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr \
      -DCMAKE_C_FLAGS:STRING="$CFLAGS" \
      -DCMAKE_CXX_FLAGS:STRING="$CXXFLAGS" \
      -DCMAKE_BUILD_TYPE=Release

make -j4
make install DESTDIR=$PKG

find $PKG | xargs file | grep -e "shared object" -e "executable" | grep ELF \
  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null

#-------------------Prepare the documentation

mkdir -p $PKG/usr/doc/$soft-$softversion 
cp -a *.txt $PKG/usr/doc/$soft-$softversion

mkdir -p $PKG/install
cat << EODESC > $PKG/install/slack-desc
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.  Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in.  You must
# make exactly 11 lines for the formatting to be correct.  It's also
# customary to leave one space after the ':'.

               |-----handy-ruler----------------------------------------------------|
libmusicbrainz3: libmusicbrainz3 - library for accessing MusicBrainz servers
libmusicbrainz3:
libmusicbrainz3: MusicBrainz is a user-maintained community music metadatabase.
libmusicbrainz3: The MusicBrainz client library allows applications to make metadata
libmusicbrainz3: lookups to a MusicBrainz server, generate signatures from WAV files
libmusicbrainz3: and create CD Index Disk IDs from audio CD-ROMs.
libmusicbrainz3:
libmusicbrainz3: libmusicbrainz is licensed under the GPL.  Relatable has graciously
libmusicbrainz3: given MusicBrainz a free license to use their TRM technology:
libmusicbrainz3:     Acoustic fingerprint technology provided by Relatable(TM),
libmusicbrainz3:     Copyright (c) 2000-2, Relatable LLC, All rights reserved.
EODESC

mkdir -p $PKG/usr/src/$soft-$softversion
cp -a $buildir/build-$soft.sh $PKG/usr/src/$soft-$softversion

#-------------------Make the packages and the md5sum

cd $PKG
makepkg -l y -c n $PKG.txz

cd $buildir

