Add Lib.Compile.compile_and_link_flags

This commit is contained in:
Jeremie Dimino 2018-03-01 18:45:20 +00:00
parent 945583ff43
commit bdb03925d1
2 changed files with 30 additions and 7 deletions

View File

@ -383,6 +383,12 @@ end)
module L = struct
type nonrec t = t list
let to_iflags dirs =
Arg_spec.S
(Path.Set.fold dirs ~init:[] ~f:(fun dir acc ->
Arg_spec.Path dir :: A "-I" :: acc)
|> List.rev)
let include_paths ts ~stdlib_dir =
let dirs =
List.fold_left ts ~init:Path.Set.empty ~f:(fun acc t ->
@ -391,24 +397,34 @@ module L = struct
Path.Set.remove dirs stdlib_dir
let include_flags ts ~stdlib_dir =
let dirs = include_paths ts ~stdlib_dir in
Arg_spec.S (List.concat_map (Path.Set.to_list dirs) ~f:(fun dir ->
[Arg_spec.A "-I"; Path dir]))
to_iflags (include_paths ts ~stdlib_dir)
let c_include_flags ts ~stdlib_dir =
let c_include_paths ts ~stdlib_dir =
let dirs =
List.fold_left ts ~init:Path.Set.empty ~f:(fun acc t ->
Path.Set.add acc t.src_dir)
in
let dirs = Path.Set.remove dirs stdlib_dir in
Arg_spec.S (List.concat_map (Path.Set.to_list dirs) ~f:(fun dir ->
[Arg_spec.A "-I"; Path dir]))
Path.Set.remove dirs stdlib_dir
let c_include_flags ts ~stdlib_dir =
to_iflags (c_include_paths ts ~stdlib_dir)
let link_flags ts ~mode ~stdlib_dir =
Arg_spec.S
(c_include_flags ts ~stdlib_dir ::
List.map ts ~f:(fun t -> Arg_spec.Deps (Mode.Dict.get t.archives mode)))
let compile_and_link_flags ~compile ~link ~mode ~stdlib_dir =
let dirs =
Path.Set.union
( include_paths compile ~stdlib_dir)
(c_include_paths link ~stdlib_dir)
in
Arg_spec.S
(to_iflags dirs ::
List.map link ~f:(fun t ->
Arg_spec.Deps (Mode.Dict.get t.archives mode)))
let jsoo_runtime_files ts =
List.concat_map ts ~f:(fun t -> t.jsoo_runtime)

View File

@ -58,6 +58,13 @@ module L : sig
val link_flags : t -> mode:Mode.t -> stdlib_dir:Path.t -> _ Arg_spec.t
val compile_and_link_flags
: compile:t
-> link:t
-> mode:Mode.t
-> stdlib_dir:Path.t
-> _ Arg_spec.t
(** All the library archive files (.a, .cmxa, _stubs.a, ...) that
should be linked in when linking an executable. *)
val archive_files : t -> mode:Mode.t -> ext_lib:string -> Path.t list