module Godi_script:This module contains library functions for GODI configuration scripts written in OCaml. This is mainly intended for the conf-foo packages.sig
..end
In order to activate such a script, define the following variables in the driver Makefile of conf-foo:
CONF_SCRIPT
: The name of the script, usually configure.gcs
(gcs = GODI configuration script). The suffix "gcs" enables a special
calling convention that automatically finds the O'Caml interpreter
and that loads the libraries str
and unix
, and, of course,
godi_script
.CONF_SCRIPT_ARGS
: Arguments to be passed to the script.
CC
: The name of the C compilerSEARCH_LIBS
: The list of standard library locationsELF_RPATH_FLAG
: The name of the RPATH flag, if any.val runcmd : string -> int
Sys.command
, but preferable.val runcmdf : ('a, unit, string, int) format4 -> 'a
runcmd
, but accepts a printf
-like format string.val read_file : string -> string
val write_file : string -> string -> unit
val read_from_cmd : string -> int * string
val read_from_cmdf : ('a, unit, string, int * string) format4 -> 'a
read_from_cmd
, but accepts a printf
-like format string.val env : string -> string
""
if the variable does
not exist.val env_opt : string -> string option
None
if the variable
is empty or does not exist.
Remember that the exit code 0 means that the command was successful.
type 'a
cmdstate
'a
val code : 'a cmdstate -> int
val result : 'a cmdstate -> 'a option
val return_code : int -> 'a cmdstate -> 'a cmdstate
val return_result : 'a option -> 'a cmdstate -> 'a cmdstate
val initial_state : unit -> 'a cmdstate
type'a
cmdlet ='a cmdstate -> 'a cmdstate
val cmd : string -> 'a cmdlet
val cmdf : ('a, unit, string, 'b cmdlet) format4 -> 'a
cmd
but accepts a printf
-like format stringval cmd_output : string -> string cmdlet
val cmdf_output : ('a, unit, string, string cmdlet) format4 -> 'a
cmd_output
but accepts a printf
-like format stringval set_code : int -> 'a cmdlet
val set_code_from : ('a cmdstate -> int) -> 'a cmdlet
val set_bool_code : bool -> 'a cmdlet
true
, and to 1 if the boolean is false
.val set_bool_code_from : ('a cmdstate -> bool) -> 'a cmdlet
set_code_bool
).val (&-) : 'a cmdlet -> 'a cmdlet -> 'a cmdlet
val (|-) : 'a cmdlet -> 'a cmdlet -> 'a cmdlet
val ignore_code : 'a cmdlet -> 'a cmdlet
val eval : 'a cmdlet -> 'a option
None
is always returned if the exit code is non-zero, regardless of
whether there is a result value or not.val eval_test : 'a cmdlet -> bool
true
if the exit code is 0,
and false
if the exit code is non-zero.
eval (cmd_output "ls /a" |- cmd_output "ls /b")
Loops should be programmed with recursion, or by folding:
eval
(List.fold_left
(fun acc x ->
acc |- cmdf_output "ls %s" (Filename.quote x))
(set_bool_code true)
[ "/a"; "/b"; "/c" ]
)
val log : string -> unit
val logf : ('a, unit, string, unit) format4 -> 'a
log
, but accepts a printf
-like format stringtype
c_env = {
|
c_incdirs : |
(* | List of directories for "#include" | *) |
|
c_libdirs : |
(* | List of library directories | *) |
|
c_libs : |
(* | Names of libraries (w/o "lib" and suffix) | *) |
|
c_flags : |
(* | Further flags for C compiling | *) |
|
ld_flags : |
(* | Further flags for linking | *) |
|
elf_rpath : |
(* | Whether | *) |
|
config_script : |
(* | The name of a foreign config script | *) |
|
godi_deps : |
(* | List of additional GODI dependencies to
output | *) |
c_incdirs
can be translated to further C compiler flags;
the c_libdirs
and c_libs
can be translated to further linker
flags. The c_flags
and ld_flags
are additional flags.
It is also allowed to only fill c_flags
and ld_flags
and let
the other components empty.
The config_script
is the name of another script that can be called
to get the C compiler and linker flags (e.g. pkg-config scripts).
The godi_deps
are dependencies to GODI packages that are required
at run-time to make the C library available. (These are usually
base-foo packages.)
val create_test_whether_c_function_exists : string -> string
val c_compile_test : c_env -> string -> string cmdlet
val run_test : string cmdlet
val find_c_library : ?godi_deps:string list ->
?pref_incdir:string ->
?pref_libdir:string ->
?c_flags:string list ->
?ld_flags:string list ->
?inc_name:string ->
libs:string list ->
test:(c_env -> c_env option) ->
unit -> c_env cmdlet
pref_incdir
and pref_libdir
are tried. If not successful, searching continues
with the locations found in the environment variable SEARCH_LIBS
.
A C library is found if:
inc_name
is found (if passed), andtest
returns a non-None
valuetest
is the result of the
commandlet.
The C environment passed to the test
function is properly set
up:
c_incdirs
contains the tested include locationc_libdirs
contains the tested library locationc_libs
is libs
c_flags
is c_flags
ld_flags
is ld_flags
elf_rpath
is tried config_script
is always None
godi_deps
is set to godi_deps
, but only when the preferred
location is triedval print_c_result : file:string -> prefix:string -> c_env -> unit
file
and to the screen.
The prefix
is prepended to the variables in file
.
Example: print_c_result ~file:"conf-foo.mk" ~prefix:"CONF_FOO" ce
val main_c_finder : ?godi_deps:string list Pervasives.ref ->
?pref_incdir:string option Pervasives.ref ->
?pref_libdir:string option Pervasives.ref ->
?c_flags:string list Pervasives.ref ->
?ld_flags:string list Pervasives.ref -> unit -> unit
godi_deps
,
pref_incdir
, pref_libdir
, c_flags
, and ld_flags
can
be set by command-line if a string reference is passed to the
function.
Example:
let pref_incdir = ref None in
let pref_libdir = ref None in
main_c_finder ~pref_incdir ~pref_libdir ();
let c_opt = eval
(find_c_library
?pref_incdir:!pref_incdir
?pref_libdir:!pref_libdir
~libs:... ~test:... ()) in
match c_opt with
None -> failwith "Cannot find library"
Some c -> print_c_result ~file:"conf-foo.mk" ~prefix:"CONF_FOO" c