Welcome to little lamb

Code » comain » release » tree

[release] / blddeps

#!/bin/sh

. "$(dirname $0)"/libcomain

usage()
{
    local r=$1
    shift

    cat <<EOF
usage: $0 ACTION

      build [-n]                    Build dependencies in deps/

      help                          Show this help screen and exit
EOF
    exit $r
}

getdep()
{
    local dep=$2
    local depname="${dep##*/}"
    local needed
    eval needed=\"\$need$depname\"
    local rec="$3"
    local cpnt=0
    test -e "$dep/cpnt" && cpnt=1
    if test $cpnt -eq 1; then return; fi
    local library=$depname
    test -e "$dep/library" && library="$(cat "$dep/library")"
    if ! test -e "deps/$depname"; then return; fi
    echo $depname lib$library $dep

    # recursive lila dependency
    if ! test -d "deps/$depname/meta/deps"; then return; fi
    for d in "deps/$depname"/meta/deps/*; do
        if ! test -d "$d"; then continue; fi
        getdep 0 "$d" "$rec  "
    done
}

mbrun()
{
    if test $dryrun -eq 0; then
        run "$@"
    else
        echo "dry-run: $@"
    fi
}

loadoptions
loaddeps

if test $# -eq 0; then usage 0; fi

dryrun=0
build=0
for arg ; do
    case "$arg" in
        build) build=1 ;;

        -n|--dry-run) dryrun=1 ;;
        -h|--help|help) usage 0  ;;
        *) dief 1 "unknown action '$arg'" ;;
    esac
done

if test $build -eq 1; then
    foreach deps $nb_deps getdep | tac | while read -r name library dep; do
        if test -e "deps/$name/$library.a" || test -e "deps/$name/$library.so"; then
            echo :: $name already built.
            continue
        fi
        echo :: Building $name

        args="$(cat "$dep/configure" 2>/dev/null)"
        if test -e "$dep/make"; then
            make="$(realpath "$dep/make")"
        else
            make=make
        fi

        mbrun cd deps/$name
        mbrun ./configure $args
        if test $? -eq 0; then mbrun $make; fi
        mbrun cd ../..
    done
fi

echo "done."