Module Sconf.OCaml_conf

module OCaml_conf: sig .. end
Main configuration detection module. This module offers functions to:
Author(s): Maxence Guesdon, Fabrice Le Fessant, Didier Remy
Version: 0.8
OCaml_conf


Configuration

You can change these values to modify the behaviour of some functions.
val temp_files_prefix : string Pervasives.ref
The prefix of the temporary files created.
val temp_files_ext : string Pervasives.ref
The default extension for the temporary files created.
val debug : bool Pervasives.ref
Set this to true to enable debug mode. Temporary files are not deleted when it is enabled.
val print : (string -> unit) Pervasives.ref
The function used to print progress messages and other information.
val string_of_bool : (bool -> string) Pervasives.ref
!string_of_bool b should return a message according to the given boolean. Default are yes/no.
val log_file : string Pervasives.ref
The name of the log file.
val fatal_error : (string -> unit) Pervasives.ref
The function to print a given fatal error message. Should exit the configuration process.

Utilities functions


val try_finalize : ('a -> 'b) -> 'a -> ('c -> 'd) -> 'c -> 'b
val restart_on_EINTR : ('a -> 'b) -> 'a -> 'b
val is_suffix : suf:string -> string -> bool
is_suffix ~suf s returns true if the string suf is a suffix of s.
val create_temp_file : ?ext:string -> ?contents:string -> unit -> string
create_temp_files ?ext ?contents () creates a temporary empty file and returns its name. The prefix of the file is specified by Sconf.OCaml_conf.temp_files_prefix.
ext : can be used to indicate a extension different from Sconf.OCaml_conf.temp_files_ext.
contents : can be used to specify the content of the file.
val remove_empty_strings : string list -> string list
val string_of_includes : string list -> string
val byte_ext_to_opt : string -> string
If the given filename has a .cmo (resp. .cma) extension, then return the same filename with a .cmx (resp. .cmxa) extension.

Handling PATH


exception Path of string * string
val path_sep : string
val path_sep_regexp : Str.regexp
val list_of_path : string -> string list
list_of_path string returns the list of directories from the given string in path format.
val path_of_list : string list -> string
path_of_list paths builds a string in path format.
Raises Path if a path contains the separator.
val get_path : unit -> string list
get_path () returns the list of directories indicated by the PATH environement variable.
val find_in_path : (string -> bool) -> string list -> string -> string list
find_in_path predicate paths file returns the list of complete filenames build from the directories and the filename, and verifying the given predicate.

Handling files


type filetest = 
| Fexists (*file exists*)
| Freadable (*file exists and is readable*)
| Fwritable (*file exists and is writable*)
| Fexecutable (*file exists and is executable*)
| Fdir (*file exists and is a directory*)
| Freg (*file exists and is a regular file*)
| Flnk (*file exists and is a symbolic link*)
| Fnonempty
| Fnewer of string (*files exists and is newer than*)
| Folder of string (*files exists and is older than*)
| Fequal of string (*files is identical (sams st_ino and st_dev) than*)
Various tests of a file.
val access_map : (filetest * Unix.access_permission) list
val access_ok_errors : Unix.error list
val testfile : filetest list -> string -> bool
testfile flags filename tests whether the given file verifies the given properties.
val buffer_size : int
val string_from_descr : Unix.file_descr -> string
val descr_from_string : string -> Unix.file_descr -> unit
val perm : int
val string_of_file : string -> string
string_of_files returns the contents of the given file as a string.
Raises Unix.Unix_error if an error occurs.
val file_of_string : contents:string -> file:string -> unit
file_of_string ~contents ~file creates the given file with the given string str as contents.
Raises Unix.Unix_error if an error occurs.
val input_lines : Pervasives.in_channel -> string list
input_lines channel return the list of lines from the given channel. The function is tail-recursive.
val unlink_f : string -> unit
unlink_f file removes the given file if it exists. If the files is a .ml file (resp. a .mli file), then it also removes the .cmo, .cmx, .o and .cmi files (resp. the .cmi file) if they exist.
Raises Unix.Unix_error if an error occurs.

Handling processes


exception Exec_failure
val execvp_to_list : string -> string array -> string list
type redirection = 
| In_from_file of string (*< file*)
| Out_to_file of string (*> file*)
| Err_to_file of string (*2> file*)
| Out_append_to_file of string (*>> file*)
| Err_to_out (*2>&1*)
| In_from_string of string (*<<END*)
| Err_null (*2>/dev/null*)
| Out_null (*>/dev/null*)
| Silent (*>/dev/null 2>&1*)
val execvp_redirect : redirection list ->
string -> string array -> Unix.process_status
val execvp : string -> string array -> Unix.process_status
val exec_and_get_first_line : string -> string array -> string
exec_and_get_first_line com args tries to execute the given command with the given arguments, and read the first line printed by the commande on its standard output. If any error occurs or the program doesn't print anything on stdout, the function returns "".
val exec_status_ok : Unix.process_status -> bool
exec_status_ok st returns true if the given return status is Unix.WEXITED 0.

Writing to log file


val string_of_date : float -> string
val add_to_log : string -> unit
add_to_log str writes the given string to the Sconf.OCaml_conf.log_file, with the date and time at the beginning of the line and an ending new line.

Handling version numbers


type version = int list 
val (<<) : 'a list -> 'a list -> bool
v1 << v2 returns true if version v1 is strictly inferior to version v2.
val dummy_version : int list
The dummy version number = [0].
val version_of_string : string -> int list
version_of_string s returns a version number from the given string s. s must b in the form X[.Y[.Z[...]]]. If the string is not correct, then the dummy version is returned.
val string_of_version : int list -> string
string_of_version v returns a string to display the given version. For example, string_of_version [1;2;3] = "1.2.3".

Handling OCaml configuration


type ocaml_conf = {
   ocaml :string;
   ocamlc :string;
   ocamlopt :string;
   ocamldep :string;
   ocamldoc :string;
   ocamldoc_opt :string;
   ocamllex :string;
   ocamlyacc :string;
   ocamlmklib :string;
   ocamlmktop :string;
   ocamlprof :string;
   camlp4 :string;
   ocamlfind :string;
   version_string :string;
   version :version;
}
Representation of the (locally detected) ocaml configuration.
exception Program_not_found of string
val ocaml_prog : ?err:bool -> string -> string
ocaml_prog file return the first executable called file in the directories of the PATH environment variable.
err : can be used to indicate whether not finding the program should raise the Program_not_found exception (err=true, default) or rather return an empty string (err=false). The function prints messages indicating what program is searched, and the result, using the Sconf.OCaml_conf.print function.
val ocaml_libdir : ocaml_conf -> string
ocaml_libdir conf uses the ocamlc program of the given configuration to retrieve the library directory. Return "" if any error occurs.
val version_of_ocaml_version_string : string -> int list
version_of_ocaml_version_string str returns a Sconf.OCaml_conf.version value from the string representing an ocaml version (which can contain '+', a date, ...).
val check_version : ?on_err:(string -> unit) -> string -> string -> unit
check_version version prog tries to run prog -version and return whether the given version string is a suffix of the first line printed. This function is used to check that an ocaml program has the correct version number.
on_err : can be used to indicate another function to call it the program is not in the correct version. Default is !Sconf.OCaml_conf.fatal_error.
val check_conf_versions : ocaml_conf -> unit
check_conf_version conf verifies that each program of the given configuration is of the correct version. If a program is not in the correct version, !Sconf.OCaml_conf.fatal_error is called.
val check_for_opt_prog : string -> string -> string
check_for_opt_prog version prog checks whether the prog.opt program is in the required version, and if so returns this program name; else it returns the given program name.
val get_opt_conf : ocaml_conf -> ocaml_conf
get_opt_conf conf returns the same configuration where some program names have been replaced by the "opt" version ("..../ocamlc.opt" instead of "..../ocamlc" for example). To do so, the function verifies if the ".opt" program found for each program of the configuration is in the same version of the bytecode program. For ocamldoc, the program in the ocamldoc field is not replaced but the ocamldoc_opt field is set to "..../ocamldoc.opt", because both bytecode and native versions can be used (for example the bytecode version is required to use custom generators).
val ocaml_conf : ?withopt:bool -> ?ocamlfind:bool -> unit -> ocaml_conf
ocaml_conf () detects and returns the Objective Caml configuration found from the PATH. The function checks that the programs found are in the same version (see Sconf.OCaml_conf.check_conf_versions), and refer to the ".opt" programs when they are available (see Sconf.OCaml_conf.get_opt_conf).
Raises Program_not found if a required program cannot be found.
withopt : can be used to raise a Sconf.OCaml_conf.Program_not_found exception if the native code compiler is not found; default is false.
ocamlfind : can be used to end up with a Sconf.OCaml_conf.Program_not_found exception if the ocamlfind tool is not found; default is false.
val print_conf : ocaml_conf -> unit
print_conf conf prints the given configuration using !Sconf.OCaml_conf.print.

Testing compilation and link


type compilation_mode = [ `Byte | `Opt ] 
val string_of_mode : [< `Byte | `Opt ] -> string
val ocamlc_of_mode : ocaml_conf -> [< `Byte | `Opt ] -> string
val string_of_com_args : string -> string array -> string
val can_compile : [< `Byte | `Opt ] ->
ocaml_conf ->
?includes:string list -> ?options:string list -> string -> bool
val can_compile_prog : ?mes:string ->
[< `Byte | `Opt ] ->
ocaml_conf ->
?includes:string list -> ?options:string list -> string -> bool
val ocaml_defined : ?mes:string ->
[< `Byte | `Opt ] ->
ocaml_conf ->
?includes:string list -> ?options:string list -> string -> bool
val ocaml_value_has_type : ?mes:string ->
[< `Byte | `Opt ] ->
ocaml_conf ->
?includes:string list -> ?options:'a -> string -> string -> bool
val can_link : ?mes:string ->
[< `Byte | `Opt ] ->
ocaml_conf ->
?out:string ->
?includes:string list ->
?libs:string list -> ?options:string list -> string list -> bool
val try_run : string -> bool

OCamlfind queries


val ocamlfind_query : ocaml_conf -> string -> string option
ocamlfind_query conf package returns the first line printed by "ocamlfind query package". If an error occurs (the package does not exist, ocamlfind cannot be executed, ...), the function returns None.
val ocamlfind_query_version : ocaml_conf -> string -> string option
val check_ocamlfind_package : ?min_version:int list ->
?max_version:int list ->
?fail:bool ->
?not_found:([ `Package_bad_version of string
| `Package_not_installed of string ] -> unit) ->
ocaml_conf -> string -> bool

Handling substitutions specification


val substs : (string, string) Hashtbl.t
val add_subst : string -> string -> unit
val subst_val : string -> string
val get_substs_list : unit -> (string * string) list
val output_substs : Pervasives.out_channel -> unit
val output_substs_to_file : string -> unit
val add_conf_variables : ocaml_conf -> unit