www.pudn.com > sswf-1.7.4-src.zip > dotar


#!/bin/sh
#
# Script used to generate the sswf (Script to SWF) tar balls
# Written by Alexis Wilke for Made to Order Software, Ltd. (c) 2002-2006
#
# Copyright (c) 2002-2006 Made to Order Software, Ltd.
#
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and
# associated documentation files (the "Software"), to
# deal in the Software without restriction, including
# without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom
# the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice
# shall be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
# ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
# EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

set -e


if test "$1" = "-h" -o "$1" = "--help"
then
	echo "Usage: $0 [-opt]"
	echo "Where -opt is one or more of the following:"
	echo "  -notest        don't run amake to make sure the packages compile"
	echo "                 and the samples work"
	echo "  -keeparchive   don't test whether the archive already exist and"
	echo "                 if it does don't delete it (useful when you don't"
	echo "                 want to recreate the source and documentation packages)"
	echo "  -OVERWRITE     don't ask whether to overwrite the existing packages"
	echo "  -remove_arch   to force all the architectures to be rebuilt"
	echo "  -nosrc         don't regenerate the source package if it exists"
	echo "                 (this option requires the -keeparchive)"
	echo "  -nodoc         don't regenerate the documentation package if it exists"
	echo "                 (this option requires the -keeparchive)"
	echo "  -noforeign     skip generation of foreign modules (Mac, Win, SGI)"
	echo "    -nowin       skip generation of Win/MinGW modules"
	echo "    -nomac       skip generation of Mac OS/X modules"
	echo "    -nosgi       skip generation of SGI modules"
	echo "    -nolinuxonpower  skip generation of Linux on Power module"
	echo "  -nolinux       don't generate the linux packages"
	echo "  -norpm         don't generate the RedHat RPM package"
	echo "  -nodebian      don't generate the Debian package"
	echo "  -noslackware   don't generate the Slackware package"
	echo "  -nocleanup     don't do any cleanup at the end"
	exit 1;
fi





start_date=`date +%H:%M:%S`
notest=false
keeparchive=false
OVERWRITE=false
remove_arch=false
nosrc=false
nodoc=false
noforeign=false
nowin=false
nomac=false
nosgi=false
nolinuxonpower=false
nolinux=false
norpm=false
nodebian=false
noslackware=false
nocleanup=false
while ! test "$1" = ""
do
	case "$1" in
	-notest*|--notest*) notest=true;;
	-keeparchive*|--keeparchive*) keeparchive=true;;
	-OVERWRITE|--OVERWRITE) OVERWRITE=true;;
	-remove_arch*|--remove_arch*) remove_arch=true;;
	-nosrc*|--nosrc*) nosrc=true;;
	-nodoc*|--nodoc*) nodoc=true;;
	-noforeign*|--noforeign*) noforeign=true;;
	-nowin*|--nowin*) nowin=true;;
	-nomac*|--nomac*) nomac=true;;
	-nosgi*|--nosgi*) nosgi=true;;
	-nolinuxonpower*|--nolinuxonpower*) nolinuxonpower=true;;
	-nolinux*|--nolinux*) nolinux=true;;
	-norpm*|--norpm*) norpm=true;;
	-nodebian*|--nodebian*) nodebian=true;;
	-noslackware*|--noslackware*) noslackware=true;;
	-nocleanup*|--nocleanup*) nocleanup=true;;
	*) echo "ERROR: unknown option \"$1\"."; exit 1;;
	esac
	shift
done


echo "Initialization"


COPY="cp --recursive --no-dereference --preserve=links"


package_date=`date -u`

##############################
# Ensure all the necessary targets
# 1) can be compiled properly
#    (this is also done when creating the RPM)
# 2) do generate all the flash movie samples
#    (if the samples fail, we need to look into it!)
##############################

if $notest
then
	echo "Skipping SSWF samples test"
else

	test_make() {
		# Now we do a clean to make sure we can compile in RELEASE
		# and DEBUG modes
		amake -s clean
		amake -s all
		amake -s samples
	}

	# Since we still pack the debug, test the release first...
	(
		export DEBUG=0
		export YYDEBUG=0
		test_make
	)
	test_make

	echo "Samples tests passed in RELEASE and DEBUG. Create packages now."

	## We need to clean before to go on
	amake -s -C samples/check_version clean
	amake -s -C samples/news-samples clean
	amake -s -C samples/showfont clean

	## We want the notes and changes in HTML
	amake -s tmp/NOTES.html tmp/CHANGES.html


fi



##############################
# Get the current packages version
##############################
VERSION=`grep "\\" include/sswf/libsswf-version.h | sed -e 's/.*\\([0-9]\\+\\.[0-9]\\+\\.[0-9]\\+\\).*/\\1/'`
PROJECT_PATH=`pwd`
CHECK_VERSION=`basename $PROJECT_PATH`

if test "sswf-$VERSION" != "$CHECK_VERSION"
then
	echo "ERROR: the current version in libsswf-version.h ($VERSION)"
	echo "       doesn't match the directory name: $PROJECT_PATH"
	echo
	echo "This usually means you are creating a newer version but"
	echo "forgot to either update the version or rename the directory."
	echo "The former could lead to duplicate versions. The later doesn't"
	echo "matter much but this script will fail anyway."
	echo
	echo "Please, rename the directory or fix the version in the header."
	exit 1;
fi




##############################
# Different installation info
##############################
INSTALL_DIR="/usr"
DST="sswf-$VERSION"
MAKEFILE_INSTALL="tmp/makefile.install"
MAKEFILE_TMP="tmp/makefile.tmp"
MAKEFILE_HEADER="tmp/makefile.header"
RPM_TMP="tmp/sswf"
CONFIGURE_AC="configure.ac"
FINK_INFO="sswf-fink.info"
WIN32_NSI="sswf-win32.nsi"
ARCHIVE="../packages/sswf-$VERSION"
TAR_TMP="tmp/tmp.tar"
MINGW_PATH="tmp/mingw"



# Before to generate the new packages, check to know whether it
# already exists, if so, the user is possibly making a mistake
# (i.e. forgot to increase the version)
need_source=true

#echo $keeparchive AND $OVERWRITE

if $keeparchive
then
	if test -d $ARCHIVE
	then
		echo "Archive $ARCHIVE already exist but it will be kept as is."
		# In this case we assume the sources & docs are valid
		need_source=false
	else
		echo "Archive $ARCHIVE doesn't exist yet, it will be created."
	fi
elif $OVERWRITE
then
	if test -d $ARCHIVE
	then
		echo "WARNING: this version ($VERSION) existed, it will be replaced now."
	fi
	rm -rf $ARCHIVE
else
	if test -d $ARCHIVE
	then
		echo "WARNING: this version ($VERSION) has already been packed."
		echo "WARNING: continuing will force a deletion of the existing packages."
		echo -n "WARNING: are you sure you want to overwrite it? (y/[n]) "
		read answer
		if test "$answer" != "y" -a "$answer" != "Y"
		then
			echo "WARNING: packaging cancelled"
			exit 1;
		fi
		echo
		echo
		# Remove the destination folder at once!
		rm -rf $ARCHIVE
	fi
fi;




if $remove_arch
then
	rm -rf arch
	echo "The directory arch was removed. All packages need to be rebuilt"
else
	echo "WARNING: when changing version you must remove the \"arch\" directory"
	echo "         at least once; did you do it? (-remove_arch command line option)"
fi


echo "Packaging SSWF version V$VERSION"

(
	echo "***********************************************"
	echo "*** SSWF V$VERSION"
	echo "***********************************************"
	echo
	echo "Package created on $package_date"
	echo "                on computer $HOSTNAME"
	echo "                with `uname -s -r -m -o`"
	echo "                by $USER"
	echo
	echo "This file was auto-generated by the dotar script"
	echo
) >misc/package_creation_date.txt

##############################
# All the files to be packed
##############################
COPYRIGHT_FILES="doc/AUTHORS.txt doc/CHANGES.txt doc/LICENSE.txt doc/LINKS.txt doc/NOTES.txt README.txt"
TOPACK_ALWAYS="$COPYRIGHT_FILES doc/INSTALL*.txt doc/TODO.txt doc/ASC-TODO.txt"
TOPACK_SRC="$TOPACK_ALWAYS
	amakefile dosamakefile dosamakefile.cl
	configure.ac Makefile.am doc/Makefile.am
	misc dev samples
	dotar sendall include src"
	#"GNUmakefile.osx scripts libsswf*.[ch]* sswf*.[chylv]* swf_dump.c
	#ft2sswf.c VC"
TOSTRIP_BIN="bin/sswf bin/swf_dump bin/ft2sswf bin/jpg2swf"
TOPACK_BIN="$TOPACK_ALWAYS include/sswf/scripts doc/man $TOSTRIP_BIN misc samples"
TOPACK_LIB="$TOPACK_ALWAYS lib include/sswf/*.h"
TOPACK_DOC="$TOPACK_ALWAYS doc"
#TOPACK_DEV="notes-to-html.c run
#	web-page/index.html web-page/sendall sf-dir/sf-compare showman
#	packages/*"


##############################
# Some preparation
##############################

	# Make sure the destination directories exist
mkdir -p $ARCHIVE


	# Create the makefile header (date of auto-generation, copyright, etc.)
	# The specific install commands are added later
(
	echo "#"
	echo "# Makefile auto-generated on $package_date"
	echo "# Use it to install SSWF on your system"
	echo "#" >>$MAKEFILE_HEADER
		# Add the copyright
	sed -e '/^#!amake$/,/^$/ p' -e d amakefile >$MAKEFILE_TMP
	sed -e '4,$ p' -e d $MAKEFILE_TMP
		# Add the version and installation directory
	echo 'VERSION="'$VERSION'"'
	echo 'INSTALL_DIR="'$INSTALL_DIR'"'
	echo
	echo 'install:'
) >$MAKEFILE_HEADER

	# Create the configure.ac with the correct version
sed -e "s//$VERSION/" dev/configure.ac >$CONFIGURE_AC

	# Create the Win32 installation script
sed -e "s//$VERSION/" dev/configure.ac >$CONFIGURE_AC



##############################
# Common functions
##############################


xtar() {
	if test "$1" = "-k"
	then
		x=exclude.txt
		shift
	else
		x=exclude-all.txt
	fi
	if test "$1" = "-i"
	then
		inside=true
		shift
	else
		inside=false
	fi
	if test "$1" = ""
	then
		src=$DST
	else
		src=$1
	fi
	tar cf $TAR_TMP $src -X dev/$x
	# the following extraction won't include the excluded files
	# which would otherwise be included in the .zip version!
	rm -rf $src
	tar xf $TAR_TMP
	if $inside; then
		main=`pwd`
		(cd $src; tar cf $main/$TAR_TMP *)
	else
		tar cf $TAR_TMP $src
	fi
}


create_makefile_install() {
	rm -rf $MAKEFILE_TMP
	for section in $*
	do
		sed -e "/# start install $section/,/end install $section/ p" -e d amakefile >>$MAKEFILE_TMP
	done
	cp $MAKEFILE_HEADER $MAKEFILE_INSTALL
	grep -v "# start" $MAKEFILE_TMP | grep -v "# end" >>$MAKEFILE_INSTALL
	echo >>$MAKEFILE_INSTALL
	mv $MAKEFILE_INSTALL $DST/makefile-$1.install
}



create_packages() {
	if test "$1" = "-k";
	then
		keep_swf=-k
		shift
	else
		keep_swf=
	fi
	if test "$1" = "-o";
	then
		all=false
		shift
	else
		all=true
	fi
	if test "$2" = "";
	then
		xtar $keep_swf
	else
		xtar $keep_swf -i $2
	fi
	echo -e "\tDestination: $ARCHIVE/$DST-$1.tar.bz2"
	bzip2 -c9 $TAR_TMP >$ARCHIVE/$DST-$1.tar.bz2
	if $all; then
		gzip -c9 $TAR_TMP >$ARCHIVE/$DST-$1.tar.gz

		# zip updates requires the current zip file to be
		# deleted and the xtar so the source directory has
		# the excluded files already removed
		rm -rf $ARCHIVE/$DST-$1.zip
		if test "$2" = "";
		then
			zip -qr9 $ARCHIVE/$DST-$1.zip $DST
		else
			main=`pwd`
			(cd $2; zip -qr9 $main/$ARCHIVE/$DST-$1.zip *)
		fi
	fi
}





######################################################################
#
#    Create the Source Archives
#    (which are necessary to create binaries on other systems)
#
######################################################################


	###########
	# Source code
	###########

create_source_packages() {
	echo "Creating source code package"
	WARN=$1
	rm -rf $DST
	mkdir -p $DST/VC
	$COPY --parents $TOPACK_SRC $DST
	rm -rf $DST/dev/tmp
	(
		cd $DST/VC
		for f in ../src/*/*.c++ ../samples/*/*.c++
		do
			echo "rename \"`echo $f | sed -e 'sX/X\\\\Xg'`\" \"`basename $f .c++`.cpp\"" >>rename_all.bat
		done
	)
	if test -f modules/win32-$VERSION-bin.tar.bz2
	then
		tar xjf modules/win32-$VERSION-bin.tar.bz2
		chmod -R 777 arch
		$COPY arch/win32/VC $DST
	elif test "$WARN" = "warn"
	then
		echo "WARNING: no grammar or lexical for MS-Windows environment"
	fi
	create_packages dev
	(
		cd $DST
		PATH=/usr/local/bin:/bin:/usr/bin
		autoreconf -i -f -v || exit 1
		# remove the cache used to create the Makefile.in & configure
		rm -rf auto*.cache
		echo "NOTE: the 'configure' script was created"
	)
	create_packages src
}

# Use -nosrc on the command line to skip this part
# However, if there isn't already an src package, create it anyway
if ! $need_source && $nosrc && test -f $ARCHIVE/$DST-src.tar.bz2
then
	echo "Skipping the pre-creation of the source packages"
else
	create_source_packages
fi

#echo "Stopping right after source packages..."
#exit 1;


	###########
	# Documentation
	###########

# Use -nodoc on the command line to skip this part
# However, if there isn't already a doc package, create it anyway
if ! $need_source && $nodoc && test -f $ARCHIVE/$DST-doc.tar.bz2
then
	echo "Skipping the creation of the documentation package."
else
	echo "Creating documentation package"
	rm -rf $DST
	mkdir -p $DST

	# We want to automatically put the version in the manual pages
	for file in dev/man/*.*
	do
		# extract the extension
		f=`basename $file`
		e=`echo $f | sed -e 's/.*\.\([0-9]\+\)$/\1/'`
		mkdir -p doc/man/man$e
		sed -e "s//$VERSION/" -e "s//`date -r $file`/" $file >doc/man/man$e/$f
	done

	# We want the HTML of the manual pages so anyone can read those.
	# Note that we avoid re-generating these files if they didn't
	# change since the last invocation of dotar.
	for file in doc/man/*/*.*
	do
		mkdir -p tmp/backup/`dirname $file`
		if ! cmp -s $file tmp/backup/$file
		then
			# This is a `basename $file `
			html=`echo $file | sed -e 's/.*\///' -e 's/\.[^.]*$//'`
			echo "Creating file: $html.html"
			if groff -m andoc -Thtml $file \
			| sed -e 'sXhttp:[a-zA-Z/.0-9]\+X&X' \
			| sed -e 's//&Back to the documentations index<\/a>/' \
			| sed -e 's/<\/body>/Back to the documentations index<\/a>&/' \
					>doc/html/$html.html
			then
				cp -f $file tmp/backup/$file
			fi
		fi
	done

	$COPY --parents $TOPACK_DOC $DST

	create_makefile_install doc manual
	create_packages -k doc
fi





##############################
#
#	Non-Linux Binary Generation
#
##############################


echo
echo



## I call modules the tar.bz2 files from other systems
## These are later extracted to create the actual packages
## (except for those which already are packages such as .deb files)
mkdir -p modules


## WARNING: we first build the windows packages for it will change
##	    the source package -- we want to save some of the
##	    generated files in the final source package, and
##	    since the source package MD5 is used in some other
##	    packages, we need to do this first. Then the source
##	    package is not allowed to change anymore.

if ! $noforeign
then
	## NOTE: no message about skipping foreign modules here
	##	 we will get that one on the next large if block!

	##################
	# MS-Windows (MinGW & Win32)
	##################

	if $nowin
	then
		echo "Skipping MS-Windows module and package generation (MinGW/Win32)"
	else
		## One of my Win32 box available?
		if ping -c1 -r -q -w3 helene >/dev/null
		then
			MINGW=helene
			export SSWF_DRIVE=D
		elif ping -c1 -r -q -w3 complex >/dev/null
		then
			MINGW=complex
			export SSWF_DRIVE=E
		else
			MINGW=""
		fi
		## NOTE: atelnet is one of my tool and one day it will be available
		##	 along with aftp... I just didn't yet find the time to make
		##	 a nice package for it!
		if test ! -z "$MINGW"
		then
			echo "Creating the Windows modules $VERSION from $MINGW"
			export SSWF_VERSION=$VERSION

			(
			# We already have the VERSION variable set
			MAJOR=`echo $VERSION | sed -e 's/\.[0-9]*\.[0-9]*//'`
			RELEASE=`echo $VERSION | sed -e 's/[0-9]*\.\([0-9]*\)\.[0-9]*/\1/'`
			MINOR=`echo $VERSION | sed -e 's/[0-9]*\.[0-9]*\.//'`
			# In order to define the samples and sources
			# we want in the win32 package we simulate the
			# creation of a tar file
			tar -cvf /dev/null samples -X dev/exclude-win32.txt \
				| grep -v '\/$' | sed -e 's/\//\\/g' \
				| sed -e 's%\(.\+\)\\\([^\/]\+\)%        SetOutPath "$INSTDIR\\${VERSION}\\\1"\r\n        File \"\1\\\2\"%' >tmp/samples.txt
			tar -cvf /dev/null src -X dev/exclude-win32.txt \
				| grep -v '\/$' | sed -e 's/\//\\/g' \
				| sed -e 's%\(.\+\)\\\([^\/]\+\)%        SetOutPath "$INSTDIR\\${VERSION}\\\1"\r\n        File \"\1\\\2\"%' >tmp/sources.txt
			sed -e "s//$VERSION/" -e "s//$MAJOR/" \
				-e "s//$RELEASE/" -e "s//$MINOR/" \
				-e "// r tmp/samples.txt" -e "// d" \
				-e "// r tmp/sources.txt" -e "// d" \
					dev/$WIN32_NSI >tmp/$WIN32_NSI
			)

			atelnet --show-cmd --nosize -c dev/mingw-build.atelnet $MINGW >tmp/mingw.txt 2>&1
			echo "NOTE: windows modules created; you can find the output in tmp/mingw.txt"
		else
			echo "WARNING: no Windows box running!"
			echo "WARNING: the current modules will be used..."
		fi
	fi
fi


###########
# Sources
###########
# Because the MS-Windows version adds a few files to the source
# package, we have to re-generate it now.
# (NOTE: it may not really be necessary, but that's a good way
# to make sure it's correct!)
# Below, this final version of the source package is used in the
# Mac OS/X packages and an MD5 for it is generated. Thus we must
# make sure that the source package doesn't change after this.
if ! $nosrc
then
	create_source_packages warn
fi



if $noforeign
then
	echo "Skipping the generation of all foreign modules and packages at once"
else
	##################
	# Mac OS/X
	##################
	## Now that we have the source and documentation we can
	## generate the proper info file for fink (we need the
	## MD5 for debian packages.)
	if $nomac
	then
		echo "Skipping Mac module and packages generation (Mac OS/X)"
	else
		## My iMac box available?
		if ping -c1 -r -q -w3 iMac >/dev/null
		then
			MACOSX=iMac
		else
			MACOSX=
		fi
		if test ! -z "$MACOSX"
		then
			echo "Creating the Mac modules $VERSION from $MACOSX"

			# We put the set in sub-shells to make sure
			# we don't destroy the command line $1, $2...
			(
			set `md5sum $ARCHIVE/$DST-src.tar.gz`
			MD5SRC=$1
			set `md5sum $ARCHIVE/$DST-doc.tar.gz`
			MD5DOC=$1
			sed -e "s//$VERSION/" -e "s//$MD5SRC/" \
				-e "s//$MD5DOC/" -e "s%%$COPYRIGHT_FILES%" \
					dev/$FINK_INFO >modules/$FINK_INFO
			)

			## Make sure I have the sswf directory
			echo "Creating the Mac OS/X modules"
			(
			ssh -l alexiswilke $MACOSX mkdir -p sswf
			scp $ARCHIVE/$DST-src.tar.gz alexiswilke@$MACOSX:/sw/src
			scp $ARCHIVE/$DST-doc.tar.gz alexiswilke@$MACOSX:/sw/src
			scp modules/$FINK_INFO alexiswilke@$MACOSX:/sw/fink/dists/local/main/finkinfo/$DST-3.info
			ssh -l alexiswilke $MACOSX ". ./.profile;
				set -e -v;
				cd sswf;
				fink -k rebuild $DST-3;
				if test -f $DST; then
					chmod -R 777 $DST;
					rm -rf $DST;
				fi;
				tar xzf /sw/src/$DST-src.tar.gz;
				tar xzf /sw/src/$DST-doc.tar.gz;
				cd $DST;
				amake macinstall;
				rm -rf arch;
				mkdir -p arch/darwin/bin;
				mkdir -p arch/darwin/lib;
				mkdir -p arch/darwin/packages;
				cp /sw/fink/debs/sswf*$VERSION*.deb arch/darwin/packages;
				cp sswf-$VERSION-darwin-powerpc.dmg arch/darwin/packages;
				cp bin/* arch/darwin/bin;
				strip arch/darwin/bin/*;
				cp lib/libsswf.a arch/darwin/lib;
				cp lib/libsswf.dylib arch/darwin/lib/libsswf-$VERSION.dylib;
				cp lib/libsswf_as.a arch/darwin/lib;
				cp lib/libsswf_as.dylib arch/darwin/lib/libsswf_as-$VERSION.dylib;
				cp lib/libsswf_asas.a arch/darwin/lib;
				cp lib/libsswf_asas.dylib arch/darwin/lib/libsswf_asas-$VERSION.dylib;
				tar cjf ../darwin-$VERSION-bin.tar.bz2 arch"
			scp alexiswilke@$MACOSX:sswf/darwin-$VERSION-bin.tar.bz2 modules
			) >tmp/darwin.txt 2>&1
			echo "NOTE: Mac OS/X modules created; you can find the output in tmp/darwin.txt"
		else
			echo "WARNING: no Mac OS/X box running!"
			echo "WARNING: the current modules will be used..."
		fi
	fi


	##################
	# IRIX
	##################
	## My SGI box available?
	if $nosgi
	then
		echo "Skipping SGI module and package generation (IRIX)"
	else
		if ping -c1 -r -q -w3 oxygen >/dev/null
		then
			IRIX=oxygen
		else
			IRIX=
		fi
		if test ! -z "$IRIX"
		then
			echo "Creating the IRIX modules $VERSION from $IRIX"

			(
			rsh $IRIX "rm -rf tools/sswf/sswf-$VERSION-*.tar.bz2 tools/sswf/sswf-$VERSION"
			rcp ../packages/sswf-$VERSION/sswf-$VERSION-src.tar.bz2 $IRIX:tools/sswf
			rcp ../packages/sswf-$VERSION/sswf-$VERSION-doc.tar.bz2 $IRIX:tools/sswf
			rsh $IRIX "cd tools/sswf;
				bunzip2 -c sswf-$VERSION-src.tar.bz2 | tar xf -;
				bunzip2 -c sswf-$VERSION-doc.tar.bz2 | tar xf -;
				cd sswf-$VERSION;
				pwd;
				amake -f amakefile irix-tar"
			rcp $IRIX:tools/sswf/sswf-$VERSION/modules/irix-$VERSION-bin.tar.bz2 modules
			) >tmp/irix.txt 2>&1
			echo "NOTE: irix modules created; you can find the output in tmp/irix.txt"
		else
			echo "WARNING: no IRIX box running!"
			echo "WARNING: the current modules will be used..."
		fi
	fi


	##################
	# Linux on Power RPM
	##################
	## Create an RPM distribution for Linux on Power

	if $nolinuxonpower
	then
		echo "Skipping the generation of the RPM packages for Linux on Power"
	else
		## Is the Linux on Power box available?
		## We can't use ping because they don't echo those...
		## if ping -c1 -r -q -w3 upegr.up.edu >/dev/null
		LINUXONPOWER=upegr.up.edu
		LOPPORT=2222
		if test ! -z "$LINUXONPOWER"
		then
			echo "Creating the LinuxOnPower modules $VERSION from $LINUXONPOWER"

			RPM_ARCH=ppc

			sed -e "s//$VERSION/" -e "s@@freetype2@" dev/sswf-rpm.spec >tmp/sswf.spec

			(
			# Send files over
			echo "=================================================="
			echo "Sending files over..."
			ssh -l alexis_wilke -p $LOPPORT $LINUXONPOWER "mkdir -p sswf tmp"
			scp -P $LOPPORT $ARCHIVE/$DST-src.tar.gz alexis_wilke@$LINUXONPOWER:sswf/.
			scp -P $LOPPORT $ARCHIVE/$DST-doc.tar.gz alexis_wilke@$LINUXONPOWER:sswf/.
			scp -P $LOPPORT tmp/sswf.spec alexis_wilke@$LINUXONPOWER:sswf/.
			scp -P $LOPPORT dev/_rpmmacros alexis_wilke@$LINUXONPOWER:sswf/.

			# Build RPM
			echo "=================================================="
			echo "Start RPM build..."
			ssh -l alexis_wilke -p $LOPPORT $LINUXONPOWER ". ./.profile;
				set -e -v;
				sed -e \"s@@\`pwd\`/sswf@\" -e \"s@@\`pwd\`/sswf@\" \\
				    -e \"s@@\`pwd\`/tmp@\" sswf/_rpmmacros >\$HOME/.rpmmacros;
				cd sswf;
				mkdir -p {sswf-root,BUILD,$RPM_ARCH};
				if ! rpmbuild -bb --quiet --target $RPM_ARCH-m2osw-linux sswf.spec;
				then
					exit 1;
				fi"

			# Retrieve result
			echo "=================================================="
			echo "Getting result..."
			scp -P $LOPPORT alexis_wilke@$LINUXONPOWER:sswf/$RPM_ARCH/$DST-3.$RPM_ARCH.rpm modules/$DST-3.$RPM_ARCH.linuxonpower.rpm

			# We don't need to keep anything on that system...
			ssh -l alexis_wilke -p $LOPPORT $LINUXONPOWER "rm -rf sswf tmp"
			) >tmp/linuxonpower.txt 2>&1

			if test -f modules/$DST-3.$RPM_ARCH.linuxonpower.rpm
			then
				echo "NOTE: the Linux on Power RPM package was created;"
				echo "      you can find the output in tmp/linuxonpower.txt"
			else
				echo "WARNING: Linux on Power RPM build failed"
			fi
		fi
	fi



fi


if test ! -f modules/mingw-$VERSION-bin.tar.bz2 -o ! -f modules/win32-$VERSION-bin.tar.bz2 -o ! -f modules/mingw-3.3_sswf-$VERSION-src.tar.bz2
then
	echo "WARNING:"
	echo "WARNING: there is no Windows modules available"
	echo "WARNING:"
fi


if test ! -f modules/irix-$VERSION-bin.tar.bz2
then
	echo "WARNING:"
	echo "WARNING: there is no IRIX modules available"
	echo "WARNING:"
fi

if test ! -f modules/darwin-$VERSION-bin.tar.bz2
then
	echo "WARNING:"
	echo "WARNING: there is no Mac OS/X modules available"
	echo "WARNING:"
fi


if test ! -f modules/$DST-3.ppc.linuxonpower.rpm
then
	echo "WARNING:"
	echo "WARNING: there is no Linux on Power module available"
	echo "WARNING:"
fi


######################################################################
#
#    Regenerate the Source Packages
#    Create the Binary Packages
#    Create the Library Packages
#
######################################################################


if $nolinux
then
	echo "Skipping the generation of the Linux packages"
else



	###########
	# Binaries
	###########
	echo "Creating binaries package"
	rm -rf $DST
	mkdir -p $DST
	$COPY --parents $TOPACK_BIN $DST
	(cd $DST; strip $TOSTRIP_BIN)
	create_makefile_install bin script manual
	create_packages bin-linux-i486



	###########
	# Library
	###########
	echo "Creating library package"
	rm -rf $DST
	mkdir -p $DST
	$COPY --parents $TOPACK_LIB $DST
	mv $DST/lib/libsswf.so $DST/lib/libsswf-$VERSION.so
	ln -s libsswf-$VERSION.so $DST/lib/libsswf.so
	create_makefile_install lib
	create_packages lib-linux-i486

fi






##################
# RPM
##################
## Create an RPM distribution


if $norpm
then
	echo "Skipping the generation of the RPM packages"
else
	RPM_ARCH=i486
	mkdir -p $RPM_TMP/{sswf-root,BUILD,$RPM_ARCH}

	# On my RedHat there is a bug and freetype2 is shown as just freetype
	sed -e "s//$VERSION/" -e "s@@freetype@" dev/sswf-rpm.spec >$RPM_TMP/sswf.spec
	sed -e "s@@`pwd`/$RPM_TMP@" -e "s@@`pwd`/$ARCHIVE@" \
		-e "s@@`pwd`/tmp@" dev/_rpmmacros >$HOME/.rpmmacros
	(
		cd $RPM_TMP
		if ! rpmbuild -ba --quiet --target $RPM_ARCH-m2osw-linux sswf.spec >../rpm.txt
		then
			echo "ERROR: the RPM package was NOT created; you can find the output in tmp/rpm.txt"
			exit 1;
		fi
		# Signing requires interaction at this time... (for the passphrase)
		#rpm --addsign $RPM_ARCH/sswf-$VERSION-1.$RPM_ARCH.rpm
		echo "NOTE: the RPM package was created; you can find the output in tmp/rpm.txt"
	)
	mv $RPM_TMP/$RPM_ARCH/sswf-$VERSION-3.$RPM_ARCH.rpm $ARCHIVE/
	mv $RPM_TMP/$RPM_ARCH/sswf-debuginfo-$VERSION-3.$RPM_ARCH.rpm $ARCHIVE/
	mv $RPM_TMP/sswf-$VERSION-3.src.rpm $ARCHIVE/
fi



##################
# Debian
##################
## Create a Debian distribution

if $nodebian
then
	echo "Skipping the generation of the Debian package"
else
	failed=false
	rm -rf $DST
	mkdir -p $DST/usr
	# Copy everything we want in the output package
	$COPY --parents $TOPACK_BIN $DST/usr
	$COPY --force --parents $TOPACK_LIB $DST/usr
	# Remove the .swf execpt from the documentation
	find $DST/usr -name '*.swf' -exec rm -f {} \;
	$COPY --force --parents $TOPACK_DOC $DST/usr
	# Remove what we don't want & fix what we keep
	(
		failed=true
		set -e
		cd $DST/usr

		# Rename the libraries so they includes the version
		echo "*** Create library links"
		mv lib/libsswf.so lib/libsswf-$VERSION.so
		ln -s libsswf-$VERSION.so lib/libsswf.so
		mv lib/libsswf_as.so lib/libsswf_as-$VERSION.so
		ln -s libsswf_as-$VERSION.so lib/libsswf_as.so
		mv lib/libsswf_asas.so lib/libsswf_asas-$VERSION.so
		ln -s libsswf_asas-$VERSION.so lib/libsswf_asas.so

		# Rework the bin directory content as required
		# First we want to relink to put the correct version
		# libraries and an rpath as expected on Slackware
		# WARNING: we need to still have the object files
		#	   available... (also, not too sure if that's
		#	   really gonna work to "share" versions like
		#	   this since the objects will have been compiled
		#	   with one version and linked with another!)
		echo "*** Recompile with 3.4.3 libraries"
		g++ -nostdlib -Wl,-rpath,/usr/lib/. \
			/usr/lib/crt1.o /usr/lib/crti.o \
			/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.3/crtbegin.o \
			-o bin/sswf ../../tmp/object/src/sswf/*.o \
			-Llib -lsswf-$VERSION -lsswf_as-$VERSION \
			-lsswf_asas-$VERSION \
			/usr/lib/libstdc++.so.5 -lz -ljpeg -lm -lgcc -lgcc_s -lc \
			/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.3/crtend.o \
			/usr/lib/crtn.o
		strip $TOSTRIP_BIN

		# Don't need the special installs
		echo "*** Delete some non-debian related documents"
		rm -f doc/INSTALL-*.txt
		rm -f doc/Makefile.am

		# Fix the makefiles in the samples directories
		echo "*** Fixing the sample makefiles"
		for m in samples/*/*makefile
		do
			sed -e 'sX\.\./\.\./libX../../../../libXg' \
			    -e 'sX\.\./\.\./include/sswf/scriptsX../../scriptsXg' \
			    -e 'sX\.\./\.\./includeX../../../../includeXg' \
			    -e 'sX\.\./\.\./bin/sswfX../../../../bin/sswfXg' \
			    -e "s/libsswf\.so/libsswf-$VERSION.so/" \
				    $m >../../tmp/makefile.tmp
			cp ../../tmp/makefile.tmp $m
		done

		# Move things which need to be in the share directory
		echo "*** Moving files around"
		mkdir -p share/{doc/sswf,sswf}
		mv doc/man share
		mv doc/html share/sswf
		mv doc/*.txt share/sswf
		rm -rf doc
		cp README.txt share/sswf
		mv README.txt share/doc/sswf
		cp share/sswf/CHANGES.txt share/doc/sswf/changelog
		sed -e "s//$VERSION/" ../../dev/changelog.Debian >share/doc/sswf/changelog.Debian
		gzip -9 share/doc/sswf/{R*,ch*}
		cat ../../dev/copyright.Debian share/sswf/LICENSE.txt >share/doc/sswf/copyright
		mv include/sswf/scripts misc samples share/sswf

		# Compress a few things
		gzip -9f share/man/man?/*.?
		failed=false
	) >tmp/debian.txt
	(
		failed=true
		set -e
		cd $DST

		SIZE=`du -ks usr | sed -e 's/[ \t]*usr//'`

		sed -e "s//$VERSION/" ../dev/libsswf-debian.la >usr/lib/libsswf.la
		sed -e "s//$VERSION/" ../dev/libsswf_as-debian.la >usr/lib/libsswf_as.la
		sed -e "s//$VERSION/" ../dev/libsswf_asas-debian.la >usr/lib/libsswf_asas.la
		sed -e "s//$VERSION/" -e "s//$SIZE/" \
			../dev/control-debian.txt >control
		echo "2.0" >debian-binary

		find usr -type f -name '*run.bat' -exec rm {} \;
		find usr -type f -name '*.bak' -exec rm {} \;
		find usr -type f -name '*~' -exec rm {} \;
		find usr/share/sswf/samples -type f -name '*.swf' -exec rm {} \;
		md5sum `find usr -type f` >md5sums
		chmod -R go-w usr md5sums control debian-binary

		tar czf control.tar.gz ./md5sums ./control
		tar czf data.tar.gz ./usr -X ../dev/exclude.txt --exclude '*run.bat'
		rm -rf ../$ARCHIVE/sswf_$VERSION-*_i386.deb
		ar cqS ../$ARCHIVE/sswf_$VERSION-2_i386.deb debian-binary control.tar.gz data.tar.gz
		failed=false
	)


	if $failed;
	then
		echo "ERROR: the Debian package creation failed."
	else
		echo "NOTE: the Debian package was created."
	fi
	echo "NOTE: the output was saved in tmp/debian.txt"
fi




##################
# Slackware
##################
## Create a Slackware distribution

if $noslackware
then
	echo "Skipping the generation of the Slackware package"
else
	failed=false
	rm -rf $DST
	mkdir -p $DST/usr
	# Copy everything we want in the output package
	$COPY --parents $TOPACK_BIN $DST/usr
	$COPY --force --parents $TOPACK_LIB $DST/usr
	# Remove the .swf except from the documentation
	find $DST/usr -name '*.swf' -exec rm -f {} \;
	$COPY --force --parents $TOPACK_DOC $DST/usr
	sed -e "s//$VERSION/" dev/libsswf-slackware.la >$DST/usr/lib/libsswf.la
	sed -e "s//$VERSION/" dev/libsswf_as-slackware.la >$DST/usr/lib/libsswf_as.la
	sed -e "s//$VERSION/" dev/libsswf_asas-slackware.la >$DST/usr/lib/libsswf_asas.la
	# Remove what we don't want & fix what we keep
	(
		failed=true
		cd $DST

		# Create the install directory content
		mkdir install
		sed -e "s//$VERSION/" ../dev/slack-desc >install/slack-desc
		sed -e "s//$VERSION/" ../dev/doinst-slackware.sh >install/doinst.sh

		cd usr

		# Rename the libraries so they include the version
		mv lib/libsswf.so lib/libsswf-$VERSION.so
		mv lib/libsswf_as.so lib/libsswf_as-$VERSION.so
		mv lib/libsswf_asas.so lib/libsswf_asas-$VERSION.so

		# Rework the bin directory content as required
		# First we want to relink to put the correct version
		# libraries and an rpath as expected on Slackware
		# WARNING: we need to still have the object files
		#	   available... (also, not too sure if that's
		#	   really gonna work to "share" versions like
		#	   this since the objects will have been compiled
		#	   with one version and linked with another!)
		g++ -nostdlib -Wl,-rpath,/usr/lib/. \
			/usr/lib/crt1.o /usr/lib/crti.o \
			/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.3/crtbegin.o \
			-o bin/sswf ../../tmp/object/src/sswf/*.o \
			-Llib -lsswf-$VERSION -lsswf_as-$VERSION \
			-lsswf_asas-$VERSION \
			/usr/lib/libstdc++.so.5 -lz -ljpeg -lm -lgcc -lgcc_s -lc \
			/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.3/crtend.o \
			/usr/lib/crtn.o
		strip $TOSTRIP_BIN

		# Keep only the INSTALL-SLACKWARE info file
		mv doc/INSTALL-SLACKWARE.txt .
		rm -f doc/INSTALL-*.txt
		rm -f doc/Makefile.am
		mv INSTALL-SLACKWARE.txt doc

		# Fix the makefiles in the samples directories
		for m in samples/*/*makefile
		do
			sed -e 'sX\.\./\.\./libX../../../../libXg' \
			    -e 'sX\.\./\.\./include/sswf/scriptsX../../scriptsXg' \
			    -e 'sX\.\./\.\./includeX../../../../includeXg' \
			    -e 'sX\.\./\.\./bin/sswfX../../../../bin/sswfXg' \
			    -e "s/libsswf\.so/libsswf-$VERSION.so/" \
				    $m >../../tmp/makefile.tmp
			cp ../../tmp/makefile.tmp $m
		done

		# Move things which need to be in the share directory
		mkdir -p share/sswf
		mv doc/man share
		mv doc/html share/sswf
		cp doc/*.txt share/sswf
		mkdir doc/sswf-$VERSION
		mv doc/*.txt doc/sswf-$VERSION
		cp README.txt share/sswf
		mv README.txt doc/sswf-$VERSION
		mv include/sswf/scripts misc samples share/sswf

		find . -type f -name '*run.bat' -exec rm {} \;
		find . -type f -name '*.bak' -exec rm {} \;
		find . -type f -name '*~' -exec rm {} \;
		find share/sswf/samples -type f -name '*.swf' -exec rm {} \;

		# Compress the manual pages
		gzip -9f share/man/man?/*.?
		failed=false
	) >tmp/slackware.txt
	(
		cd $DST
		chmod -R go-w usr install
		tar czf ../$ARCHIVE/$DST-i486-1will.tgz install ./usr -X ../dev/exclude.txt --exclude '*run.bat'
	)

	if $failed;
	then
		echo "ERROR: the Slackware package creation failed."
	else
		echo "NOTE: the Slackware package was created."
	fi
	echo "NOTE: the output was saved in tmp/slackware.txt"
fi




######################################################################
# Function to create non-linux packages
#
# Parameter:	$1	system name (mingw, etc.)
#
######################################################################

pack_system() {
	# Get the modules files (in case it wasn't extracted yet)
	NAME="`echo $1 | sed -e 'sX/$XX'`"
	tar xjf modules/$NAME-$VERSION-bin.tar.bz2
	chmod -R 777 arch

	#######################
	# Check parameter validity
	#######################
	if ! test -d "arch/$1"
	then
		echo "ERROR: can't access system (directory) $1"
		exit 1;
	fi
	SRC="arch/$NAME"

	SYS=`grep system:$NAME: dev/arch.txt | sed -e "s/system:$NAME://"`
	EXE=`grep extension:$NAME: dev/arch.txt | sed -e "s/extension:$NAME://"`


	#######################
	# Binaries (must already be stripped on the source system)
	#######################
	if test -z "$EXE"
	then
		EXEMSG=""
	else
		EXEMSG=" (with \"$EXE\" as the extension of binaries)"
	fi
	echo "Creating bin-$SYS module$EXEMSG"
	rm -rf $DST
	mkdir -p $DST
	$COPY --parents $TOPACK_BIN $DST
	# remove the linux version and replace with specific arch version
	rm -rf $DST/bin
	$COPY $SRC/bin $DST
	create_packages bin-$SYS

	#######################
	# Library
	#######################
	echo "Creating lib-$SYS module"
	rm -rf $DST
	mkdir -p $DST
	$COPY --parents $TOPACK_LIB $DST
	# remove the linux version and replace with specific arch version
	rm -rf $DST/lib
	$COPY $SRC/lib $DST
	create_packages lib-$SYS
}



##############################
# Check if the other distributions
# are available - if so, run the
# extrapack command on them
##############################

# Uncomment this function if you don't need packages
# other than Linux packages
#skip_func6() {

if test -f modules/mingw-$VERSION-bin.tar.bz2
then
	# MinGW systems get their own version using
	# the MinGW directory tree as expected by the
	# MinGW users
	SYS=mingw-i686

	# Get the modules files (in case it wasn't extracted yet)
	tar xjf modules/mingw-$VERSION-bin.tar.bz2
	chmod -R 777 arch

	############
	# Binaries
	############
	echo "Creating bin-$SYS package (with \".exe\" as the extension of binaries)"
	rm -rf $MINGW_PATH
	mkdir -p $MINGW_PATH/{bin,contrib/sswf,include/sswf}
	$COPY arch/mingw/bin $MINGW_PATH
	$COPY $TOPACK_ALWAYS $MINGW_PATH/contrib/sswf
	$COPY --parents include/sswf/scripts $MINGW_PATH
	$COPY --parents doc/man $MINGW_PATH

	create_packages bin-$SYS $MINGW_PATH

	############
	# Library
	############
	echo "Creating lib-$SYS package"
	rm -rf $MINGW_PATH
	mkdir -p $MINGW_PATH/{contrib/sswf,include/sswf,lib}
	cp -rf arch/mingw/lib $MINGW_PATH
	cp -rf arch/mingw/include $MINGW_PATH
	cp -rf $TOPACK_ALWAYS $MINGW_PATH/contrib/sswf

	create_packages lib-$SYS $MINGW_PATH

	# Documentation
	echo "Creating doc-mingw package"
	rm -rf $MINGW_PATH
	mkdir -p $MINGW_PATH/{contrib/sswf,doc/sswf-$VERSION}

	cp -rf doc/html/*.{html,pdf} doc/html/images doc/html/tutorial $MINGW_PATH/doc/sswf-$VERSION
	cp -rf doc/man $MINGW_PATH
	cp -rf $TOPACK_ALWAYS $MINGW_PATH/contrib/sswf

	create_packages -k doc-mingw $MINGW_PATH
fi

if test -f modules/win32-$VERSION-bin.tar.bz2
then
	pack_system win32
	cp -f arch/win32/installer/sswf-$VERSION-win32-i686.exe $ARCHIVE
fi

if test -f modules/irix-$VERSION-bin.tar.bz2
then
	pack_system irix
	cp arch/irix/dist/* $ARCHIVE/
fi

if test -f modules/darwin-$VERSION-bin.tar.bz2
then
	pack_system darwin
	cp arch/darwin/packages/* $ARCHIVE/
	cp modules/$FINK_INFO $ARCHIVE/
fi


if test -f modules/$DST-3.ppc.linuxonpower.rpm
then
	cp modules/$DST-3.ppc.linuxonpower.rpm $ARCHIVE/
fi

#}


##############################
# Cleanup
##############################

if $nocleanup
then
	echo "NOTE: cleanup step skipped; many intermediate files will still be available."
else
	rm -rf $DST $TAR_TMP $RPM_TMP $MAKEFILE_TMP $MAKEFILE_HEADER \
		$MINGW_PATH $CONFIGURE_AC tmp/amake* tmp/makefile.tmp
fi


##############################
# Stats
##############################

echo "Started at $start_date and finised at `date +%H:%M:%S`"