let sources2packages ?(src="src") archs l =
  let archs = "all"::"any"::archs in
  (* as per policy, if the first arch restriction contains a !
   * then we assume that all archs on the lists are bang-ed.
   * cf: http://www.debian.org/doc/debian-policy/ch-relationships.html 7.1 *)

  let select = function
    |(v,(((false,_)::_) as al)) when 
      List.for_all (fun (_,a) -> not(List.mem a archs)) al -> Some v
    |(v,(((true,_)::_) as al)) when 
      List.exists (fun (_,a) -> List.mem a archs) al -> Some v
    |(v,[]) -> Some v
    |-> None
  in
  let conflicts l = List.filter_map select l in
  let depends ll = 
    List.filter_map (fun l ->
      match List.filter_map select l with 
      |[] -> None 
      | l -> Some l
    ) ll
  in
  let bins pkg = String.concat "," pkg.binary in
  List.filter_map (fun pkg ->
    let pkgarchs = pkg.architecture in
    if List.exists (fun a -> List.mem a archs) pkgarchs then
      Some (
      { Packages.default_package with
        Packages.name = src ^ sep ^ pkg.name ;
        source = (pkg.name, Some pkg.version);
        version = pkg.version;
        depends = depends (pkg.build_depends_indep @ pkg.build_depends);
        conflicts = conflicts (pkg.build_conflicts_indep @ pkg.build_conflicts);
        architecture = String.concat "," pkg.architecture;
        extras = [("type",src);("binaries",bins pkg)]
      }
      )
    else None
  ) l