# -*- shell-script -*-
# Generated by mkapspec 0.3
[Meta]
ShortName: celstart
SoftwareVersion: @PACKAGE_VERSION@
DisplayName: CELstart
RootName: @crystalspace3d.org/celstart:$SOFTWAREVERSION
Summary: CEL game launcher
Maintainer: Jorrit Tyberghein <jorrit@crystalspace3d.org>
Packager: Frank Richter <res@crystalspace3d.org>
PackageVersion: 3
CPUArchitectures: x86
AutopackageTarget: 1.2
Type: Application
License: GNU Library or "Lesser" General Public License (LGPL)
PackageDesktop: celstart.desktop
Repository: http://crystalspace3d.org/downloads/celstart/$SOFTWAREVERSION/$SHORTNAME.xml

[Description]
CELstart is a launcher for game packages made with CrystalSpace+CEL.

[BuildPrepare]
# If you're using autotools, the default should be enough.
# prepareBuild will set up apbuild and run configure for you. If you
# need to pass arguments to configure, just add them to prepareBuild:
# prepareBuild --enable-foo --disable-bar
#prepareBuild

[BuildUnprepare]
# If you're using prepareBuild above, there is no need to change this!
#unprepareBuild

[Globals]

[Prepare]
require '@libpng.org/libpng' 3
require '@jig.org/libjpeg' 62
require '@xiph.org/libogg' 0
require '@xiph.org/libvorbis' 0
require '@freetype.org/freetype' 6
require '@xfree86.org/xlib' 6
require '@zlib.org/zlib' 1
require '@opengl.org/opengl' 1.4
require '@python.org/python' 2.4

[Imports]
# This command will tell makeinstaller what to include in the package.
# The selection comes from the files created by 'make install' or equivalent.
# Usually, you can leave this at the default
echo $source_dir/celstart_static | import
import <<EOF
/usr/lib/libCg.so
/usr/lib/libCgGL.so
EOF

# look for CS
locatedir()
{
  my_IFS=$IFS; IFS=:
  for dir in $1 ; do
      if [ -d $dir/$2 ] ; then
	  echo $dir
	  break
      fi
  done
  IFS=$my_IFS
}
locatedata()
{
  locatedir "$CRYSTAL" data
}
CS_DIR=`locatedata "$CRYSTAL"`
CEL_DIR="$source_dir/scripts/autopackage/@top_srcdir@"
# We *don't* just want to pull all the files from CS'/CEL's data/ - they may 
# contain the .svn dirs! So filter out these files...
fetch_data()
{
  old_pwd=`pwd`
  cd $2
  find . ! \( -regex ".*\.svn.*" -o -regex ".*~$" \) -a -type d -exec mkdir -p $old_pwd/$1/{} ";" > /dev/null
  find . ! \( -regex ".*\.svn.*" -o -regex ".*~$" \) -a -type f -exec cp "{}" $old_pwd/$1/{} ";" > /dev/null
  cd $old_pwd
  echo $1
}
if [ -n $CS_DIR ] ; then
  fetch_data config $CS_DIR/data/config | import
  fetch_data shader $CS_DIR/data/shader | import
  echo $CS_DIR/data/ttf-dejavu.zip | import
  echo $CS_DIR/data/standard.zip | import
else
  exit 1
fi
if [ -n $CEL_DIR ] ; then
  fetch_data images $CEL_DIR/data/images | import
  fetch_data library $CEL_DIR/data/library | import
  fetch_data sounds $CEL_DIR/data/sounds | import
else
  exit 1
fi

# .py files (from the build directories)
echo "$source_dir/*.py" | import
echo "`locatedir "$CRYSTAL" out`/*.py" | import

# Merge CS+CEL vfs.cfg
cp $CS_DIR/vfs.cfg .
cat $CEL_DIR/vfs.cfg >> vfs.cfg
echo vfs.cfg | import

# Icons
echo $CEL_DIR/scripts/autopackage/celstart.desktop | import
setup_icon()
{
  for size in 16x16 24x24 32x32 48x48 64x64 128x128 scalable ; do
    mkdir -p hicolor/$size/$2
    srcdir=$CEL_DIR/scripts/autopackage/icons/$size
    if [ -d $srcdir ] ; then
      cp $srcdir/$1.* hicolor/$size/$2 
    fi
  done
}
setup_icon gnome-mime-application-x-zip-celstart mimetypes
echo hicolor | import
mkdir -p share/mime/packages
cp $CEL_DIR/scripts/autopackage/package-celstart.xml share/mime/packages
echo share | import

# Wrapper shell script
cat > celstart <<EOF
#!/bin/sh
# autopackage wrapper uses full path
mypath="\`dirname \$0\`"
celstartpath="\${mypath}/../opt/celstart/"
export LD_LIBRARY_PATH="\$celstartpath:\${LD_LIBRARY_PATH}"
export CRYSTAL="\$celstartpath"
"\$celstartpath/celstart_static" \$@
EOF
echo celstart | import

[Install]
# See http://www.autopackage.org/api/ for details
copyFiles celstart_static $PREFIX/opt/celstart
copyFiles libCg* $PREFIX/opt/celstart
unpack_data()
{
  copyFiles $1 $PREFIX/opt/celstart/data/
}
unpack_data config
unpack_data shader
unpack_data images
unpack_data library
unpack_data sounds
copyFiles *.zip $PREFIX/opt/celstart/data
copyFiles vfs.cfg $PREFIX/opt/celstart
copyFiles *.py $PREFIX/opt/celstart/scripts
installIcon hicolor
installExe celstart
installMenuItem Games celstart.desktop
installMime share/mime/packages/package-celstart.xml

[Uninstall]
# Leaving this at the default is safe unless you use custom commands in
# "Install" to create files. By default, all autopackage API functions are
# logged.
uninstallFromLog
