# vi:filetype=tcl
#
# configuration for libsingthreads

use cc cc-shared

source autoutil.tcl

options {
  singular:.. => "path to singular directory"
  threads=1 => "disable thread support"
  location:system => {
      If and where to install the Singular thread bindings.

      local  - do not install them.
      system - install them in the Singular directory.
      <dir>  - install them in directory <dir>.
  }
}

set SINGULAR [opt-val singular ..]

if {![file isdirectory $SINGULAR]} {
  user-error "Singular path is not a directory"
}

set LOCATION_LIB {}
set LOCATION_MOD {}

switch -glob -- [opt-val location system] {
  local {}
  system {
    set LOCATION_LIB $SINGULAR/Singular/LIB
    set LOCATION_MOD $SINGULAR/Singular/MOD
  }
  /* {
    set LOCATION_LIB [opt-val location]
    set LOCATION_MOD [opt-val location]
  }
  ./* {
    set LOCATION_LIB [opt-val location]
    set LOCATION_MOD [opt-val location]
  }
  default {
    user-error "Invalid value for --location"
  }
}

if {[string equal $LOCATION_LIB ""]} {
  define INSTALLATION ""
} else {
  set LOCATION_LIB [shell-quote $LOCATION_LIB]
  set LOCATION_MOD [shell-quote $LOCATION_MOD]
  define INSTALLATION "\ttools/install.sh -c -m 644 systhreads.lib $LOCATION_LIB
\ttools/install.sh -c -m 644 systhreads.so $LOCATION_MOD
\ttools/install.sh -c -m 644 threadtasks.lib $LOCATION_LIB
"
}
set sing_includes {}
foreach inc [list $SINGULAR $SINGULAR/factory/include $SINGULAR/libpolys] {
  lappend sing_includes $inc
}

set sing_libs ""

define SING_INCLUDES [-I {*}$sing_includes]
define SING_LIBS $sing_libs

if {[opt-bool threads] && [file exists "$SINGULAR/factory/prelude.h"]} {
  msg-result "Enabling thread support"
  define ENABLE_THREADS 1
} else {
  msg-result "Disabling thread support"
  define ENABLE_THREADS 0
}

make-config-header threadconf.h -auto {ENABLE_*}
make-template Makefile.in
