let annotate arch =
let rec self arch acc =
match arch with
| Arch_dir_pack(name, _, contents) ->
let acc = { (acc) with for_pack = join_pack acc.for_pack name } in
let (_, _, i, new_contents) = self_contents name contents acc in
([], Arch_dir_pack(name, i, List.rev new_contents))
| Arch_dir(name, _, contents) ->
let (current_path, include_dirs, i, new_contents) = self_contents name contents acc in
(current_path :: include_dirs, Arch_dir(name, i, List.rev new_contents))
| Arch_file(name, _) ->
([], Arch_file(name, acc))
and self_contents name contents acc =
let current_path = acc.current_path/name in
let include_dirs = if current_path = "" then acc.include_dirs else current_path :: acc.include_dirs in
let i = { (acc) with current_path = current_path; include_dirs = include_dirs } in
let (include_dirs, new_contents) =
List.fold_left begin fun (include_dirs, new_contents) x ->
let j = { (i) with include_dirs = include_dirs @ i.include_dirs } in
let (include_dirs', x') = self x j in
(include_dirs @ include_dirs', x' :: new_contents)
end ([], []) contents in
(current_path, include_dirs, i, new_contents) in
let init = { current_path = ""; include_dirs = []; for_pack = "" } in
snd (self arch init)