Source

sulu-ocaml-core / build-and-install

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

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

configflags="
 enable-linux
disable-linux
 enable-posix-timers
disable-posix-timers
"

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

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

set -e
eval set -- "$opts"

linuxflag=
timerflag=
makeflags=""
configopts=( )
uninstall=false
use_sudo=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  ;;
        --enable-linux)  linuxflag="--enable-linux";  shift  ;;
        --disable-linux) linuxflag="--disable-linux"; shift  ;;
        --enable-posix-timers)  timerflag="--enable-posix-timers";  shift ;;
        --disable-posix-timers) timerflag="--disable-posix-timers"; shift ;;
        --) shift; break ;;
         *) configopts+=( "$1" )
    esac
done

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 findlibname {
    local dir="$1"
    (cd "$dir"
     case $dir in
        *-$core_version) ;;
        *) [[ -e _oasis ]] || ./oasis.sh >/dev/null;;
     esac
     grep 'FindlibParent:' _oasis || grep 'FindlibName:' _oasis) \
    | head -1 | awk '{print $2}'
}

function uninstall {
    local lib=$(findlibname "$1")
    maybe_sudo ocamlfind remove "$lib" || true;
}

for dir in "${build_order[@]}"; do
  echo "------ $BASE/$dir ------"
  optflags=

  uninstall "$BASE/$dir" || true
  if $uninstall; then continue; fi

  pushd $BASE/$dir

  case $dir in
      core|core/extended|core-$core_version|core_extended-$core_version)
          optflags="$linuxflag $timerflag" ;;
      async) # horrible hack (avoids rebuilding async_{core,scheduler,extra})
          src=$(pwd)
          dest=$(mktemp -d -t ocaml-core-async.XXXXXX)
          mkdir -p "$dest/$BASE/async"
          cp -rp "$root/build-common.sh" "$dest/"
          cp -rp lib oasis.sh "$dest/$BASE/async/"
          cd $dest/$BASE/async
          trap "rm -r '$dest'" EXIT
          ;;
  esac

  case $dir in
      *-$core_version) ;;
      *) ./oasis.sh    ;;
  esac

  ./configure $optflags "${configopts[@]:+${configopts[@]}}"
  make build BUILDFLAGS="$makeflags"

  if ! maybe_sudo make install; then
      echo "*** ERROR: couldn't install '$dir'" 1>&2
      exit 1
  fi

  popd

  case $dir in
      async) # copy the generated setup.ml and setup.data back
        cp -rp "$dest"/$BASE/async/{configure,Makefile,setup.ml,setup.data,myocamlbuild.ml} "$src"/
      ;;
  esac

done
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.