Sophie

Sophie

distrib > Mageia > 5 > x86_64 > by-pkgid > 8957ed83efafee0e0debf6150010ef53 > files > 3

hugs98-2006.09-7.mga5.src.rpm

#!/bin/sh

# Create libraries sufficient for runhugs, ffihugs, cpphs, hsc2hs and
# Cabal scripts.

boot_packages='base haskell98 Cabal'

# ensure that letter ranges work
LC_ALL=C
export LC_ALL

case $0 in
*/*)	toolsdir=`dirname $0` ;;
*)	toolsdir=. ;;
esac

# parameters set by configure
. $toolsdir/config

cd $toolsdir/../..

source=packages
target=libraries/bootlib
fp_includes=ghc/includes
tmpdir_root=/tmp

HUGSDIR=hugsdir
HUGSFLAGS="-P$target"
export HUGSDIR HUGSFLAGS

# platform sensitive settings

case `uname -a` in
*CYGWIN*)
	# Canonicalize win32 paths 
	# (i.e., stay far away from unportable /cygdrive-paths)
	case $platform in
	Cygwin)	# stay away from -m
		# (older versions of 'cygpath' don't support it.)
		source=`cygpath -w $source | sed -e 's@\\\\@/@g'`
		target=`cygpath -w $target | sed -e 's@\\\\@/@g'`
		tmpdir_root=`cygpath -w $tmpdir_root | sed -e 's@\\\\@/@g'`
	esac

	platform=Win32 ;;
*MINGW*)
	platform=Win32 ;;
*)	platform=Unix ;;
esac

# create all scratch files in $tmpdir

tmpdir=$tmpdir_root/cvt.$$
[ -d $tmpdir ] && rm -r $tmpdir
trap "rm -rf $tmpdir; exit 0" 0 1 2 3 15
mkdir $tmpdir

# K&R-style C preprocessor

through_cpp() {
	# The input file need not be called *.c, but for
	# portability we run the preprocessor on a .c file.
	cpp_input=$tmpdir/cppinput.c

	cp "$1" $cpp_input

	# gcc-3.3 on MacOS X 10.3 is reported to add #pragma
	$cpp $cpp_flags $cpp_input | grep -v '^#' | cat -s
}

# internal Hugs modules

mkdir -p $target/Hugs
cp libraries/hugsbase/Hugs/*.* $target/Hugs
cp libraries/hugsbase/Hugs.hs $target

# Preprocess hierarchical modules

for package in $boot_packages
do
	package_dir=$source/$package

	# configure the library package first

	if test -x $package_dir/configure; then
		(cd $package_dir; ./configure)
	fi

	# Determine the list of modules to be converted

	module_list=$tmpdir/list.1
	all_modules=$tmpdir/list.2

	(
		cd $package_dir
		$FIND . \( -name '[a-z]*' -o -name '[GN]HC' \) -prune -o \
			\( -name \*.hs -o -name \*.lhs -o -name \*.hsc \) -print |
			sed '	s:^\./::
				s/\..*//' |
			grep -v '^Text/Regex' |
			$SORT -u >$all_modules

		if [ -f hugs/exclude ]; then
			sed '	/^[	]*#/ d
				/^[ 	]*$/ d
				s/[ 	].*//
				s:\.:/:g' hugs/exclude |
			$SORT -u | comm -13 - $all_modules >$module_list
		else
			mv $all_modules $module_list
		fi
	)

	# Preprocess modules

	while read modname
	do	echo "Preprocessing $modname"

		stem=$package_dir/$modname
		target_stem=$target/$modname
		dstdir=`dirname $target_stem`
		basename=`basename $stem`
		cpp_flags="$CPPFLAGS -I$HUGSDIR/include -I$package_dir/include -I$fp_includes"

		mkdir -p $dstdir

		# Hack: can't assume hsc2hs at this point, so just use cpp.
		# This works for System.Time and System.CPUTime, but not
		# Text.Regex.Posix, so we won't be compiling that.
		if [ -f $stem.hsc ]; then
			through_cpp $stem.hsc >$target_stem.hs
		elif [ -f $stem.hs ]; then
			through_cpp $stem.hs >$target_stem.hs
		elif [ -f $stem.lhs ]; then
			through_cpp $stem.lhs >$target_stem.lhs
		else
			echo "$0: don't know how to handle $stem" >&2
		fi
	done <$module_list
done

# compile some modules in bootlibs with ffihugs

ffihugs=src/ffihugs

base_includes="-I$source/base/include -I$fp_includes"

case $platform in
Unix)	base_libs= ;;
Win32)	base_libs='-lwsock32' ;;
esac

$ffihugs Hugs.Storable \
	libraries/hugsbase/Hugs/Storable_aux.c

$ffihugs '-i"HsBase.h"' Foreign.C.Error $base_includes \
	$source/base/cbits/PrelIOUtils.c $base_libs
$ffihugs '-i"HsBase.h"' Foreign.Marshal.Alloc $base_includes \
	$source/base/cbits/PrelIOUtils.c \
	$source/base/cbits/dirUtils.c \
	$source/base/cbits/consUtils.c $base_libs
$ffihugs '-i"HsBase.h"' Foreign.Marshal.Utils $base_includes $base_libs
$ffihugs '-i"HsBase.h"' Foreign.Ptr $base_includes \
	$source/base/cbits/PrelIOUtils.c $base_libs

case $platform in
Unix)
	$ffihugs '-i"HsBase.h"' System.Posix.Internals $base_includes \
		$source/base/cbits/dirUtils.c \	
	;;
Win32)
	$ffihugs '-i"HsBase.h"' System.Directory $base_includes $base_libs
	$ffihugs Distribution.Simple.Utils
	$ffihugs -98 Distribution.Simple.LocalBuildInfo
	;;
esac