Source

ocaml-core / base / core / oasis.sh

The branch 'bash' does not exist.
Diff from to

File base/core/oasis.sh

-#!/bin/bash
+#!/usr/bin/env bash
 set -e -u -o pipefail
 
+enable_linux=false
+enable_linux_default="--disable-linux"
+case $(ocamlc -config | awk '$1 == "system:" {print $2}') in
+    linux|linux_elf)
+        enable_linux=true
+        enable_linux_default="--enable-linux"
+    ;;
+esac
+
+enable_timers=false
+enable_timers_default="--disable-posix-timers"
+if [[ $(getconf _POSIX_TIMERS 2>/dev/null) -ge 200112 ]]; then
+    enable_timers=true
+    enable_timers_default="--enable-posix-timers"
+fi
+
+opts=( "$@" )
+for ((i=0; i<$#; i++)); do
+    case ${opts[$i]} in
+        --enable-linux)  enable_linux=true;  enable_linux_default= ;;
+        --disable-linux) enable_linux=false; enable_linux_default= ;;
+        --enable-posix-timers)  enable_timers=true;  enable_timers_default= ;;
+        --disable-posix-timers) enable_timers=false; enable_timers_default= ;;
+    esac
+done
+
+use_librt=
+if ld -lrt -shared -o /dev/null 2>/dev/null; then
+    use_librt=-lrt
+fi
+
 here="$(dirname "${BASH_SOURCE[0]}")"
-
 my_join () {
     local FIRST="true"
     while read line; do
         bname="$(basename $i)"
         j=${bname%%.ml*};
         case $j in
-            linux_ext) continue;;
-            bigstring_marshal) continue;;
+            linux_ext|bigstring_marshal)
+                if [ "$enable_linux" == "false" ]; then continue; fi;;
             inline_tests_runner) continue;;
             *);;
         esac
         bname="$(basename $i)"
         j=${bname%%.?};
         case $j in
-            linux_ext_stubs) continue;;
-            bigstring_marshal_stubs) continue;;
+            linux_ext_stubs|bigstring_marshal_stubs)
+                if [ "$enable_linux" == "false" ]; then continue; fi;;
             *);;
         esac
         echo "$bname"
 }
 
 MODULES="$(list_mods | sort -u | my_join)"
+CSOURCES="config.h,$(list_stubs | sort -u| my_join)"
+CCLIB="$use_librt"
 
 cat >$here/_oasis<<EOF
 #AUTOGENERATED FILE; EDIT oasis.sh INSTEAD
 
 Flag linux
   Description: Enable linux specific extensions
-  Default$:    system(linux) || system(linux_elf)
+  Default\$:   $enable_linux
 
-if flag(linux)
-  PostConfCommand: lib/discover.sh lib/config.mlh lib/config.h -DLINUX_EXT
-else
-  PostConfCommand: lib/discover.sh lib/config.mlh lib/config.h
+Flag "posix-timers"
+  Description: Enable POSIX timers
+  Default\$:   $enable_timers
 
-PreBuildCommand:     mkdir -p _build; cp lib/*mlh _build/
+PostConfCommand: lib/discover.sh lib/config.mlh lib/config.h $(
+  if [[ "$enable_linux"  == "true" ]]; then echo -n " -DLINUX_EXT"; fi
+  if [[ "$enable_timers" == "true" ]]; then echo -n " -DPOSIX_TIMERS"; fi
+  echo
+)
+
+PreBuildCommand:     mkdir -p _build/; cp lib/*.mlh _build/
 PreDistCleanCommand: \$rm "lib/config.mlh" "lib/config.h"
 
 Library core
   FindlibName:        core
   Pack:               true
   Modules:${MODULES}
-  #This should actually be the result of calling `getconf LFS64_CFLAGS`
-  CCOpt:              -D_LARGEFILE64_SOURCE
-  #Hack to skip the compilation of linux_ext
-  CSources:           config.h,$(list_stubs | sort -u|my_join)
-  #Disabled for now: those fields cannot be conditional...
-  #if flag(linux)
-    CSources+:        linux_ext_stubs.c,bigstring_marshal_stubs.c
-    Modules+:         Linux_ext,Bigstring_marshal
-  if flag(linux)
-    CCLib:            -lrt
+  CCOpt:              $(getconf LFS64_CFLAGS)
+  CSources:           ${CSOURCES}
+  CCLib:              ${CCLIB}
   BuildDepends:       variantslib,
                       variantslib.syntax,
                       sexplib.syntax,
 
 cd $here
 oasis setup
-./configure "$@"
+./configure "$enable_linux_default" "$@"