diff --git a/sw/tools/Makefile b/sw/tools/Makefile index 6358d55550..e0f0b33ccf 100644 --- a/sw/tools/Makefile +++ b/sw/tools/Makefile @@ -24,7 +24,7 @@ Q=@ OCAML=ocaml OCAMLC=ocamlc -INCLUDES=-I ../lib/ocaml $(shell ocamlfind query -r -i-format xml-light) +INCLUDES=-I ../lib/ocaml $(shell ocamlfind query -r -i-format xml-light) -I . OCAMLNETINCLUDES=$(shell ocamlfind query -r -i-format netstring) OCAMLNETCMA=$(shell ocamlfind query -r -a-format -predicates byte netstring) OCAMLLEX=ocamllex @@ -42,13 +42,13 @@ gen_flight_plan.out : $(FP_CMO) ../lib/ocaml/lib-pprz.cma fp_proc.cmo : fp_proc.cmi gen_flight_plan.cmo : fp_proc.cmi +gen_common.cmo : gen_common.cmi - -%.out : %.ml Makefile +%.out : %.ml gen_common.ml Makefile @echo OC $< $(Q)$(OCAMLC) $(INCLUDES) -o $@ unix.cma str.cma ivy-ocaml.cma xml-light.cma lib-pprz.cma gen_common.cmo $< @cat ../../pprz_src_test.sh > $@ - @echo '$(OCAML) $(shell ocamlfind query -r -i-format xml-light) $(OCAMLNETINCLUDES) -I $$PAPARAZZI_SRC/sw/lib/ocaml unix.cma str.cma ivy-ocaml.cma xml-light.cma $(OCAMLNETCMA) lib-pprz.cma $$PAPARAZZI_BIN/$< $$*' >> $@ + @echo '$(OCAML) -I $$PAPARAZZI_SRC/sw/tools $(shell ocamlfind query -r -i-format xml-light) $(OCAMLNETINCLUDES) -I $$PAPARAZZI_SRC/sw/lib/ocaml unix.cma str.cma ivy-ocaml.cma xml-light.cma $(OCAMLNETCMA) lib-pprz.cma gen_common.cmo $$PAPARAZZI_BIN/$< $$*' >> $@ @chmod a+x $@ %.cmo : %.ml ../lib/ocaml/lib-pprz.cma diff --git a/sw/tools/gen_aircraft.ml b/sw/tools/gen_aircraft.ml index f748a160a6..cc5130f8e5 100644 --- a/sw/tools/gen_aircraft.ml +++ b/sw/tools/gen_aircraft.ml @@ -26,7 +26,8 @@ open Printf module U = Unix -module GC = Gen_common + +open Gen_common let (//) = Filename.concat @@ -62,9 +63,9 @@ let check_unique_id_and_name = fun conf -> (** [get_modules dir xml] * [dir] is the conf directory for modules, [xml] is the parsed airframe.xml *) let get_modules = fun dir xml -> - let modules = GC.get_modules_of_airframe xml in + let modules = Gen_common.get_modules_of_airframe xml in (* build a list (file name, (xml, xml list of flags)) *) - let extract = List.map GC.get_full_module_conf modules in + let extract = List.map Gen_common.get_full_module_conf modules in (* return a list of name and a list of pairs (xml, xml list) *) List.split extract @@ -75,14 +76,14 @@ let get_modules = fun dir xml -> **) let dump_module_section = fun xml f -> (* get modules *) - let (files, modules) = get_modules GC.modules_dir xml in + let (files, modules) = get_modules Gen_common.modules_dir xml in (* print modules directories and includes for all targets *) fprintf f "\n####################################################\n"; fprintf f "# modules makefile section\n"; fprintf f "####################################################\n"; fprintf f "\n# include modules directory for all targets\n"; (* get dir and target list *) - let dir_list = GC.get_modules_dir modules in + let dir_list = Gen_common.get_modules_dir modules in (** let target_list = union_of_lists (List.map (fun (m,_) -> get_targets_of_module m) modules) in List.iter (fun target -> fprintf f "%s.CFLAGS += -I modules -I arch/$(ARCH)/modules\n" target) target_list; @@ -96,7 +97,7 @@ let dump_module_section = fun xml f -> 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 = GC.get_targets_of_module m in + let module_target_list = Gen_common.get_targets_of_module m 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 -> @@ -116,7 +117,7 @@ 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 = GC.targets_of_field l in + let targets = Gen_common.targets_of_field l in (* Look for defines, flags, files, ... *) List.iter (fun field -> match String.lowercase (Xml.tag field) with diff --git a/sw/tools/gen_common.mli b/sw/tools/gen_common.mli new file mode 100644 index 0000000000..9ec2fc7774 --- /dev/null +++ b/sw/tools/gen_common.mli @@ -0,0 +1,64 @@ +(* + * $Id$ + * + * generic tools for modules + * + * Copyright (C) 2010 Gautier Hattenberger + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + *) + +val modules_dir : string + +(** remove all duplicated elements of a list *) +val singletonize : 'a list -> 'a 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 + +(** [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_module_conf module] Parse module configuration file + * Returns parsed xml file *) +val get_module_conf : Xml.xml -> Xml.xml + +(** [get_targets_of_module xml] Returns the list of targets of a module *) +val get_targets_of_module : Xml.xml -> string list + +(** [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 *) +val unload_unused_modules : Xml.xml list -> bool -> Xml.xml list + +(** [get_modules_name xml] + * 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 +