ocaml-core / build-and-install

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

function usage {
    echo "usage: ${BASH_SOURCE[0]} [-j <JOBS>] [tree]"
    echo "         -h, --help       Display this help"
    echo "         -j N             Run at most N jobs in parallel"
}

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

opts=$(getopt -n ${BASH_SOURCE[0]} -o "j:h" \
              -l "jobs:,help,$(echo -n $configflags | tr ' ' ,)" -- "$@")
if [[ $? != 0 ]]; then usage; exit 1; fi

set -e
eval set -- "$opts"

linuxflag=
timerflag=
makeflags=""
configopts=( )
while true; do
    case "$1" in
        -h|--help) usage; exit 0;;
        -j|--jobs) makeflags="$makeflags -j $2";      shift 2;;
        --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

tree=""
case $# in
    0) tree="."  ;;
    1) tree="$1" ;;
    *) echo "too many anonymous arguments: $@" ;;
esac

# in dependency topological order
libraries="
type-conv
pipebang
compare
typehash
fieldslib
variantslib
pa_ounit
bin-prot
sexplib
core
core/extended
async/core
async/scheduler
async/extra
async
"

cd "$tree"
for dir in $libraries; do
  echo "------ base/$dir ------"
  pushd base/$dir
  optflags=
  case $dir in
      core|core/extended) optflags="$linuxflag $timerflag" ;;
      async/scheduler)    optflags="$linuxflag" ;;
      async) # horrible hack (avoids rebuilding async_{core,scheduler,extra})
          dest=$(mktemp -d -t ocaml-core-async.XXXXXX)
          mkdir -p "$dest/base/async"
          cp -rp ../../build-common.sh "$dest/"
          cp -rp lib oasis.sh "$dest/base/async/"
          cd $dest/base/async
          trap "rm -r '$dest'" EXIT
          ;;
  esac
  ./oasis.sh $optflags "${configopts[@]:+${configopts[@]}}"
  make build BUILDFLAGS="$makeflags"
  make install || true
  popd
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.