1. Stéphane Legrand
  2. sulu-ocaml-core

Source

sulu-ocaml-core / base / core / extended / oasis.sh

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

source ../../../build-common.sh

cat >$HERE/_oasis <<EOF
#AUTOGENERATED FILE; EDIT oasis.sh INSTEAD

OASISFormat:  0.3
OCamlVersion: >= 3.12
Name:         core_extended
Version:      $core_version
Synopsis:     Jane Street Capital's standard library overlay
Authors:      Jane street capital
Copyrights:   (C) 2008-2012 Jane Street Capital LLC
License:      LGPL-2.1 with OCaml linking exception
LicenseFile:  LICENSE
Plugins:      StdFiles (0.3), DevFiles (0.3), META (0.3)
BuildTools:   ocamlbuild
Description:  Jane Street Capital's standard library overlay
FindlibVersion: >= 1.2.7
XStdFilesAUTHORS: false
XStdFilesINSTALLFilename: INSTALL
XStdFilesREADME: false

Flag linux
  Description: Enable linux specific extensions
  Default\$:   false   # actually, the default is detected

Flag "posix-timers"
  Description: Enable POSIX timers
  Default\$:   false   # actually, the default is detected

PostConfCommand: lib/discover.sh lib/config.mlh lib/config.h

PreDistCleanCommand: \$rm lib/version_defaults.mlh lib/config.mlh lib/config.h

Library core_extended
  Path:               lib
  FindlibName:        core_extended
  Pack:               true
  Modules:            $(list_mods  "$HERE/lib")
  CSources:           $(list_stubs "$HERE/lib"),config.h
  CCOpt+:             -Ilib
  BuildDepends:       sexplib.syntax,
                      sexplib,
                      fieldslib.syntax,
                      fieldslib,
                      bin_prot,
                      bin_prot.syntax,
                      pa_ounit,
                      pa_pipebang,
                      core,
                      bigarray,
                      pcre,
                      res,
                      unix,
                      threads

Executable core_extended_hello
  Path:               lib_test
  MainIs:             core_extended_hello.ml
  Build\$:            flag(tests)
  Custom:             true
  CompiledObject:     best
  Install:            false
  BuildDepends:       core_extended

Executable core_hello
  Path:               lib_test
  MainIs:             core_hello.ml
  Build\$:            flag(tests)
  Custom:             true
  CompiledObject:     best
  Install:            false
  BuildDepends:       core,threads

Executable test_runner
  Path:               lib_test
  MainIs:             test_runner.ml
  Build\$:            flag(tests)
  Custom:             true
  CompiledObject:     best
  Install:            false
  BuildDepends:       core_extended,oUnit (>= 1.1.0),threads

Test test_runner
  Run\$:              flag(tests)
  Command:            \$test_runner --core-hello \$core_hello --core-extended-hello \$core_extended_hello
  WorkingDirectory:   lib_test
  TestTools:          core_hello,core_extended_hello

Document "core-extended"
  Title:                Jane street's core extended library
  Type:                 ocamlbuild (0.3)
  BuildTools+:          ocamldoc
  XOCamlbuildPath:      lib
  XOCamlbuildLibraries: core_extended

EOF

if [[ ! -e $HERE/lib/version_defaults.mlh ]]; then
    cat >$HERE/lib/version_defaults.mlh <<EOF
DEFINE DEFAULT_VERSION = "No version info."
DEFINE DEFAULT_BUILDINFO = "No build info."
EOF
fi

make_tags "$HERE/_tags" <<EOF
<lib/*.ml{,i}>          : syntax_camlp4o
"lib/command.ml"        : mlh, pkg_camlp4.macro
"lib/console.ml"        : mlh, pkg_camlp4.macro
"lib/core_command.ml"   : mlh, pkg_camlp4.macro
"lib/extended_linux.ml" : mlh, pkg_camlp4.macro
"lib/malloc.ml"         : mlh, pkg_camlp4.macro
"lib/posix_clock.ml"    : mlh, pkg_camlp4.macro
EOF

make_myocamlbuild "$HERE/myocamlbuild.ml" <<EOF
let endswith x s =
  let len_x = String.length x and len_s = String.length s in
  (len_x <= len_s) && x = String.sub s (len_s - len_x) len_x

let select_files dir ext =
  List.map (Pathname.concat dir)
    (List.filter (endswith ext)
      (Array.to_list (Sys.readdir dir)))

let mlh_files = select_files "lib/" ".mlh"

let dispatch = function
  | After_rules as e ->
    dep  ["ocaml"; "ocamldep"; "mlh"] mlh_files;
    List.iter (fun tag ->
      flag ["mlh"; "ocaml"; tag] (S[A"-ppopt"; A"-Ilib/"]))
      ["ocamldep"; "compile"];
    dispatch_default e
  | e -> dispatch_default e

let () = Ocamlbuild_plugin.dispatch dispatch
EOF

make_setup_ml "$HERE/setup.ml" <<EOF
let test cmd =
  match Sys.command (cmd ^ " 2>/dev/null") with
  | 0 -> true
  | 1 -> false
  | _ -> failwith ("command '"^cmd^"' failed.")

let getconf var =
  let f_exit_code = ignore in
  let ctxt = !BaseContext.default in
  OASISExec.run_read_output ~f_exit_code ~ctxt "getconf" [var]

let linux_possible = test "uname | grep -q -i linux"
let timers_possible =
  match getconf "_POSIX_TIMERS" with
  | [x] -> (try int_of_string x >= 200112 with _ -> false)
  |  _  -> false

let map_section = function
  | Flag (cs, flag) when cs.cs_name = "linux" ->
    Flag (cs, { flag with
                flag_default = [OASISExpr.EBool true,      linux_possible;
                                OASISExpr.EBool false, not linux_possible] })
  | Flag (cs, flag) when cs.cs_name = "posix-timers" ->
    Flag (cs, { flag with
                flag_default = [OASISExpr.EBool true,      timers_possible;
                                OASISExpr.EBool false, not timers_possible] })
  | section -> section

let setup_t = { setup_t with
  BaseSetup.package = { setup_t.BaseSetup.package with
    sections = List.map map_section setup_t.BaseSetup.package.sections;
  }
}
EOF

cd $HERE
oasis setup