[dia] Added files to build App and dmg on Mac OS X.



commit f883d2c7279ebbb51aa70fc95b260e4d9ca4eba4
Author: sdteffen <sdteffen external site>
Date:   Sun Apr 11 19:12:22 2010 +0200

    Added files to build App and dmg on Mac OS X.

 configure.in                  |    1 +
 installer/Makefile.am         |    2 +-
 installer/macosx/Makefile.am  |    4 +
 installer/macosx/osx-app.sh   |  405 +++++++++++++++++++++++++++++++++++++++++
 installer/macosx/osx-build.sh |  331 +++++++++++++++++++++++++++++++++
 installer/macosx/osx-dmg.sh   |  179 ++++++++++++++++++
 6 files changed, 921 insertions(+), 1 deletions(-)
---
diff --git a/configure.in b/configure.in
index 6936d2c..57c80de 100644
--- a/configure.in
+++ b/configure.in
@@ -665,6 +665,7 @@ doc/eu/Makefile
 doc/pl/Makefile
 doc/fr/Makefile
 installer/Makefile
+installer/macosx/Makefile
 installer/win32/Makefile
 installer/win32/locale/Makefile
 dia.keys
diff --git a/installer/Makefile.am b/installer/Makefile.am
index a783431..75a60dd 100644
--- a/installer/Makefile.am
+++ b/installer/Makefile.am
@@ -1,4 +1,4 @@
 ## Process this file with automake to produce Makefile.in
 
-SUBDIRS = win32
+SUBDIRS = macosx win32
 
diff --git a/installer/macosx/Makefile.am b/installer/macosx/Makefile.am
new file mode 100644
index 0000000..fbbf27a
--- /dev/null
+++ b/installer/macosx/Makefile.am
@@ -0,0 +1,4 @@
+## Process this file with automake to produce Makefile.in
+
+EXTRA_DIST = osx-app.sh osx-build.sh osx-dmg.sh
+
diff --git a/installer/macosx/osx-app.sh b/installer/macosx/osx-app.sh
new file mode 100755
index 0000000..c648021
--- /dev/null
+++ b/installer/macosx/osx-app.sh
@@ -0,0 +1,405 @@
+#!/bin/bash
+#
+# USAGE
+# osx-app [-s] [-l /path/to/libraries] -py /path/to/python/modules [-l /path/to/libraries] -b /path/to/bin/dia -p /path/to/Info.plist
+#
+# This script attempts to build an Dia.app package for OS X, resolving
+# dynamic libraries, etc.
+# 
+# If the '-s' option is given, then the libraries and executable are stripped.
+# 
+# The Info.plist file can be found in the base dia directory once
+# configure has been run.
+#
+# AUTHORS
+#		 Steffen Macke <sdteffen sdteffen de>
+#		 Kees Cook <kees outflux net>
+#		 Michael Wybrow <mjwybrow users sourceforge net>
+#		 Jean-Olivier Irisson <jo irisson gmail com>
+# 
+# Copyright (C) 2005 Kees Cook
+# Copyright (C) 2005-2009 Michael Wybrow
+# Copyright (C) 2007-2009 Jean-Olivier Irisson
+# Copyright (C) 2010 Steffen Macke
+#
+# Released under GNU GPL, read the file 'COPYING' for more information
+#
+# Thanks to GNUnet's "build_app" script for help with library dep resolution.
+#		https://gnunet.org/svn/GNUnet/contrib/OSX/build_app
+# 
+# NB:
+# When packaging Dia for OS X, configure should be run with the 
+# "--enable-osxapp" option which sets the correct paths for support
+# files inside the app bundle.
+# 
+
+# Defaults
+strip=false
+
+# If LIBPREFIX is not already set (by osx-build.sh for example) set it to blank (one should use the command line argument to set it correctly)
+if [ -z $LIBPREFIX ]; then
+	LIBPREFIX=""
+fi
+
+
+# Help message
+#----------------------------------------------------------
+help()
+{
+echo -e "
+Create an app bundle for OS X
+
+\033[1mUSAGE\033[0m
+	$0 [-s] [-l /path/to/libraries] -py /path/to/python/modules -b /path/to/bin/dia -p /path/to/Info.plist
+
+\033[1mOPTIONS\033[0m
+	\033[1m-h,--help\033[0m 
+		display this help message
+	\033[1m-s\033[0m
+		strip the libraries and executables from debugging symbols
+	\033[1m-py,--with-python\033[0m
+		add python modules (numpy, lxml) from given directory
+		inside the app bundle
+	\033[1m-l,--libraries\033[0m
+		specify the path to the librairies Dia depends on
+		(typically /sw or /opt/local)
+	\033[1m-b--binary\033[0m
+		specify the path to Dia's binary. By default it is in
+		Build/bin/ at the base of the source code directory
+	\033[1m-p,--plist\033[0m
+		specify the path to Info.plist. Info.plist can be found
+		in the base directory of the source code once configure
+		has been run
+
+\033[1mEXAMPLE\033[0m
+	$0 -s -py ~/python-modules -l /opt/local -b ../../Build/bin/dia -p ../../Info.plist
+"
+}
+
+
+# Parse command line arguments
+#----------------------------------------------------------
+while [ "$1" != "" ]
+do
+	case $1 in
+		-py|--with-python)
+			add_python=true
+			python_dir="$2"
+			shift 1 ;;
+		-s)
+			strip=true ;;
+		-l|--libraries)
+			LIBPREFIX="$2"
+			shift 1 ;;
+		-b|--binary)
+			binary="$2"
+			shift 1 ;;
+		-p|--plist)
+			plist="$2"
+			shift 1 ;;
+		-h|--help)
+			help
+			exit 0 ;;
+		*)
+			echo "Invalid command line option: $1" 
+			exit 2 ;;
+	esac
+	shift 1
+done
+
+echo -e "\n\033[1mCREATE INKSCAPE APP BUNDLE\033[0m\n"
+
+# Safety tests
+
+if [ "x$binary" == "x" ]; then
+	echo "Dia binary path not specified." >&2
+	exit 1
+fi
+
+if [ ! -x "$binary" ]; then
+	echo "Dia executable not not found at $binary." >&2
+	exit 1
+fi
+
+if [ "x$plist" == "x" ]; then
+	echo "Info.plist file not specified." >&2
+	exit 1
+fi
+
+if [ ! -f "$plist" ]; then
+	echo "Info.plist file not found at $plist." >&2
+	exit 1
+fi
+
+
+if [ ! -e "$LIBPREFIX" ]; then
+	echo "Cannot find the directory containing the libraires: $LIBPREFIX" >&2
+	exit 1
+fi
+
+if [ ! -e "$LIBPREFIX/share/themes/Clearlooks-Quicksilver" ]; then
+	echo "Missing Clearlooks -- please install gtk2-clearlooks and try again." >&2
+	exit 1
+fi
+
+# Handle some version specific details.
+VERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d'.'`
+if [ "$VERSION" -ge "4" ]; then
+	# We're on Tiger (10.4) or later.
+	# XCode behaves a little differently in Tiger and later.
+	XCODEFLAGS="-configuration Deployment"
+	SCRIPTEXECDIR="ScriptExec/build/Deployment/ScriptExec.app/Contents/MacOS"
+	EXTRALIBS=""
+else
+	# Panther (10.3) or earlier.
+	XCODEFLAGS="-buildstyle Deployment"
+	SCRIPTEXECDIR="ScriptExec/build/ScriptExec.app/Contents/MacOS"
+	EXTRALIBS=""
+fi
+
+
+# Package always has the same name. Version information is stored in
+# the Info.plist file which is filled in by the configure script.
+package="Dia.app"
+
+# Remove a previously existing package if necessary
+if [ -d $package ]; then
+	echo "Removing previous Dia.app"
+	rm -Rf $package
+fi
+
+
+# Set the 'macosx' directory, usually the current directory.
+resdir=`pwd`
+
+
+# Prepare Package
+#----------------------------------------------------------
+pkgexec="$package/Contents/MacOS"
+pkgbin="$package/Contents/Resources/bin"
+pkglib="$package/Contents/Resources/lib"
+pkglocale="$package/Contents/Resources/locale"
+pkgpython="$package/Contents/Resources/python/site-packages/"
+pkgresources="$package/Contents/Resources"
+
+mkdir -p "$pkgexec"
+mkdir -p "$pkgbin"
+mkdir -p "$pkglib"
+mkdir -p "$pkglocale"
+mkdir -p "$pkgpython"
+
+mkdir -p "$pkgresources/Dutch.lprj"
+mkdir -p "$pkgresources/English.lprj"
+mkdir -p "$pkgresources/French.lprj"
+mkdir -p "$pkgresources/German.lprj"
+mkdir -p "$pkgresources/Italian.lprj"
+mkdir -p "$pkgresources/Spanish.lprj"
+mkdir -p "$pkgresources/fi.lprj"
+mkdir -p "$pkgresources/no.lprj"
+mkdir -p "$pkgresources/sv.lprj"
+
+# Build and add the launcher
+#----------------------------------------------------------
+(
+	# Build fails if CC happens to be set (to anything other than CompileC)
+	unset CC
+	
+	cd "$resdir/ScriptExec"
+	echo -e "\033[1mBuilding launcher...\033[0m\n"
+	xcodebuild $XCODEFLAGS clean build
+)
+cp "$resdir/$SCRIPTEXECDIR/ScriptExec" "$pkgexec/Dia"
+
+
+# Copy all files into the bundle
+#----------------------------------------------------------
+echo -e "\n\033[1mFilling app bundle...\033[0m\n"
+
+binary_name=`basename "$binary"`
+binary_dir=`dirname "$binary"`
+
+# Dia's binary
+binpath="$pkgbin/dia-bin"
+cp -v "$binary" "$binpath"
+# TODO Add a "$verbose" variable and command line switch, which sets wether these commands are verbose or not
+
+# Share files
+rsync -av "$binary_dir/../share/$binary_name"/* "$pkgresources/"
+cp "$plist" "$package/Contents/Info.plist"
+rsync -av "$binary_dir/../share/locale"/* "$pkgresources/locale"
+
+# Copy GTK shared mime information
+mkdir -p "$pkgresources/share"
+cp -rp "$LIBPREFIX/share/mime" "$pkgresources/share/"
+
+# Icons and the rest of the script framework
+rsync -av --exclude ".svn" "$resdir"/Resources/* "$pkgresources/"
+
+# Update the ImageMagick path in startup script.
+
+# PkgInfo must match bundle type and creator code from Info.plist
+echo "APPLInks" > $package/Contents/PkgInfo
+
+# Pull in extra requirements for Pango and GTK
+pkgetc="$package/Contents/Resources/etc"
+mkdir -p $pkgetc/pango
+cp $LIBPREFIX/etc/pango/pangox.aliases $pkgetc/pango/
+# Need to adjust path and quote in case of spaces in path.
+sed -e "s,$LIBPREFIX,\"\${CWD},g" -e 's,\.so ,.so" ,g' $LIBPREFIX/etc/pango/pango.modules > $pkgetc/pango/pango.modules
+cat > $pkgetc/pango/pangorc <<END_PANGO
+[Pango]
+ModuleFiles=\${HOME}/.dia-etc/pango.modules
+[PangoX]
+AliasFiles=\${HOME}/.dia-etc/pangox.aliases
+END_PANGO
+
+# We use a modified fonts.conf file so only need the dtd
+mkdir -p $pkgetc/fonts
+cp $LIBPREFIX/etc/fonts/fonts.dtd $pkgetc/fonts/
+cp -r $LIBPREFIX/etc/fonts/conf.avail $pkgetc/fonts/
+cp -r $LIBPREFIX/etc/fonts/conf.d $pkgetc/fonts/
+
+mkdir -p $pkgetc/gtk-2.0
+sed -e "s,$LIBPREFIX,\${CWD},g" $LIBPREFIX/etc/gtk-2.0/gdk-pixbuf.loaders > $pkgetc/gtk-2.0/gdk-pixbuf.loaders
+sed -e "s,$LIBPREFIX,\${CWD},g" $LIBPREFIX/etc/gtk-2.0/gtk.immodules > $pkgetc/gtk-2.0/gtk.immodules
+
+pango_version=`pkg-config --variable=pango_module_version pango`
+mkdir -p $pkglib/pango/$pango_version/modules
+cp $LIBPREFIX/lib/pango/$pango_version/modules/*.so $pkglib/pango/$pango_version/modules/
+
+gtk_version=`pkg-config --variable=gtk_binary_version gtk+-2.0`
+mkdir -p $pkglib/gtk-2.0/$gtk_version/{engines,immodules,loaders,printbackends}
+cp -r $LIBPREFIX/lib/gtk-2.0/$gtk_version/* $pkglib/gtk-2.0/$gtk_version/
+
+# Find out libs we need from fink, darwinports, or from a custom install
+# (i.e. $LIBPREFIX), then loop until no changes.
+a=1
+nfiles=0
+endl=true
+while $endl; do
+	echo -e "\033[1mLooking for dependencies.\033[0m Round" $a
+	libs="`otool -L $pkglib/gtk-2.0/$gtk_version/{engines,immodules,loaders,printbackends}/*.{dylib,so} $pkglib/pango/$pango_version/modules/* $pkglib/gnome-vfs-2.0/modules/* $package/Contents/Resources/lib/* $pkglib/ImageMagick-$IMAGEMAGICKVER/modules-Q16/{filters,coders}/*.so $binary 2>/dev/null | fgrep compatibility | cut -d\( -f1 | grep $LIBPREFIX | sort | uniq`"
+	cp -f $libs $package/Contents/Resources/lib
+	let "a+=1"	
+	nnfiles=`ls $package/Contents/Resources/lib | wc -l`
+	if [ $nnfiles = $nfiles ]; then
+		endl=false
+	else
+		nfiles=$nnfiles
+	fi
+done
+
+# Add extra libraries of necessary
+for libfile in $EXTRALIBS
+do
+	cp -f $libfile $package/Contents/Resources/lib
+done
+
+
+# Strip libraries and executables if requested
+#----------------------------------------------------------
+if [ "$strip" = "true" ]; then
+	echo -e "\n\033[1mStripping debugging symbols...\033[0m\n"
+	chmod +w "$pkglib"/*.dylib
+	strip -x "$pkglib"/*.dylib
+	strip -ur "$binpath"
+fi
+
+# NOTE: This works for all the dylibs but causes GTK to crash at startup.
+#				Instead we leave them with their original install_names and set
+#				DYLD_LIBRARY_PATH within the app bundle before running Dia.
+#
+fixlib () {
+	libPath="`echo $2 | sed 's/.*Resources//'`"
+	pkgPath="`echo $2 | sed 's/Resources\/.*/Resources/'`"
+	# Fix a given executable or library to be relocatable
+	if [ ! -d "$1" ]; then
+		libs="`otool -L $1 | fgrep compatibility | cut -d\( -f1`"
+		for lib in $libs; do
+			echo "	$lib"
+			base=`echo $lib | awk -F/ '{print $NF}'`
+			first=`echo $lib | cut -d/ -f1-3`
+			relative=`echo $lib | cut -d/ -f4-`
+			to= executable_path/../$relative
+			if [ $first != /usr/lib -a $first != /usr/X11 -a $first != /System/Library ]; then
+				/usr/bin/install_name_tool -change $lib $to $1
+				if [ "`echo $lib | fgrep libcrypto`" = "" ]; then
+					/usr/bin/install_name_tool -id $to $1
+					for ll in $libs; do
+						base=`echo $ll | awk -F/ '{print $NF}'`
+						first=`echo $ll | cut -d/ -f1-3`
+						relative=`echo $ll | cut -d/ -f4-`
+						to= executable_path/../$relative
+						if [ $first != /usr/lib -a $first != /usr/X11 -a $first != /System/Library -a "`echo $ll | fgrep libcrypto`" = "" ]; then
+							/usr/bin/install_name_tool -change $ll $to $pkgPath/$relative
+						fi
+					done
+				fi
+			fi
+		done
+	fi
+}
+
+rewritelibpaths () {
+	# 
+	# Fix package deps
+	(cd "$package/Contents/Resources/lib/gtk-2.0/2.10.0/loaders"
+	for file in *.so; do
+		echo "Rewriting dylib paths for $file..."
+		fixlib "$file" "`pwd`"
+	done
+	)
+	(cd "$package/Contents/Resources/lib/gtk-2.0/2.10.0/engines"
+	for file in *.so; do
+		echo "Rewriting dylib paths for $file..."
+		fixlib "$file" "`pwd`"
+	done
+	)
+	(cd "$package/Contents/Resources/lib/gtk-2.0/2.10.0/immodules"
+	for file in *.so; do
+		echo "Rewriting dylib paths for $file..."
+		fixlib "$file" "`pwd`"
+	done
+	)
+	(cd "$package/Contents/Resources/lib/gtk-2.0/2.10.0/printbackends"
+	for file in *.so; do
+		echo "Rewriting dylib paths for $file..."
+		fixlib "$file" "`pwd`"
+	done
+	)
+	(cd "$package/Contents/Resources/lib/pango/1.6.0/modules"
+	for file in *.so; do
+		echo "Rewriting dylib paths for $file..."
+		fixlib "$file" "`pwd`"
+	done
+	)
+	(cd "$package/Contents/Resources/bin"
+	for file in *; do
+		echo "Rewriting dylib paths for $file..."
+		fixlib "$file" "`pwd`"
+	done
+	cd ../lib
+	for file in *.dylib; do
+		echo "Rewriting dylib paths for $file..."
+		fixlib "$file" "`pwd`"
+	done
+	)
+}
+
+PATHLENGTH=`echo $LIBPREFIX | wc -c`
+if [ "$PATHLENGTH" -ge "50" ]; then
+	# If the LIBPREFIX path is long enough to allow 
+	# path rewriting, then do this.
+	rewritelibpaths
+else
+	echo "Could not rewrite dylb paths for bundled libraries.  This requires" >&2
+	echo "Macports to be installed in a PREFIX of at least 50 characters in length." >&2
+	echo "" >&2
+	echo "The package will still work if the following line is uncommented in" >&2
+	echo "Dia.app/Contents/Resources/bin/dia:" >&2
+	echo '        export DYLD_LIBRARY_PATH="$TOP/lib"' >&2
+	exit 1
+
+fi
+
+exit 0
diff --git a/installer/macosx/osx-build.sh b/installer/macosx/osx-build.sh
new file mode 100755
index 0000000..b3f19a2
--- /dev/null
+++ b/installer/macosx/osx-build.sh
@@ -0,0 +1,331 @@
+#!/bin/bash
+#
+#  Dia compilation and packaging script for Mac OS X
+#
+# Please see
+#  http://dia-installer.de/compiling.html
+# for more complete information
+#
+# Author:
+#	Steffen Macke <sdteffen sdteffen de>
+# with information from
+#	Jean-Olivier Irisson <jo irisson gmail com>
+#	Kees Cook
+#	Michael Wybrow
+#
+# Copyright (C) 2006-2010
+# Released under GNU GPL, read the file 'COPYING' for more information
+#
+
+############################################################
+
+# User modifiable parameters
+#----------------------------------------------------------
+# Configure flags
+CONFFLAGS="--enable-osxapp"
+# Libraries prefix (Warning: NO trailing slash)
+LIBPREFIX="/opt/local"
+# User name on Modevia
+MODEVIA_NAME=""
+
+############################################################
+
+# Help message
+#----------------------------------------------------------
+help()
+{
+
+echo -e "
+Compilation script for Dia on Mac OS X.
+
+\033[1mUSAGE\033[0m
+  $0 [options] action[s]
+
+\033[1mACTIONS & OPTIONS\033[0m
+  \033[1mh,help\033[0m	
+    display this help message
+  \033[1mu,up,update\033[0m
+    update an existing checkout from svn (run svn up)
+  \033[1ma,auto,autogen\033[0m
+    prepare configure script (run autogen.sh). This is only necessary
+    for a fresh svn checkout or after make distclean.
+  \033[1mc,conf,configure\033[0m
+    configure the build (run configure). Edit your configuration
+    options in $0
+    \033[1m-p,--prefix\033[0m	specify install prefix (configure step only)
+  \033[1mb,build\033[0m
+    build Dia (run make)
+  \033[1mi,install\033[0m
+    install the build products locally, inside the source
+    directory (run make install)
+  \033[1mp,pack,package\033[0m
+    package Dia in a double clickable .app bundle 
+    \033[1m-s,--strip\033[0m	remove debugging information in Dia package
+    \033[1m-py,--with-python\033[0m	specify python modules path for inclusion into the app bundle
+  \033[1md,dist,distrib\033[0m
+    store Dia.app in a disk image (dmg) for distribution
+  \033[1mput,upload\033[0m
+    upload the dmg and the associate info file on Modevia server
+  \033[1mall\033[0m
+    do everything (update, configure, build, install, package, distribute)
+
+\033[1mEXAMPLES\033[0m
+  \033[1m$0 conf build install\033[0m
+    configure, build and install a dowloaded version of Dia in the default
+    directory, keeping debugging information.	
+  \033[1m$0 u a c b -p ~ i -s -py ~/site-packages/ p d\033[0m
+    update an svn checkout, prepare configure script, configure,
+    build and install Dia in the user home directory (~). 	
+    Then package Dia without debugging information,
+    with python packages from ~/site-packages/ and prepare 
+    a dmg for distribution."
+}
+
+# Parameters
+#----------------------------------------------------------
+# Paths
+HERE=`pwd`
+SRCROOT=$HERE/../..		# we are currently in packaging/macosx
+
+# Defaults
+if [ "$INSTALLPREFIX" = "" ]
+then
+	INSTALLPREFIX=$SRCROOT/Build/
+fi
+SVNUPDATE="f"
+AUTOGEN="f"
+CONFIGURE="f"
+BUILD="f"
+INSTALL="f"
+PACKAGE="f"
+DISTRIB="f"
+UPLOAD="f"
+
+STRIP=""
+PYTHON_MODULES=""
+
+# Parse command line options
+#----------------------------------------------------------
+while [ "$1" != "" ]
+do
+	case $1 in
+	h|help)
+		help 
+		exit 1 ;;
+	all)            
+		SVNUPDATE="t"
+		CONFIGURE="t"
+		BUILD="t" 
+		INSTALL="t"
+		PACKAGE="t"
+		DISTRIB="t" ;;
+   u|up|update)
+		SVNUPDATE="t" ;;
+   a|auto|autogen)
+		AUTOGEN="t" ;;
+	c|conf|configure)
+		CONFIGURE="t" ;;
+	b|build)
+		BUILD="t" ;;
+	i|install)
+		INSTALL="t" ;;
+	p|pack|package)
+		PACKAGE="t" ;;
+	d|dist|distrib)
+		DISTRIB="t" ;;
+	put|upload)
+		UPLOAD="t" ;;
+	-p|--prefix)
+	  	INSTALLPREFIX=$2
+	  	shift 1 ;;
+	-s|--strip)
+	     	STRIP="-s" ;;
+	-py|--with-python)
+		PYTHON_MODULES="$2"
+		shift 1 ;;
+	*)
+		echo "Invalid command line option: $1" 
+		exit 2 ;;
+	esac
+	shift 1
+done
+
+
+# Set environment variables
+# ----------------------------------------------------------
+export LIBPREFIX
+
+# Specific environment variables
+#  automake seach path
+export CPATH="$LIBPREFIX/include"
+#  configure search path
+export CPPFLAGS="-I$LIBPREFIX/include"
+# export CPPFLAGS="-I$LIBPREFIX/include -I /System/Library/Frameworks/Carbon.framework/Versions/Current/Headers"
+export LDFLAGS="-L$LIBPREFIX/lib"
+#  compiler arguments
+export CFLAGS="-O3 -Wall"
+export CXXFLAGS="$CFLAGS"
+
+
+# Actions
+# ----------------------------------------------------------
+if [[ "$SVNUPDATE" == "t" ]]
+then
+	cd $SRCROOT
+	svn up
+	status=$?
+	if [[ $status -ne 0 ]]; then
+		echo -e "\nSVN update failed"
+		exit $status
+	fi
+	cd $HERE
+fi
+
+if [[ "$AUTOGEN" == "t" ]]
+then
+	cd $SRCROOT
+	./autogen.sh
+	status=$?
+	if [[ $status -ne 0 ]]; then
+		echo -e "\nautogen failed"
+		exit $status
+	fi
+	cd $HERE
+fi
+
+if [[ "$CONFIGURE" == "t" ]]
+then
+	ALLCONFFLAGS=`echo "$CONFFLAGS --prefix=$INSTALLPREFIX"`
+	cd $SRCROOT
+	if [ ! -f configure ]
+	then
+		echo "Configure script not found in $SRCROOT. Run '$0 autogen' first"
+		exit 1
+	fi
+	./configure $ALLCONFFLAGS
+	status=$?
+	if [[ $status -ne 0 ]]; then
+		echo -e "\nConfigure failed"
+		exit $status
+	fi
+	cd $HERE
+fi
+
+if [[ "$BUILD" == "t" ]]
+then
+	cd $SRCROOT
+	make
+	status=$?
+	if [[ $status -ne 0 ]]; then
+		echo -e "\nBuild failed"
+		exit $status
+	fi
+	cd $HERE
+fi
+
+if [[ "$INSTALL" == "t" ]] 
+then
+	cd $SRCROOT
+	make install
+	status=$?
+	if [[ $status -ne 0 ]]; then
+		echo -e "\nInstall failed"
+		exit $status
+	fi
+	cd $HERE
+fi
+
+if [[ "$PACKAGE" == "t" ]]
+then
+	
+	# Test the existence of required files
+	if [ ! -e $INSTALLPREFIX/bin/dia ]
+	then
+		echo "The dia executable \"$INSTALLPREFIX/bin/dia\" cound not be found."
+		exit 1
+	fi
+	if [ ! -e $SRCROOT/Info.plist ]
+	then
+		echo "The file \"$SRCROOT/Info.plist\" could not be found, please re-run configure."
+		exit 1
+	fi
+	
+	# Set python command line option (if PYTHON_MODULES location is not empty, then add the python call to the command line, otherwise, stay empty)
+	if [[ "$PYTHON_MODULES" != "" ]]; then
+		PYTHON_MODULES="-py $PYTHON_MODULES"
+		# TODO: fix this: it does not allow for spaces in the PATH under this form and cannot be quoted
+	fi
+
+	# Create app bundle
+	./osx-app.sh $STRIP -b $INSTALLPREFIX/bin/dia -p $SRCROOT/Info.plist $PYTHON_MODULES
+	status=$?
+	if [[ $status -ne 0 ]]; then
+		echo -e "\nApplication bundle creation failed"
+		exit $status
+	fi
+fi
+
+# Fetch some information
+REVISION=`head -n 4 ../../.svn/entries | tail -n 1`
+ARCH=`arch | tr [p,c] [P,C]`
+MINORVERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d \.`
+NEWNAME="Dia-$REVISION-10.$MINORVERSION-$ARCH"
+DMGFILE="$NEWNAME.dmg"
+INFOFILE="$NEWNAME-info.txt"
+
+if [[ "$DISTRIB" == "t" ]]
+then
+	# Create dmg bundle
+	./osx-dmg.sh -p "Dia.app"
+	status=$?
+	if [[ $status -ne 0 ]]; then
+		echo -e "\nDisk image creation failed"
+		exit $status
+	fi
+
+	mv Dia.dmg $DMGFILE
+	
+	# Prepare information file
+	echo "Version information on $DATE for `whoami`:
+	OS X       `/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d \:`
+	Architecture $ARCH
+	DarwinPorts  `port version | cut -f2 -d \ `
+	GCC          `gcc --version | grep GCC`
+	GTK          `pkg-config --modversion gtk+-2.0`
+	GTKmm        `pkg-config --modversion gtkmm-2.4`
+	Cairo        `pkg-config --modversion cairo`
+	Cairomm      `pkg-config --modversion cairomm-1.0`
+	CairoPDF     `pkg-config --modversion cairo-pdf`
+	Pango        `pkg-config --modversion pango`
+Configure options:
+	$CONFFLAGS" > $INFOFILE
+	if [[ "$STRIP" == "t" ]]; then
+		echo "Debug info
+	no" >> $INFOFILE
+	else
+		echo "Debug info
+	yes" >> $INFOFILE
+	fi	
+fi
+
+if [[ "$UPLOAD" == "t" ]]
+then
+	# Provide default for user name on modevia
+	if [[ "$MODEVIA_NAME" == "" ]]; then
+		MODEVIA_NAME=$USER
+	fi
+	# Uploasd file
+	scp $DMGFILE $INFOFILE "$MODEVIA_NAME"@dia.modevia.com:dia/docs/macosx-snap/
+	status=$?
+	if [[ $status -ne 0 ]]; then
+		echo -e "\nUpload failed"
+		exit $status
+	fi
+fi
+
+if [[ "$PACKAGE" == "t" || "$DISTRIB" == "t" ]]; then
+	# open a Finder window here to admire what we just produced
+	open .
+fi
+
+exit 0
diff --git a/installer/macosx/osx-dmg.sh b/installer/macosx/osx-dmg.sh
new file mode 100755
index 0000000..1bf5fed
--- /dev/null
+++ b/installer/macosx/osx-dmg.sh
@@ -0,0 +1,179 @@
+#!/bin/sh
+#
+# USAGE
+# osx-dmg [-s] -p /path/to/Dia.app
+#
+# The script creates a read-write disk image, 
+# copies Dia in it, customizes its appearance using a 
+# previously created .DS_Store file (dia.ds_store),
+# and then compresses the disk image for distribution.
+#
+# AUTHORS
+#	Jean-Olivier Irisson <jo irisson gmail com>
+#	Michael Wybrow <mjwybrow users sourceforge net>
+#	Steffen Macke <sdteffen sdteffen de>
+#
+# Copyright (C) 2006-2010
+# Released under GNU GPL, read the file 'COPYING' for more information
+#
+#
+# How to update the disk image layout:
+# ------------------------------------
+#
+# Modify the 'dmg_background.svg' file and generate a new 
+# 'dmg_background.png' file.
+#
+# Update the AppleScript file 'dmg_set_style.scpt'.
+#
+# Run this script with the '-s' option.  It will apply the
+# 'dmg_set_style.scpt' AppleScript file, and then prompt the
+# user to check the window size and position before writing
+# a new 'dia.ds_store' file to work around a bug in Finder
+# and AppleScript.  The updated 'dia.ds_store' will need 
+# to be commited to the repository when this is done.
+#
+
+# Defaults
+set_ds_store=false
+ds_store_file="dia.ds_store"
+package=""
+rw_name="RWdia.dmg"
+volume_name="Dia"
+tmp_dir="/tmp/dmg-$$"
+auto_open_opt=
+
+# Help message
+#----------------------------------------------------------
+help()
+{
+echo "
+Create a custom dmg file to distribute Dia
+
+\033[1mUSAGE\033[0m
+	$0 [-s] -p /path/to/Dia.app
+
+\033[1mOPTIONS\033[0m
+	\033[1m-h,--help\033[0m 
+		display this help message
+	\033[1m-s\033[0m
+		set a new apperance (do not actually creates a bundle)
+	\033[1m-p,--package\033[0m
+		set the path to the Dia.app that should be copie
+		in the dmg
+"
+}
+
+# Parse command line arguments
+while [ "$1" != "" ]
+do
+	case $1 in
+	  	-h|--help)
+			help
+			exit 0 ;;
+	  	-s)
+			set_ds_store=true ;;
+	  	-p|--package)
+			package="$2"
+			shift 1 ;;
+		*)
+			echo "Invalid command line option" 
+			exit 2 ;;
+	esac
+	shift 1
+done
+
+# Safety checks
+if [ ! -e "$package" ]; then
+	echo "Cannot find package: $package"
+	exit 1
+fi
+
+echo "\n\033[1mCREATE DIA DISK IMAGE\033[0m\n"
+
+# Create temp directory with desired contents of the release volume.
+rm -rf "$tmp_dir"
+mkdir "$tmp_dir"
+
+echo "\033[1mCopying files to temp directory\033[0m"
+# Dia itself
+# copy Dia.app
+cp -rf "$package" "$tmp_dir"/
+# link to Applications in order to drag and drop dia onto it
+ln -sf /Applications "$tmp_dir"/
+
+# Copy a background image inside a hidden directory so the image file itself won't be shown.
+mkdir "$tmp_dir/.background"
+cp dmg_background.png "$tmp_dir/.background/background.png"
+
+# If the appearance settings are not to be modified we just copy them
+if [ ${set_ds_store} = "false" ]; then
+	# Copy the .DS_Store file which contains information about
+	# window size, appearance, etc.  Most of this can be set
+	# with Apple script but involves user intervention so we
+	# just keep a copy of the correct settings and use that instead.
+	cp $ds_store_file "$tmp_dir/.DS_Store"
+	auto_open_opt=-noautoopen
+fi
+
+# Create a new RW image from the temp directory.
+echo "\033[1mCreating a temporary disk image\033[0m"
+rm -f "$rw_name"
+/usr/bin/hdiutil create -srcfolder "$tmp_dir" -volname "$volume_name" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW "$rw_name"
+
+# We're finished with the temp directory, remove it.
+rm -rf "$tmp_dir"
+
+# Mount the created image.
+MOUNT_DIR="/Volumes/$volume_name"
+DEV_NAME=`/usr/bin/hdiutil attach -readwrite -noverify $auto_open_opt  "$rw_name" | egrep '^/dev/' | sed 1q | awk '{print $1}'`
+
+# Have the disk image window open automatically when mounted.
+bless -openfolder /Volumes/$volume_name
+
+# In case the apperance has to be modified, mount the image and apply the base settings to it via Applescript
+if [ ${set_ds_store} = "true" ]; then
+	/usr/bin/osascript dmg_set_style.scpt
+
+	open "/Volumes/$volume_name"
+	# BUG: one needs to move and close the window manually for the
+	# changes in appearance to be retained... 
+        echo " 
+        ************************************** 
+        *  Please move the disk image window * 
+        *    to the center of the screen     *  
+        *   then close it and press enter    * 
+        ************************************** 
+        " 
+        read -e DUMB
+
+	# .DS_Store files aren't written till the disk is unmounted, or finder is restarted.
+	hdiutil detach "$DEV_NAME"
+	auto_open_opt=-noautoopen
+	DEV_NAME=`/usr/bin/hdiutil attach -readwrite -noverify $auto_open_opt  "$rw_name" | egrep '^/dev/' | sed 1q | awk '{print $1}'`
+	echo
+	echo "New $ds_store_file file written. Re-run $0 without the -s option to use it"
+	cp /Volumes/$volume_name/.DS_Store ./$ds_store_file
+	SetFile -a v ./$ds_store_file
+
+	# Unmount the disk image.
+	hdiutil detach "$DEV_NAME"
+	rm -f "$rw_name"
+
+	exit 0
+fi
+
+# Unmount the disk image.
+hdiutil detach "$DEV_NAME"
+
+# Create the offical release image by compressing the RW one.
+echo "\033[1mCompressing the final disk image\033[0m"
+img_name="Dia.dmg"
+# TODO make this a command line option
+if [ -e "$img_name" ]; then
+	echo "$img_name already exists."
+	rm -i "$img_name"
+fi
+/usr/bin/hdiutil convert "$rw_name" -format UDZO -imagekey zlib-level=9 -o "$img_name"
+rm -f "$rw_name"
+
+exit 0



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]