#! /bin/sh
# Generated automatically from c2init.in by configure.
#---------------------------------------------------------------------------#
# Copyright (C) 1995 University of Melbourne.
# This file may only be copied under the terms of the GNU General
# Public License - see the file COPYING in the Mercury distribution.
#---------------------------------------------------------------------------#

# C2INIT - Convert *.c to *_init.c
#
# This script outputs an appropriate init.c, given the .c files.
# Type `c2init --help' for usage message.
#
# Environment variables: MERCURY_MOD_LIB_DIR, MERCURY_MOD_LIB_MODS,
# MERCURY_MKINIT.

MERCURY_MOD_LIB_DIR=${MERCURY_MOD_LIB_DIR=/usr/lib/mercury/modules}
MERCURY_MOD_LIB_MODS=${MERCURY_MOD_LIB_MODS=$MERCURY_MOD_LIB_DIR/*}
MKINIT=${MERCURY_MKINIT=mkinit}

# maximum number of calls to put in a single function
maxcalls=40
defentry=mercury__io__run_0_0
while true; do
	case "$1" in
	-c|--max-calls)
		maxcalls="$2"; shift; shift;;
	-w|--entry-point)
		defentry="$2"; shift; shift;;
	--)
		shift; break;;
	-*)
		echo "Usage: c2init [options] modules ..." 1>&2
		echo "Options: " 1>&2
		echo "-c <n>, --max-calls <n>" 1>&2
		echo "	Break up the initialization into groups of at" \
			"most <n> function calls" 1>&2
		echo "	(Default value of <n> is 40)" 1>&2
		echo "-w <label>, --entry-point <label>" 1>&2
		echo "	Set entry point to <label>" 1>&2
		echo "	(Default value is \`mercury__io__run_0_0')" 1>&2
		exit 1;;
	*)
		break;;
	esac
done

case $# in
	0) exec $MKINIT -w"$defentry" -c"$maxcalls" $MERCURY_MOD_LIB_MODS
	   ;;
	*) exec $MKINIT -w"$defentry" -c"$maxcalls" "$@" $MERCURY_MOD_LIB_MODS
	   ;;
esac
