Skip to content

Commit

Permalink
unload modules if the target is not supported (this may require a cle…
Browse files Browse the repository at this point in the history
…an_ac)
  • Loading branch information
gautierhattenberger committed Sep 6, 2010
1 parent 0a9d04e commit acdf61f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
10 changes: 4 additions & 6 deletions Makefile.ac
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ MODULES_H=$(ACINCLUDE)/modules.h
MODULES_DIR=$(PAPARAZZI_HOME)/conf/modules/
AIRCRAFT_MD5=$(AIRCRAFT_CONF_DIR)/aircraft.md5


# "make Q=''" to get full echo
Q=@

Expand Down Expand Up @@ -130,13 +129,12 @@ $(MODULES_H) : $(CONF)/$(AIRFRAME_XML) $(TOOLS)/gen_modules.out $(CONF)/modules/
$(Q)$(TOOLS)/gen_modules.out $(MODULES_DIR) $(SETTINGS_MODULES) $< > $@
$(Q)chmod a+r $@


ac_h :
%.ac_h :
$(Q)if (expr "$(AIRCRAFT)"); then : ; else echo "AIRCRAFT undefined: type 'make AIRCRAFT=AircraftName ...'"; exit 1; fi
@echo BUILD $(AIRCRAFT)
$(Q)PAPARAZZI_SRC=$(PAPARAZZI_SRC) PAPARAZZI_HOME=$(PAPARAZZI_HOME) Q=$(Q) $(TOOLS)/gen_aircraft.out $(AIRCRAFT)
@echo BUILD $(AIRCRAFT), TARGET $*
$(Q)PAPARAZZI_SRC=$(PAPARAZZI_SRC) PAPARAZZI_HOME=$(PAPARAZZI_HOME) TARGET=$* Q=$(Q) $(TOOLS)/gen_aircraft.out $(AIRCRAFT)

%.compile: ac_h
%.compile: %.ac_h
cd $(AIRBORNE); $(MAKE) TARGET=$* all

%.wr_fuses: %.compile
Expand Down
4 changes: 3 additions & 1 deletion sw/tools/gen_aircraft.ml
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ let () =
assert(Sys.command (sprintf "mv %s %s" temp_makefile_ac makefile_ac) = 0)
end;

make "all_ac_h" "";
(* Get TARGET env, needed to build modules.h according to the target *)
let t = Printf.sprintf "TARGET=%s" (try Sys.getenv "TARGET" with _ -> "") in
make "all_ac_h" t;
make_opt "radio_ac_h" "RADIO" "radio";
make_opt "flight_plan_ac_h" "FLIGHT_PLAN" "flight_plan"
with
Expand Down
31 changes: 31 additions & 0 deletions sw/tools/gen_modules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,36 @@ let write_settings = fun xml_file out_set modules ->
fprintf out_set " </dl_settings>\n";
fprintf out_set "</settings>\n"

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 rec singletonize = fun l ->
match l with
[] | [_] -> l
| x :: ((y :: t) as yt) -> if x = y then singletonize yt else x :: singletonize yt
in
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))

let unload_unused_modules = fun modules ->
let target = try Sys.getenv "TARGET" with _ -> "" in
let is_target_in_module = fun m ->
let target_is_in_module = List.exists (fun x -> String.compare target x = 0) (get_targets_of_module m) in
if not target_is_in_module then
Printf.fprintf stderr "Module %s unloaded, target %s not supported\n" (Xml.attrib m "name") target;
target_is_in_module
in
if String.length target = 0 then
modules
else
List.find_all is_target_in_module modules

let h_name = "MODULES_H"

let () =
Expand All @@ -349,6 +379,7 @@ let () =
let main_freq = try (int_of_string (Xml.attrib modules "main_freq")) with _ -> !freq in
freq := main_freq;
let modules_list = List.map (get_modules modules_dir) (Xml.children modules) in
let modules_list = unload_unused_modules modules_list in
let modules_name =
(List.map (fun l -> try Xml.attrib l "name" with _ -> "") (Xml.children modules)) @
(List.map (fun m -> try Xml.attrib m "name" with _ -> "") modules_list) in
Expand Down

0 comments on commit acdf61f

Please sign in to comment.