diff --git a/sw/tools/gen_aircraft.ml b/sw/tools/gen_aircraft.ml index 6d290cf5fc0..d7d7e22f107 100644 --- a/sw/tools/gen_aircraft.ml +++ b/sw/tools/gen_aircraft.ml @@ -92,12 +92,13 @@ let dump_module_section = fun xml f -> fprintf f "$(TARGET).CFLAGS += -I modules -I arch/$(ARCH)/modules\n"; List.iter (fun dir -> let dir_name = (String.uppercase dir)^"_DIR" in fprintf f "%s = modules/%s\n" dir_name dir) dir_list; (* parse each module *) - List.iter (fun (m, flags) -> + List.iter (fun (m, flags, extra_targets) -> let name = ExtXml.attrib m "name" in let dir = try Xml.attrib m "dir" with _ -> name in let dir_name = (String.uppercase dir)^"_DIR" in - (* get the list of all the targets for this module *) - let module_target_list = Gen_common.get_targets_of_module m in + (* get the list of all the targets for this module and concat the extra targets *) + let module_target_list = Gen_common.singletonize ( + Gen_common.get_targets_of_module m @ extra_targets) in (* print global flags as compilation defines and flags *) fprintf f "\n# makefile for module %s in modules/%s\n" name dir; List.iter (fun flag -> @@ -117,7 +118,10 @@ let dump_module_section = fun xml f -> (* Look for makefile section *) List.iter (fun l -> if ExtXml.tag_is l "makefile" then begin - let targets = Gen_common.targets_of_field l in + (* add extra targets only if default is used *) + let et = try ignore(Xml.attrib l "target"); [] with _ -> extra_targets in + let targets = Gen_common.singletonize ( + Gen_common.targets_of_field l Gen_common.default_module_targets @ et) in (* Look for defines, flags, files, ... *) List.iter (fun field -> match String.lowercase (Xml.tag field) with diff --git a/sw/tools/gen_common.ml b/sw/tools/gen_common.ml index a1c30c5faed..12148da1c0f 100644 --- a/sw/tools/gen_common.ml +++ b/sw/tools/gen_common.ml @@ -31,6 +31,8 @@ let (//) = Filename.concat let paparazzi_conf = Env.paparazzi_home // "conf" let modules_dir = paparazzi_conf // "modules" +let default_module_targets = "ap|sim" + (** remove all duplicated elements of a list *) let singletonize = fun l -> let rec loop = fun l -> @@ -51,46 +53,55 @@ let union_of_lists = fun l -> let sl = List.sort compare (List.flatten l) in singletonize sl +(** [targets_of_field] + * Returns the targets of a makefile node in modules + * Default "ap|sim" *) +let pipe_regexp = Str.regexp "|" +let targets_of_field = fun field default -> + try + Str.split pipe_regexp (ExtXml.attrib_or_default field "target" default) + with + _ -> [] + (** [get_modules_of_airframe xml] - * Returns a list of modules ("load" node) from airframe file *) + * Returns a list of pair (modules ("load" node), targets) from airframe file *) let get_modules_of_airframe = fun xml -> (* extract all "modules" sections *) let modules = List.map (fun x -> match String.lowercase (Xml.tag x) with - "modules" -> Xml.children x + "modules" -> + let targets = targets_of_field x "" in + List.map (fun m -> (m,targets)) (Xml.children x) | _ -> [] ) (Xml.children xml) in (* flatten the list (result is a list of "load" xml nodes) *) List.flatten modules -(** [get_full_module_conf module] Parse module configuration file - * Returns module file name and a pair (xml, xml list): parsed file, children *) -let get_full_module_conf = fun m -> +(** [get_full_module_conf module] Parse module configuration file (with extra targets) + * Returns module file name and a triple (xml, xml list, targets): parsed file, children, extra targets *) +let get_full_module_conf = fun (m, t) -> match Xml.tag m with "load" -> let file = modules_dir // ExtXml.attrib m "name" in - (file, (ExtXml.parse_file file, Xml.children m)) + let targets = targets_of_field m "" in + (file, (ExtXml.parse_file file, Xml.children m, t @ targets)) | _ -> Xml2h.xml_error "load" (** [get_module_conf module] Parse module configuration file * Returns parsed xml file *) let get_module_conf = fun m -> - let (_ , (conf, _)) = get_full_module_conf m in + let (_ , (conf, _, _)) = get_full_module_conf (m, []) in conf (** [get_targets_of_module xml] Returns the list of targets of a module *) let get_targets_of_module = fun m -> - let pipe_regexp = Str.regexp "|" in - let targets_of_field = fun field -> try - Str.split pipe_regexp (ExtXml.attrib_or_default field "target" "ap|sim") with _ -> [] in let targets = List.map (fun x -> match String.lowercase (Xml.tag x) with - "makefile" -> targets_of_field x + "makefile" -> targets_of_field x default_module_targets | _ -> [] ) (Xml.children m) in (* return a singletonized list *) singletonize (List.sort compare (List.flatten targets)) -(* gm *) (** [unload_unused_modules modules ?print_error] * Returns a list of [modules] where unused modules are removed * If [print_error] is true, a warning is printed *) @@ -107,36 +118,24 @@ let unload_unused_modules = fun modules print_error -> else List.find_all is_target_in_module modules - -(* gp *) (** [get_modules_name xml] * Returns a list of loaded modules' name *) let get_modules_name = fun xml -> (* extract all "modules" sections *) let modules = get_modules_of_airframe xml in (* parse modules *) - let modules = List.map (fun m -> ExtXml.parse_file (modules_dir // ExtXml.attrib m "name")) modules in + let modules = List.map (fun (m,_) -> ExtXml.parse_file (modules_dir // ExtXml.attrib m "name")) modules in (* filter the list if target is not supported *) let modules = unload_unused_modules modules false in (* return a list of modules name *) List.map (fun m -> ExtXml.attrib m "name") modules -(** [targets_of_field] - * Returns the targets of a makefile node in modules - * Default "ap|sim" *) -let pipe_regexp = Str.regexp "|" -let targets_of_field = fun field -> - try - Str.split pipe_regexp (ExtXml.attrib_or_default field "target" "ap|sim") - with - _ -> [] - (** [get_targets_of_module xml] * Returns the list of targets of a module *) let get_targets_of_module = fun m -> let targets = List.map (fun x -> match String.lowercase (Xml.tag x) with - "makefile" -> targets_of_field x + "makefile" -> targets_of_field x default_module_targets | _ -> [] ) (Xml.children m) in (* return a singletonized list *) @@ -145,6 +144,6 @@ let get_targets_of_module = fun m -> (** [get_modules_dir xml] * Returns the list of modules directories *) let get_modules_dir = fun modules -> - let dir = List.map (fun (m, _) -> try Xml.attrib m "dir" with _ -> ExtXml.attrib m "name") modules in + let dir = List.map (fun (m, _, _) -> try Xml.attrib m "dir" with _ -> ExtXml.attrib m "name") modules in singletonize (List.sort compare dir) diff --git a/sw/tools/gen_common.mli b/sw/tools/gen_common.mli index 9ec2fc7774a..1d5c98491c5 100644 --- a/sw/tools/gen_common.mli +++ b/sw/tools/gen_common.mli @@ -25,17 +25,23 @@ *) val modules_dir : string +val default_module_targets : string (** remove all duplicated elements of a list *) val singletonize : 'a list -> 'a list +(** [targets_of_field] + * Returns the targets of a makefile node in modules + * Default "ap|sim" *) +val targets_of_field : Xml.xml -> string -> string list + (** [get_modules_of_airframe xml] - * Returns a list of modules ("load" node) from airframe file *) -val get_modules_of_airframe : Xml.xml -> Xml.xml list + * Returns a list of pair (modules ("load" node), targets) from airframe file *) +val get_modules_of_airframe : Xml.xml -> (Xml.xml * string list) list -(** [get_full_module_conf module] Parse module configuration file - * Returns module file name and a pair (xml, xml list): parsed file, children *) -val get_full_module_conf : Xml.xml -> (string * (Xml.xml * Xml.xml list)) +(** [get_full_module_conf module] Parse module configuration file (with extra targets) + * Returns module file name and a pair (xml, xml list, targets): parsed file, children, extra targets *) +val get_full_module_conf : (Xml.xml * string list) -> (string * (Xml.xml * Xml.xml list * string list)) (** [get_module_conf module] Parse module configuration file * Returns parsed xml file *) @@ -53,12 +59,7 @@ val unload_unused_modules : Xml.xml list -> bool -> Xml.xml list * Returns a list of loaded modules' name *) val get_modules_name : Xml.xml -> string list -(** [targets_of_field] - * Returns the targets of a makefile node in modules - * Default "ap|sim" *) -val targets_of_field : Xml.xml -> string list - (** [get_modules_dir xml] * Returns the list of modules directories *) -val get_modules_dir : (Xml.xml * 'a) list -> string list +val get_modules_dir : (Xml.xml * 'a * 'b) list -> string list