let sources2packages ?(profiles=false) ?(noindep=false) ?(src="src") builddeparch l =
let conflicts profile l = List.filter_map (select builddeparch profile) l in
let depends profile ll =
List.filter_map (fun l ->
match List.filter_map (select builddeparch profile) l with
|[] -> None
|l -> Some l
) ll
in
let add_native_l =
List.map (function
|(((name, None), constr), al, pl) ->
(((name, Some "native"), constr), al, pl)
|(((name, Some a), constr), al, pl) ->
warning "modifier %s for indep dependency %s used" a name;
(((name, Some a), constr), al, pl)
)
in
let add_native_ll = List.map add_native_l in
let src2pkg ?(profile=None) srcpkg =
let prefix = match profile with None -> src | Some s -> src^"-"^s in
let extras_profile = match profile with None -> [] | Some s -> [("profile", s)] in
let depends_indep = if noindep then [] else add_native_ll srcpkg.build_depends_indep in
let conflicts_indep = if noindep then [] else add_native_l srcpkg.build_conflicts_indep in
let build_essential = [(("build-essential", Some "native"), None)] in
{ Packages.default_package with
Packages.name = prefix ^ sep ^ srcpkg.name ;
source = (srcpkg.name, Some srcpkg.version);
version = srcpkg.version;
depends = build_essential::(depends profile (depends_indep @ srcpkg.build_depends));
conflicts = conflicts profile (conflicts_indep @ srcpkg.build_conflicts);
architecture = String.concat "," srcpkg.architecture;
extras = extras_profile @ [("Type",src)]
}
in
let getprofiles pkg =
let deps = pkg.build_conflicts @ (List.flatten pkg.build_depends) in
List.unique (List.map snd (List.fold_left (fun l (_,_,pl) -> pl @ l) [] deps))
in
List.fold_right (fun srcpkg al ->
let pkg = src2pkg srcpkg in
if profiles then
pkg :: (List.map (fun p -> src2pkg ~profile:(Some p) srcpkg) (getprofiles srcpkg)) @ al
else
pkg::al
) l []