#!/bin/sh

# Copyright (c) 2005,2006
# Foundation for Research and Technology-Hellas (Greece).
# All rights reserved.
#
# This file is part of CGAL (www.cgal.org); you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; version 2.1 of the License.
# See the file LICENSE.LGPL distributed with CGAL.
#
# Licensees holding a valid commercial license may use this file in
# accordance with the commercial license agreement provided with the software.
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/MacOSX/scripts/cgal_make_macosx_app $
# $Id: cgal_make_macosx_app 29564 2006-03-16 21:29:51Z reichel $
#
# Authors: Herve Bronnimann
#          Menelaos Karavelas

# This script creates the appropriate directory structure so that a CGAL
# Qt demo can be run on MacOSX

usage()
{
     echo "Usage: cgal_make_macosx_app executable"
}


case $# in
  0) usage
     exit 1
esac


for i do
  if [ -x "$i" ] ; then
     EXECUTABLE=$i
  else
     usage
     exit 1
  fi
done

if [ -z "$EXECUTABLE.app" ] ; then
  mkdir $EXECUTABLE.app
fi

test -d $EXECUTABLE.app/Contents/MacOS/ || mkdir -p $EXECUTABLE.app/Contents/MacOS/
strip $EXECUTABLE
cp $EXECUTABLE $EXECUTABLE.app/Contents/MacOS/$EXECUTABLE

rm -f  $EXECUTABLE.app/Contents/PkgInfo
echo "APPL????" > $EXECUTABLE.app/Contents/PkgInfo

rm -f  $EXECUTABLE.app/Contents/Info.plist
cat > $EXECUTABLE.app/Contents/Info.plist <<ENDINFO
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM
"file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version=\"0.9\">
<dict>
        <key>CFBundleIconFile</key>
        <string>cgal_app.icns</string>
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleGetInfoString</key>
        <string>Created by CGAL</string>
        <key>CFBundleSignature</key>
        <string>ttxt</string>
        <key>CFBundleExecutable</key> 
        <string>$EXECUTABLE</string>
ENDINFO

if [ -d "help" ] ; then 
cat >> $EXECUTABLE.app/Contents/Info.plist <<ENDINFO
	<key>CFBundleHelpBookFolder</key>
	<string>Help</string>
	<key>CFBundleHelpBookName</key>
	<string>Help</string>
ENDINFO
	test -d $EXECUTABLE.app/Contents/Resources/Help || mkdir -p $EXECUTABLE.app/Contents/Resources/Help
	cp -r help/* $EXECUTABLE.app/Contents/Resources/Help
	ln -s index.html $EXECUTABLE.app/Contents/Resources/Help/Help.html
fi

cat >> $EXECUTABLE.app/Contents/Info.plist <<ENDINFO
        <key>NOTE</key>
        <string>This file was generated by CGAL/scripts/cgal_make_macosx_app.</string>
</dict>
</plist>
ENDINFO

test -d $EXECUTABLE.app/Contents/Resources || mkdir -p $EXECUTABLE.app/Contents/Resources
CGALMAKEDIR=`dirname $CGAL_MAKEFILE`
CGALDIR="$CGALMAKEDIR/../"
cp $CGALDIR/auxiliary/cgal_app.icns $EXECUTABLE.app/Contents/Resources
echo "created $EXECUTABLE.app ..." 
