ysulsky avatar ysulsky committed 675916d

support for unified tarball, installing with sudo

Comments (0)

Files changed (3)

 
 hgroot=$(hg root)
 
+cp "$hgroot/build-and-install" "$destdir/"
+cat >"$destdir/build-common.sh" <<EOF
+#!/bin/bash
+
+core_version=$core_version
+
+# in dependency-topological order
+build_order=(
+EOF
+
 for dir in $packages; do
     pushd "base/$dir"
 
     ./oasis.sh
     name=$(oasis query name)
     version=$(oasis query version)
+
+    echo "    $name-$version" >>"$destdir/build-common.sh"
+
     dest="$destdir/${name}-${version}"
     mkdir "$dest"
 
 
     popd
 done
+
+cat >>"$destdir/build-common.sh" <<EOF
+)
+
+BASE=\$(dirname -- \$0)
+EOF

build-and-install

 #!/usr/bin/env bash
 set -u -o pipefail
 
-. build-common.sh
-
 function usage {
-    echo "usage: ${BASH_SOURCE[0]} [-j <JOBS>] [tree]"
+    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"
 }
 
 opts=
 if getopt -V | grep -q enhanced; then
-  opts=$(getopt -n ${BASH_SOURCE[0]} -o "j:uh" \
-                -l "jobs:,help,$(echo -n $configflags | tr ' ' ,)" -- "$@")
+  opts=$(getopt -n ${BASH_SOURCE[0]} -o "j:uhs" \
+                -l "jobs:,help,sudo,$(echo -n $configflags | tr ' ' ,)" -- "$@")
 else
-  opts=$(getopt "j:uh" $*)
+  opts=$(getopt "j:uhs" $*)
 fi
 
 if [[ $? != 0 ]]; then usage; exit 1; fi
 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;;
+        -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 ;;
     esac
 done
 
-tree=""
-case $# in
-    0) tree="."  ;;
-    1) tree="$1" ;;
-    *) echo "too many anonymous arguments: $@"; exit 1 ;;
-esac
+tree=$(dirname -- "$0")
+
+cd "$tree"
+. build-common.sh
 
 if $uninstall; then
   rev_build_order=( )
   build_order=( "${rev_build_order[@]}" )
 fi
 
-cd "$tree"
+function maybe_sudo {
+    if $use_sudo; then sudo "$@"; else "$@"; fi
+}
 
 function findlibname {
     local dir="$1"
-    (grep FindlibParent: "$dir"/oasis.sh || grep FindlibName: "$dir"/oasis.sh) \
+    local fn=""
+    case $dir in
+        *-$core_version) fn="$dir/_oasis"   ;;
+        *)               fn="$dir/oasis.sh" ;;
+    esac
+    (grep FindlibParent: "$fn" || grep FindlibName: "$fn") \
     | awk '{print $2}' | head -1
 }
 
 function uninstall {
     local lib=$(findlibname "$1")
-    ocamlfind remove "$lib" || true;
+    maybe_sudo ocamlfind remove "$lib" || true;
 }
 
 for dir in "${build_order[@]}"; do
-  echo "------ base/$dir ------"
-  pushd base/$dir
+  echo "------ $BASE/$dir ------"
   optflags=
 
-  if $uninstall; then
-    uninstall .
-    popd; continue
-  fi
+  uninstall "$BASE/$dir" || true
+  if $uninstall; then continue; fi
+
+  pushd $BASE/$dir
 
   case $dir in
-      core|core/extended) optflags="$linuxflag $timerflag" ;;
-      async/scheduler)    optflags="$linuxflag" ;;
+      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 ../../build-common.sh "$dest/"
-          cp -rp lib oasis.sh "$dest/base/async/"
-          cd $dest/base/async
+          mkdir -p "$dest/$BASE/async"
+          cp -rp "$tree/build-common.sh" "$dest/"
+          cp -rp lib oasis.sh "$dest/$BASE/async/"
+          cd $dest/$BASE/async
           trap "rm -r '$dest'" EXIT
           ;;
   esac
-  ./oasis.sh
+
+  case $dir in
+      *-$core_version) ;;
+      *) ./oasis.sh    ;;
+  esac
+
   ./configure $optflags "${configopts[@]:+${configopts[@]}}"
   make build BUILDFLAGS="$makeflags"
-  uninstall .
-  make install
+
+  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"/
+        cp -rp "$dest"/$BASE/async/{configure,Makefile,setup.ml,setup.data,myocamlbuild.ml} "$src"/
       ;;
   esac
-  popd
 
 done
 '
 
 HERE=$(dirname -- "$0")
-
+BASE=$HERE/base
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.