Add ?prelude argument when import constants
A user can now define their own macros to use with extracting compile time info
This commit is contained in:
parent
b8f2fa0465
commit
69b76f0c8e
|
@ -283,12 +283,13 @@ module C_define = struct
|
||||||
| String of string
|
| String of string
|
||||||
end
|
end
|
||||||
|
|
||||||
let import t ?c_flags ?link_flags ~includes vars =
|
let import t ?prelude ?c_flags ?link_flags ~includes vars =
|
||||||
let buf = Buffer.create 1024 in
|
let buf = Buffer.create 1024 in
|
||||||
let pr fmt = Printf.bprintf buf (fmt ^^ "\n") in
|
let pr fmt = Printf.bprintf buf (fmt ^^ "\n") in
|
||||||
let includes = "stdio.h" :: includes in
|
let includes = "stdio.h" :: includes in
|
||||||
List.iter includes ~f:(pr "#include <%s>");
|
List.iter includes ~f:(pr "#include <%s>");
|
||||||
pr "";
|
pr "";
|
||||||
|
Option.iter prelude ~f:(pr "%s");
|
||||||
pr "int main()";
|
pr "int main()";
|
||||||
pr "{";
|
pr "{";
|
||||||
List.iter vars ~f:(fun (name, (kind : Type.t)) ->
|
List.iter vars ~f:(fun (name, (kind : Type.t)) ->
|
||||||
|
|
|
@ -44,6 +44,9 @@ module C_define : sig
|
||||||
*)
|
*)
|
||||||
val import
|
val import
|
||||||
: t
|
: t
|
||||||
|
-> ?prelude: string
|
||||||
|
(** Define extra code be used with extracting values below. Note that the
|
||||||
|
compiled code is never executed. *)
|
||||||
-> ?c_flags: string list
|
-> ?c_flags: string list
|
||||||
-> ?link_flags:string list
|
-> ?link_flags:string list
|
||||||
-> includes: string list
|
-> includes: string list
|
||||||
|
|
|
@ -4,10 +4,11 @@ let () =
|
||||||
let module C_define = Configurator.C_define in
|
let module C_define = Configurator.C_define in
|
||||||
Configurator.main ~name:"c_test" (fun t ->
|
Configurator.main ~name:"c_test" (fun t ->
|
||||||
C_define.import t
|
C_define.import t
|
||||||
|
~prelude:{|#define CONFIGURATOR_TESTING "foobar"|}
|
||||||
~includes:["caml/config.h"]
|
~includes:["caml/config.h"]
|
||||||
[ "CAML_CONFIG_H", C_define.Type.Switch
|
[ "CAML_CONFIG_H", C_define.Type.Switch
|
||||||
; "Page_log", C_define.Type.Int
|
; "Page_log", C_define.Type.Int
|
||||||
; "__func__", C_define.Type.String
|
; "CONFIGURATOR_TESTING", C_define.Type.String
|
||||||
]
|
]
|
||||||
|> List.iter (fun (n, v) ->
|
|> List.iter (fun (n, v) ->
|
||||||
Printf.printf "%s=%s\n"
|
Printf.printf "%s=%s\n"
|
||||||
|
|
|
@ -11,4 +11,4 @@ Importing #define's from code is successful
|
||||||
$ jbuilder exec import-define/run.exe
|
$ jbuilder exec import-define/run.exe
|
||||||
CAML_CONFIG_H=true
|
CAML_CONFIG_H=true
|
||||||
Page_log=12
|
Page_log=12
|
||||||
__func__=main
|
CONFIGURATOR_TESTING=foobar
|
||||||
|
|
Loading…
Reference in New Issue