let get_architectures native_opt foreign =
let cmd = "apt-config dump" in
let arch = ref "" in
let archs = ref [] in
let aux () =
let out = Std.input_list (Unix.open_process_in cmd) in
List.iter (fun s ->
let key, value = ExtString.String.split s " " in
if key = "APT::Architecture" then
arch := ExtString.String.slice ~first: 1 ~last:(-2) value
else if key = "APT::Architectures::" || key = "APT::Architectures" then
let s = ExtString.String.slice ~first:1 ~last:(-2) value in
if s <> "" then
archs := (ExtString.String.slice ~first:1 ~last:(-2) value)::!archs
) out;
debug "Atomatically set native as %s and foreign archs as %s" !arch (String.concat "," !archs);
in
match native_opt, foreign with
|None,None -> aux () ; (!arch,List.filter ((<>) !arch) !archs)
|None,Some l -> fatal "Native arch is missing while Foregin archs are specified"
|Some a,None -> (a,[])
|Some a,Some l -> (a,l)