1#!/bin/sh
2# Copyright (c) 2008-2014 Robert Virding
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16follow_symlink () {
17    if [ -h "$1" ]; then
18        follow_symlink "$(readlink "$1")"
19    else
20        echo "$1"
21    fi
22}
23
24SELF=$(follow_symlink "$0")
25LFE_PROGNAME=$(echo "$0" | sed 's/.*\///')
26LFE_BINDIR=$(dirname "$SELF")
27LFE_ROOTDIR=$(dirname "$LFE_BINDIR")
28
29export LFE_ROOTDIR
30export LFE_BINDIR
31export LFE_PROGNAME
32
33# Collect all +flags and -flags. We follow the same handling as in
34# 'erl' EXCEPT that as soon as we reach a "plain" argument all the
35# rest also become "plain" arguments and will be prefixed with -extra.
36# These arguments are then handed over as is the LFE boot to do as it
37# pleases.
38
39flags=""
40
41while [ -n "$1" ]; do
42    case "$1" in
43	-extra | --)		# We're explicitly done
44	    shift
45	    break ;;
46	-* | +*)		# Flags
47	    flags="$flags $1"
48	    shift
49	    while [ -n "$1" ]; do
50		case "$1" in
51		    -* | +*)
52			break ;;
53		    *)
54			flags="$flags $1"
55		esac
56		shift
57	    done ;;
58	*)			# Plain argument
59	    break ;;
60    esac
61done
62
63lflags="-pa $LFE_ROOTDIR/ebin"	# Location of LFE files
64if [ -n "$1" ]; then
65    lflags="-noshell $lflags"	# To avoid getting a shell process
66fi
67
68echo "$flags" "$lflags" -user lfe_init -extra "$@"
69