Source

sulu-ocaml-core / build-and-install

Full commit
Brandon Mitchell d140a6d 
ysulsky 7faf13d 


ysulsky 915dde7 
ysulsky 7faf13d 
ysulsky 675916d 
ysulsky 915dde7 
ysulsky 7faf13d 
Sylvain Le Gall 7029f75 
ysulsky 7faf13d 

ysulsky dff0aed 

ysulsky 915dde7 

ysulsky dff0aed 
ysulsky 915dde7 
ysulsky dff0aed 

ysulsky 7faf13d 




Sylvain Le Gall 7029f75 
ysulsky 675916d 
ysulsky 915dde7 
ysulsky 7faf13d 



ysulsky 675916d 

ysulsky 915dde7 
ysulsky 7faf13d 
ysulsky 915dde7 
ysulsky 7faf13d 


ysulsky 915dde7 

ysulsky 77d8544 


ysulsky 6180b96 
ysulsky 7614c2d 
ysulsky e1f704c 
ysulsky df0bf47 
ysulsky e1f704c 


ysulsky 7614c2d 

ysulsky 675916d 


ysulsky e1f704c 
ysulsky 915dde7 

ysulsky bec1360 
ysulsky 915dde7 

ysulsky bec1360 

ysulsky 915dde7 



ysulsky e1f704c 

ysulsky 915dde7 




ysulsky e1f704c 

ysulsky 915dde7 

ysulsky e1f704c 
ysulsky 915dde7 
ysulsky e1f704c 
ysulsky 915dde7 
ysulsky e1f704c 
ysulsky 7faf13d 
ysulsky 915dde7 

ysulsky 7faf13d 
ysulsky 675916d 
ysulsky 915dde7 


ysulsky 675916d 

ysulsky 915dde7 




ysulsky 7614c2d 
ysulsky 915dde7 
Sylvain Le Gall 7029f75 
ysulsky 915dde7 













ysulsky 7faf13d 
ysulsky 915dde7 

#!/usr/bin/env bash
set -u -o pipefail

function usage {
    echo "usage: ${BASH_SOURCE[0]} [-s] [-v] [-j <JOBS>]"
    echo "         -h, --help       Display this help"
    echo "         -s, --sudo       Install with sudo"
    echo "         -v, --verbose    Log to the terminal"
    echo "         -j N             Run at most N jobs in parallel"
    echo "         -u               Don't install, uninstall"
}

opts=
if getopt -V | grep -q enhanced; then
  opts=$(getopt -n ${BASH_SOURCE[0]} -o "j:uhsv" \
                -l "jobs:,help,sudo,verbose" -- "$@")
else
  opts=$(getopt "j:uhsv" $*)
fi

if [[ $? != 0 ]]; then usage; exit 1; fi

eval set -- "$opts"

makeflags=""
uninstall=false
use_sudo=false
verbose=false
while true; do
    case "$1" in
        -h|--help) usage; exit 0;;
        -j|--jobs) makeflags="$makeflags -j $2";      shift 2;;
        -u)        uninstall=true;                    shift  ;;
        -s|--sudo) use_sudo=true;                     shift  ;;
        -v|--verbose) verbose=true    ;               shift  ;;
        --) shift; break ;;
         *) echo "unexpected flag '$1'"; usage; exit 1 ;;
    esac
done

if [[ $# -gt 0 ]]; then echo "unexpected arguments $@"; usage; exit 1; fi

source $(dirname -- "$0")/build-common.sh
root="$HERE";
cd "$root"

if $uninstall; then
  rev_build_order=( )
  for ((i=${#build_order[@]}-1; i>=0; i--)); do
      rev_build_order+=( "${build_order[$i]}" )
  done
  build_order=( "${rev_build_order[@]}" )
fi

function maybe_sudo {
    if $use_sudo; then sudo "$@"; else "$@"; fi
}

function maybe_verbose {
    if $verbose; then "$@"; else
        local ret=0
        local output=''
        output=$("$@" 2>&1)
        ret=$?
        if [[ $ret -ne 0 ]]; then
            echo "$output"
            return $ret
        fi
    fi
}

function findlibname {
    local oasis=$1
    local output=''
    (grep 'FindlibParent:' "$oasis"   \
     || grep 'FindlibName:' "$oasis") | head -1 | awk '{print $2}'
}

function die { echo "*** ERROR: $1"; exit 1; }

for dir in "${build_order[@]}"; do
  echo "=> $dir"

  pushd $dir >/dev/null

  case $dir in
      *-$core_version) ;; # no need to do anything for released packages
      *) maybe_verbose ./oasis.sh || die "Error generating $dir/_oasis";;
  esac

  lib=$(findlibname '_oasis')
  if [[ $? -ne 0 ]]; then
      die "Couldn't figure out the library name from $dir/_oasis"
  fi

  if ocamlfind query "$lib" 2>/dev/null >/dev/null; then
      echo "   * uninstalling"
      maybe_verbose maybe_sudo ocamlfind remove "$lib" \
          || die "Couldn't uninstall $lib"
  fi

  if ! $uninstall; then

      echo "   * configuring"
      maybe_verbose ./configure \
          || die "Couldn't configure $lib"

      echo "   * compiling"
      maybe_verbose make build BUILDFLAGS="$makeflags" \
          || die "Couldn't compile $lib"

      echo "   * installing"
      maybe_verbose maybe_sudo make install \
          || die "Couldn't install $lib"

  fi
  popd >/dev/null
done

echo "All finished!"