revised version of module makefile extraction

"flag" can be used in airframe file to give a global flag or define to a module
This commit is contained in:
Gautier Hattenberger
2010-08-31 13:08:29 +00:00
parent 1a76bdc43c
commit 0948bc036f
4 changed files with 129 additions and 90 deletions
+4 -3
View File
@@ -14,8 +14,9 @@
<!--load name="infrared_i2c.xml"/--> <!--load name="infrared_i2c.xml"/-->
<!--load name="max3100.xml"/> <!--load name="max3100.xml"/>
<load name="gsm.xml"/--> <load name="gsm.xml"/-->
<load name="sys_mon.xml"> <load name="demo_module.xml">
<param name="TEST" value="1"/> <flag name="TEST" value="1"/>
<flag name="TEST_FLAG"/>
</load> </load>
<!--load name="enose.xml"/--> <!--load name="enose.xml"/-->
<load name="light.xml"/> <load name="light.xml"/>
@@ -36,7 +37,7 @@
<subsystem name="radio_control" type="ppm"/> <subsystem name="radio_control" type="ppm"/>
<subsystem name="telemetry" type="xbee_api"/> <subsystem name="telemetry" type="xbee_api"/>
<subsystem name="control_new"/> <subsystem name="control" type="new"/>
<subsystem name="attitude" type="infrared"/> <subsystem name="attitude" type="infrared"/>
<subsystem name="gps" type="ublox_lea5h"/> <subsystem name="gps" type="ublox_lea5h"/>
<subsystem name="navigation"/> <subsystem name="navigation"/>
+6 -1
View File
@@ -21,8 +21,9 @@
<!ELEMENT linear EMPTY> <!ELEMENT linear EMPTY>
<!ELEMENT makefile (#PCDATA)> <!ELEMENT makefile (#PCDATA)>
<!ELEMENT modules (load)*> <!ELEMENT modules (load)*>
<!ELEMENT load (param)*> <!ELEMENT load (param|flag)*>
<!ELEMENT param EMPTY> <!ELEMENT param EMPTY>
<!ELEMENT flag EMPTY>
<!ELEMENT firmware (target|subsystem)*> <!ELEMENT firmware (target|subsystem)*>
<!ELEMENT target (param|define)*> <!ELEMENT target (param|define)*>
<!ELEMENT subsystem (param)*> <!ELEMENT subsystem (param)*>
@@ -95,6 +96,10 @@ value CDATA #IMPLIED
unit CDATA #IMPLIED unit CDATA #IMPLIED
integer CDATA #IMPLIED> integer CDATA #IMPLIED>
<!ATTLIST flag
name CDATA #REQUIRED
value CDATA #IMPLIED>
<!ATTLIST param <!ATTLIST param
name CDATA #REQUIRED name CDATA #REQUIRED
value CDATA #REQUIRED> value CDATA #REQUIRED>
+4
View File
@@ -14,5 +14,9 @@
<flag name="DEMO_MODULE_LED" value="2"/> <flag name="DEMO_MODULE_LED" value="2"/>
<file name="demo_module.c"/> <file name="demo_module.c"/>
</makefile> </makefile>
<makefile target="demo">
<flag name="SOME_FLAG"/>
<define name="SOME_DEFINE" value="bla"/>
</makefile>
</module> </module>
+80 -51
View File
@@ -62,17 +62,61 @@ let check_unique_id_and_name = fun conf ->
let pipe_regexp = Str.regexp "|" let pipe_regexp = Str.regexp "|"
let targets_of_field = fun field -> let targets_of_field = fun field ->
try try
Str.split pipe_regexp (Xml.attrib field "target") Str.split pipe_regexp (ExtXml.attrib_or_default field "target" "ap|sim")
with with
_ -> [] _ -> []
(** singletonize a sorted list *)
let rec singletonize = fun l ->
match l with
[] | [_] -> l
| x :: ((y :: t) as yt) -> if x = y then singletonize yt else x :: singletonize yt
let get_modules = fun dir m -> (** union of two lists *)
let union = fun l1 l2 ->
let l = l1 @ l2 in
let sl = List.sort compare l in
singletonize sl
let union_of_lists = fun l ->
let sl = List.sort compare (List.flatten l) in
singletonize sl
(** [get_modules dir xml]
* [dir] is the conf directory for modules, [xml] is the parsed airframe.xml *)
let get_modules = fun dir xml ->
(* extract all "modules" sections *)
let modules = List.map (fun x ->
match String.lowercase (Xml.tag x) with
"modules" -> Xml.children x
| _ -> []
) (Xml.children xml) in
(* flatten the list (result is a list of "load" xml nodes) *)
let modules = List.flatten modules in
(* build a list (file name, (xml, xml list of flags)) *)
let extract = List.map (fun m ->
match String.lowercase (Xml.tag m) with match String.lowercase (Xml.tag m) with
"load" -> (dir // ExtXml.attrib m "name", Xml.children m) "load" -> let file = dir // ExtXml.attrib m "name" in
(file, (ExtXml.parse_file file, Xml.children m))
| tag -> failwith (sprintf "Warning: tag load is undefined; found '%s'" tag) | tag -> failwith (sprintf "Warning: tag load is undefined; found '%s'" tag)
) modules in
(* return a list of name and a list of pairs (xml, xml list) *)
List.split extract
(** [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
| _ -> []
) (Xml.children m) in
(* return a singletonized list *)
singletonize (List.sort compare (List.flatten targets))
(** [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
singletonize (List.sort compare dir)
(** (**
Search and dump the module section : Search and dump the module section :
@@ -80,46 +124,34 @@ let get_modules = fun dir m ->
f : makefile.ac f : makefile.ac
**) **)
let dump_module_section = fun xml f -> let dump_module_section = fun xml f ->
let files = ref [] in (* get modules *)
List.iter (fun x -> let (files, modules) = get_modules modules_dir xml in
if ExtXml.tag_is x "modules" then (* print modules directories and includes for all targets *)
let modules_names = List.map (get_modules modules_dir) (Xml.children x) in fprintf f "\n####################################################\n";
List.iter (fun (name,_) -> files := name :: !files) modules_names; fprintf f "# modules makefile section\n";
let modules_list = List.map (fun (m,p) -> (Xml.parse_file m, p)) modules_names in fprintf f "####################################################\n";
(* Print modules directories and includes for all targets *)
fprintf f "\n# include modules directory for all targets\n"; fprintf f "\n# include modules directory for all targets\n";
let target_list = ref [] in (* get dir and target list *)
let dir_list = ref [] in let dir_list = get_modules_dir modules in
List.iter (fun (m,_) -> let target_list = union_of_lists (List.map (fun (m,_) -> get_targets_of_module m) modules) in
let dir = try Xml.attrib m "dir" with _ -> ExtXml.attrib m "name" in List.iter (fun target -> fprintf f "%s.CFLAGS += -I modules -I arch/$(ARCH)/modules\n" target) target_list;
dir_list := List.merge String.compare !dir_list [dir]; List.iter (fun dir -> let dir_name = (String.uppercase dir)^"_DIR" in fprintf f "%s = modules/%s\n" dir_name dir) dir_list;
List.iter (fun l -> (* parse each module *)
if ExtXml.tag_is l "makefile" then List.iter (fun (m, flags) ->
target_list := List.merge String.compare !target_list (targets_of_field l); let name = ExtXml.attrib m "name" in
) (Xml.children m) let dir = try Xml.attrib m "dir" with _ -> name in
) modules_list;
List.iter (fun target -> fprintf f "%s.CFLAGS += -I modules -I arch/$(ARCH)/modules\n" target) !target_list;
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 makefile *)
List.iter (fun (modul,params) ->
let name = ExtXml.attrib modul "name" in
let dir = try Xml.attrib modul "dir" with _ -> name in
let dir_name = (String.uppercase dir)^"_DIR" in let dir_name = (String.uppercase dir)^"_DIR" in
(* Extract the list of all the targes for this module *) (* get the list of all the targes for this module *)
let module_target_list = ref [] in let module_target_list = get_targets_of_module m in
List.iter (fun l -> (* print global flags as compilation defines and flags *)
if ExtXml.tag_is l "makefile" then module_target_list := List.merge String.compare !module_target_list (targets_of_field l) fprintf f "\n# makefile for module %s in modules/%s\n" name dir;
) (Xml.children modul);
fprintf f "\n# makefile for module %s\n" name;
(* Print parameters as global copilation defines *)
List.iter (fun target -> List.iter (fun target ->
List.iter (fun param -> try List.iter (fun flag ->
let name = Xml.attrib param "name" let name = ExtXml.attrib flag "name"
and value = Xml.attrib param "value" in and value = try "="^(Xml.attrib flag "value") with _ -> "" in
fprintf f "%s.CFLAGS += -D%s=%s\n" target name value fprintf f "%s.CFLAGS += -D%s%s\n" target name value
with _ -> () ) flags
) params ) module_target_list;
) !module_target_list;
(* Look for makefile section *) (* Look for makefile section *)
List.iter (fun l -> List.iter (fun l ->
if ExtXml.tag_is l "makefile" then begin if ExtXml.tag_is l "makefile" then begin
@@ -128,16 +160,15 @@ let dump_module_section = fun xml f ->
List.iter (fun field -> List.iter (fun field ->
match String.lowercase (Xml.tag field) with match String.lowercase (Xml.tag field) with
"flag" -> "flag" ->
List.iter List.iter (fun target ->
(fun target ->
let value = try "="^(Xml.attrib field "value") with _ -> "" let value = try "="^(Xml.attrib field "value") with _ -> ""
and name = Xml.attrib field "name" in and name = Xml.attrib field "name" in
let flag_type = match (ExtXml.attrib_or_default field "type" "define") with let flag_type = match (ExtXml.attrib_or_default field "type" "define") with
"define" | "D" -> "D" "define" | "D" -> "D"
| "include" | "I" -> "I" | "include" | "I" -> "I"
| _ -> "D" in | _ -> "D" in
fprintf f "%s.CFLAGS += -%s%s%s\n" target flag_type name value) fprintf f "%s.CFLAGS += -%s%s%s\n" target flag_type name value
targets ) targets
| "file" -> | "file" ->
let name = Xml.attrib field "name" in let name = Xml.attrib field "name" in
List.iter (fun target -> fprintf f "%s.srcs += $(%s)/%s\n" target dir_name name) targets List.iter (fun target -> fprintf f "%s.srcs += $(%s)/%s\n" target dir_name name) targets
@@ -154,13 +185,11 @@ let dump_module_section = fun xml f ->
| _ -> fprintf stderr "Warning: wrong makefile section in module '%s'\n" name | _ -> fprintf stderr "Warning: wrong makefile section in module '%s'\n" name
end end
| _ -> () | _ -> ()
) ) (Xml.children l)
(Xml.children l) end) (Xml.children m)
end) ) modules;
(Xml.children modul)) (** returns a list of modules file name *)
modules_list) files
(Xml.children xml);
!files
(** (**
Search and dump the makefile sections Search and dump the makefile sections