ocaml-core / build-common.sh

#!/bin/bash

function my_join {
    sep=","
    if [[ $# -gt 0 ]]; then sep="$1"; fi
    local cursep=
    while read line; do
        echo -n "$cursep"
        cursep="$sep"
        echo -n "$line"
    done
    echo
}

function capitalize {
    local j="$1"
    echo -n "${j:0:1}" | tr "[:lower:]" "[:upper:]"; echo ${j:1}
}

function mod_names {
    while read line; do
        bname=$(basename "$line")
        j=${bname%%.ml*};
        if [[ "$j" == "inline_tests_runner" ]]; then continue; fi
        capitalize "$j"
    done
}

function make_tags {
    cat >"$1" <<EOF
# OASIS_START
# OASIS_STOP
EOF
    cat >>"$1"
}

function tag_for_pack {
    local libname=$(capitalize "$1")
    shift
    for ml in "$@"; do
        local dir=$(dirname "$ml" | sed -e 's_^\./__')
        local bname=$(basename "$ml")
        echo "\"${dir}/${bname%%.ml*}.cmx\": for-pack($libname)"
        echo "\"${dir}/$(capitalize ${bname%%.ml*}).cmx\": for-pack($libname)"
    done
}

function enable_pack_in_setup_ml {
    awk -f - setup.ml > setup.ml.pack <<EOF
BEGIN                      { next_pack=0; skipnext=0; }
/cs_name/                  { next_pack=0; }
/cs_name = "$1"/           { next_pack=1; }
/lib_pack = (true|false);/ { if (next_pack) {
                               print "lib_pack = true;"
                               skipnext=1
                             }
                           }
/.*/                       { if (!skipnext) { print \$0; }
                             skipnext=0; }
EOF
    mv setup.ml.pack setup.ml
    for dir in $(find . -name "$1".mllib -exec dirname \{\} \;); do
        mv "$dir"/"$1".mllib "$dir"/"$1".mlpack
    done
}

function check_linux_enabled {
    enable_linux=false
    enable_linux_default="--disable-linux"
    case $(ocamlc -config | awk '$1 == "system:" {print $2}') in
        linux|linux_elf)
            enable_linux=true
            enable_linux_default="--enable-linux"
            ;;
    esac

    for opt in "$@"; do
        case "$opt" in
            --enable-linux)  enable_linux=true;  enable_linux_default= ;;
            --disable-linux) enable_linux=false; enable_linux_default= ;;
        esac
    done
}

function getconf_or_zero {
    local ret=$(getconf "$@" 2>/dev/null)
    case "$ret" in
	[0-9][0-9]*) echo "$ret" ;;
	*) echo 0 ;;
    esac
}

function check_posix_timers_enabled {
    enable_timers=false
    enable_timers_default="--disable-posix-timers"
    if [[ $(getconf_or_zero _POSIX_TIMERS) -ge 200112 ]]; then
        enable_timers=true
        enable_timers_default="--enable-posix-timers"
    fi

    for opt in "$@"; do
        case "$opt" in
            --enable-posix-timers)  enable_timers=true;  enable_timers_default= ;;
            --disable-posix-timers) enable_timers=false; enable_timers_default= ;;
        esac
    done
}

HERE=$(dirname "$0")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.