#! /bin/bash # Find the directory containing this script. source="${BASH_SOURCE[0]}" while [ -h "${source}" ] ; do eccdir="$(cd -P "$(dirname "${source}")" && pwd)" source="$(readlink "${source}")" [[ ${source} != /* ]] && source="$DIR/${source}" done eccdir="$(cd -P "$(dirname "${source}")" && pwd)" # Check for a previous ELLCC definition. if [ -z "${ELLCC}" ] ; then ELLCC=~/ellcc fi # Look for the libecc directory. dirs=( $(dirname $eccdir)/libecc ${ELLCC}/libecc /usr/local/libecc /usr/libecc ) LIBECC= for dir in "${dirs[@]}" ; do if [ -d ${dir} ] ; then LIBECC=${dir} break fi done # Get the invocation name. name=$(basename ${BASH_SOURCE[0]}) if [ -z "${LIBECC}" ] ; then echo ${name}: could not find libecc in any of the expected places. echo checked: ${dirs[@]} exit 1 fi # Check for C or C++. if [[ ${name} == *ecc ]] ; then cplusplus=n elif [[ ${name} == *ecc++ ]] ; then cplusplus=y else echo ${name}: does not end in ecc or ecc++ exit 1 fi get_config() { if [ -e $1 ] ; then echo $1 elif [ -e ${TOOLINFO}/$1 ] ; then echo ${TOOLINFO}/$1 else echo -n "" fi } # See if a target is defined in the name. TARGET= if [[ ${name} == *-ecc ]] ; then candidate=$(basename -s -ecc ${name}) if [ -e ${TOOLINFO)/${candidate} ] ; then TARGET=${candidate} else echo ${name}: ${candidate} is not a defined target name. exit 1 fi elif [[ ${name} == *-ecc++ ]] ; then candidate=$(basename -s -ecc++ ${name}) if [ -e ${TOOLINFO}/${candidate} ] ; then TARGET=${candidate} else echo ${name}: ${candidate} is not a defined target name. exit 1 fi fi # Find ecc command line arguments, gather the rest in ARGS. ARGS=() index=0 target_position=0 while [ $# -ne 0 ] ; do case "$1" in -target) shift candidate=$1 if [ "$(get_config ${candidate})" != "" ] ; then TARGET=${candidate} target_position=${index} else echo ${name}: ${candidate} is not a defined target name. exit 1 fi shift ;; -e|--environment) environment=y shift ;; *) ARGS+=("$1") shift (( index++ )) ;; esac done parse_yaml() { local prefix=$2 local s local w local fs s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs="$(echo @|tr @ '\034')" sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \ -e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" | awk -F"$fs" '{ indent = length($1)/2; vname[indent] = $2; for (i in vname) {if (i > indent) {delete vname[i]}} if (length($3) > 0) { vn=""; for (i=0; i