diff --git a/src/gen_rules.ml b/src/gen_rules.ml index 8c3fff24..ec1cdd28 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -1151,12 +1151,24 @@ module Gen(P : Params) = struct | _ -> [dll ~dir lib] in List.concat - [ List.map files ~f:(fun src -> - { Install.Entry. src; dst = None; section = Lib }) - ; List.map dlls ~f:(fun src -> - { Install.Entry. src; dst = None; section = Stublibs }) + [ List.map files ~f:(Install.Entry.make Lib ) + ; List.map dlls ~f:(Install.Entry.make Stublibs) ] + let add_doc_file fn entries = + let suffixes = [""; ".md"; ".org"; ".txt"] in + match + List.find_map suffixes ~f:(fun suf -> + let path = Path.of_string (fn ^ suf) in + if Path.exists path then + Some path + else + None) + with + | None -> entries + | Some path -> + Install.Entry.make Doc path :: entries + let install_file package = let entries = List.concat_map P.stanzas ~f:(fun { ctx_dir = dir; stanzas; _ } -> @@ -1169,11 +1181,18 @@ module Gen(P : Params) = struct let entries = let meta = Path.of_string "META" in if Path.exists meta then - { Install.Entry. - src = meta - ; dst = None - ; section = Lib - } :: entries + Install.Entry.make Lib meta :: entries + else + entries + in + let entries = + List.fold_left ["README"; "LICENSE"] ~init:entries ~f:(fun acc fn -> + add_doc_file fn acc) + in + let entries = + let opam = Path.of_string "opam" in + if Path.exists opam then + Install.Entry.make Lib opam :: entries else entries in diff --git a/src/import.ml b/src/import.ml index e23aacf9..5fffa9b9 100644 --- a/src/import.ml +++ b/src/import.ml @@ -51,6 +51,14 @@ module List = struct let partition_map l ~f = let l, r = rev_partition_map l ~f in (List.rev l, List.rev r) + + let rec find_map l ~f = + match l with + | [] -> None + | x :: l -> + match f x with + | None -> find_map l ~f + | Some _ as res -> res end module Hashtbl = struct diff --git a/src/install.ml b/src/install.ml index ef23ce50..ec0fa44b 100644 --- a/src/install.ml +++ b/src/install.ml @@ -38,6 +38,12 @@ module Entry = struct ; dst : string option ; section : Section.t } + + let make section ?dst src = + { src + ; dst + ; section + } end module SMap = Map.Make(Section) diff --git a/src/install.mli b/src/install.mli index 4cfcc7c1..796bb6c3 100644 --- a/src/install.mli +++ b/src/install.mli @@ -22,6 +22,8 @@ module Entry : sig ; dst : string option ; section : Section.t } + + val make : Section.t -> ?dst:string -> Path.t -> t end val files : Entry.t list -> Path.Set.t