New makefile architecture.
[bertos.git] / wizard / bertos_utils.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # This file is part of BeRTOS.
5 #
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 #
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction.  Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License.  This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
28 #
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30 #
31 # $Id$
32 #
33 # Author: Lorenzo Berni <duplo@develer.com>
34 #
35
36 import os
37 import fnmatch
38 import glob
39 import re
40 import shutil
41 # Use custom copytree function
42 import copytree
43 import pickle
44
45 import const
46 import plugins
47 import DefineException
48
49 from _wizard_version import WIZARD_VERSION
50
51 from LoadException import VersionException, ToolchainException
52
53 def isBertosDir(directory):
54    return os.path.exists(directory + "/VERSION")
55
56 def bertosVersion(directory):
57    return open(directory + "/VERSION").readline().strip()
58
59 def enabledModules(project_info):
60     enabled_modules = []
61     for name, module in project_info.info("MODULES").items():
62         if module["enabled"]:
63             enabled_modules.append(name)
64     return enabled_modules
65
66 def presetList(directory):
67     """
68     Return the list of the preset found in the selected BeRTOS Version.
69     """
70     abspath = os.path.join(directory, const.PREDEFINED_BOARDS_DIR)
71     preset_list = dict([
72         (os.path.join(abspath, preset_dir), presetInfo(os.path.join(abspath, preset_dir)))
73         for preset_dir in os.listdir(os.path.join(directory, const.PREDEFINED_BOARDS_DIR))
74     ])
75     return preset_list
76
77 def presetInfo(preset_dir):
78     """
79     Return the preset-relevant info contined into the project_file.
80     """
81     preset_info = pickle.loads(open(os.path.join(preset_dir, "project.bertos"), "r").read())
82     try:
83         description = open(os.path.join(preset_dir, "description"), "r").read()
84     except IOError:
85         # No description file found.
86         description = ""
87     relevant_info = {
88         "CPU_NAME": preset_info.get("CPU_NAME"),
89         "SELECTED_FREQ": preset_info.get("SELECTED_FREQ"),
90         "WIZARD_VERSION": preset_info.get("WIZARD_VERSION", None),
91         "PRESET_NAME": preset_info.get("PROJECT_NAME"),
92         "PRESET_DESCRIPTION": description.decode("utf-8"),
93     }
94     return relevant_info
95
96 def mergeSources(srcdir, new_sources, old_sources):
97     # The current mergeSources function provide only a raw copy of the sources in the
98     # created project.
99     #
100     # TODO: implement the three way merge algorithm
101     #
102     shutil.rmtree(srcdir, True)
103     copytree.copytree(os.path.join(new_sources, "bertos"), srcdir, ignore_list=const.IGNORE_LIST)
104
105 def projectFileGenerator(project_info):
106     directory = project_info.info("PROJECT_PATH")
107     project_data = {}
108     enabled_modules = []
109     for module, information in project_info.info("MODULES").items():
110         if information["enabled"]:
111             enabled_modules.append(module)
112     project_data["ENABLED_MODULES"] = enabled_modules
113     if project_info.info("PRESET"):
114         # For presets save again the BERTOS_PATH into project file
115         project_data["PRESET"] = True
116         project_data["BERTOS_PATH"] = project_info.info("BERTOS_PATH")
117     else:
118         # Use the local BeRTOS version instead of the original one
119         # project_data["BERTOS_PATH"] = project_info.info("BERTOS_PATH")
120         project_data["BERTOS_PATH"] = directory
121     project_data["PROJECT_NAME"] = project_info.info("PROJECT_NAME", os.path.basename(directory))
122     project_data["PROJECT_SRC_PATH"] = project_info.info("PROJECT_SRC_PATH")
123     project_data["TOOLCHAIN"] = project_info.info("TOOLCHAIN")
124     project_data["CPU_NAME"] = project_info.info("CPU_NAME")
125     project_data["SELECTED_FREQ"] = project_info.info("SELECTED_FREQ")
126     project_data["OUTPUT"] = project_info.info("OUTPUT")
127     project_data["WIZARD_VERSION"] = WIZARD_VERSION
128     project_data["PRESET"] = project_info.info("PRESET")
129     return pickle.dumps(project_data)
130
131 def loadPlugin(plugin):
132     """
133     Returns the given plugin module.
134     """
135     return getattr(__import__("plugins", {}, {}, [plugin]), plugin)
136
137 def versionFileGenerator(project_info, version_file):
138     version = bertosVersion(project_info.info("BERTOS_PATH"))
139     return version_file.replace('$version', version)
140
141 def userMkGenerator(project_info):
142     makefile = open(os.path.join(const.DATA_DIR, "mktemplates/template_user.mk"), "r").read()
143     destination = os.path.join(project_info.prjdir, os.path.basename(project_info.prjdir) + "_user.mk")
144     # Deadly performances loss was here :(
145     mk_data = {}
146     mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH"))
147     mk_data["$ppath"] = os.path.basename(project_info.info("PROJECT_SRC_PATH"))
148     mk_data["$main"] = os.path.basename(project_info.info("PROJECT_PATH")) + "/main.c"
149     for key in mk_data:
150         while makefile.find(key) != -1:
151             makefile = makefile.replace(key, mk_data[key])
152     open(destination, "w").write(makefile)
153
154 def mkGenerator(project_info):
155     """
156     Generates the mk file for the current project.
157     """
158     makefile = open(os.path.join(const.DATA_DIR, "mktemplates/template.mk"), "r").read()
159     destination = os.path.join(project_info.prjdir, os.path.basename(project_info.prjdir) + ".mk")
160     mk_data = {}
161     mk_data["$pname"] = project_info.info("PROJECT_NAME")
162     mk_data["$ppath"] = os.path.basename(project_info.info("PROJECT_SRC_PATH"))
163     mk_data["$cpuclockfreq"] = project_info.info("SELECTED_FREQ")
164     cpu_mk_parameters = []
165     for key, value in project_info.info("CPU_INFOS").items():
166         if key.startswith(const.MK_PARAM_ID):
167             cpu_mk_parameters.append("%s = %s" %(key.replace("MK", mk_data["$pname"]), value))
168     mk_data["$cpuparameters"] = "\n".join(cpu_mk_parameters)
169     mk_data["$csrc"], mk_data["$pcsrc"], mk_data["$cppasrc"], mk_data["$cxxsrc"], mk_data["$asrc"], mk_data["$constants"] = csrcGenerator(project_info)
170     mk_data["$prefix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[0])
171     mk_data["$suffix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[1])
172     mk_data["$main"] = os.path.basename(project_info.info("PROJECT_PATH")) + "/main.c"
173     for key in mk_data:
174         while makefile.find(key) != -1:
175             makefile = makefile.replace(key, mk_data[key])
176     open(destination, "w").write(makefile)
177
178 def makefileGenerator(project_info):
179     """
180     Generate the Makefile for the current project.
181     """
182     makefile = open(os.path.join(const.DATA_DIR, "mktemplates/Makefile"), "r").read()
183     destination = os.path.join(project_info.maindir, "Makefile")
184     # TODO write a general function that works for both the mk file and the Makefile
185     mk_data = {}
186     mk_data["$pname"] = project_info.info("PROJECT_NAME")
187     mk_data["$ppath"] = os.path.basename(project_info.info("PROJECT_SRC_PATH"))
188     for key in mk_data:
189         while makefile.find(key) != -1:
190             makefile = makefile.replace(key, mk_data[key])
191     open(destination, "w").write(makefile)
192
193 def csrcGenerator(project_info):
194     modules = project_info.info("MODULES")
195     files = project_info.info("FILES")
196     if "harvard" in project_info.info("CPU_INFOS")["CPU_TAGS"]:
197         harvard = True
198     else:
199         harvard = False
200     # file to be included in CSRC variable
201     csrc = []
202     # file to be included in PCSRC variable
203     pcsrc = []
204     # files to be included in CPPASRC variable
205     cppasrc = []
206     # files to be included in CXXSRC variable
207     cxxsrc = []
208     # files to be included in ASRC variable
209     asrc = []
210     # constants to be included at the beginning of the makefile
211     constants = {}
212     for module, information in modules.items():
213         module_files = set([])
214         dependency_files = set([])
215         # assembly sources
216         asm_files = set([])
217         hwdir = os.path.basename(project_info.info("PROJECT_PATH")) + "/hw" 
218         if information["enabled"]:
219             if "constants" in information:
220                 constants.update(information["constants"])
221             cfiles, sfiles = findModuleFiles(module, project_info)
222             module_files |= set(cfiles)
223             asm_files |= set(sfiles)
224             for file in information["hw"]:
225                 if file.endswith(".c"):
226                     module_files |= set([hwdir + "/" + os.path.basename(file)])
227             for file_dependency in information["depends"] + tuple(files.keys()):
228                     dependencyCFiles, dependencySFiles = findModuleFiles(file_dependency, project_info)
229                     dependency_files |= set(dependencyCFiles)
230                     asm_files |= set(dependencySFiles)
231             for file in module_files:
232                 if not harvard or information.get("harvard", "both") == "both":
233                     csrc.append(file)
234                 if harvard and "harvard" in information:
235                     pcsrc.append(file)
236             for file in dependency_files:
237                 csrc.append(file)
238             for file in project_info.info("CPU_INFOS")["C_SRC"]:
239                 csrc.append(file)
240             for file in project_info.info("CPU_INFOS")["PC_SRC"]:
241                 pcsrc.append(file)
242             for file in asm_files:
243                 cppasrc.append(file)
244     for file in project_info.info("CPU_INFOS")["CPPA_SRC"]:
245         cppasrc.append(file)
246     for file in project_info.info("CPU_INFOS")["CXX_SRC"]:
247         cxxsrc.append(file)
248     for file in project_info.info("CPU_INFOS")["ASRC"]:
249         asrc.append(file)
250     csrc = set(csrc)
251     csrc = " \\\n\t".join(csrc) + " \\"
252     pcsrc = set(pcsrc)
253     pcsrc = " \\\n\t".join(pcsrc) + " \\"
254     cppasrc = set(cppasrc)
255     cppasrc = " \\\n\t".join(cppasrc) + " \\"
256     cxxsrc = set(cxxsrc)
257     cxxsrc = " \\\n\t".join(cxxsrc) + " \\"
258     asrc = set(asrc)
259     asrc = " \\\n\t".join(asrc) + " \\"
260     constants = "\n".join([os.path.basename(project_info.info("PROJECT_PATH")) + "_" + key + " = " + unicode(value) for key, value in constants.items()])
261     return csrc, pcsrc, cppasrc, cxxsrc, asrc, constants
262
263 def findModuleFiles(module, project_info):
264     # Find the files related to the selected module
265     cfiles = []
266     sfiles = []
267     # .c files related to the module and the cpu architecture
268     for filename, path in project_info.searchFiles(module + ".c"):
269         path = path.replace(project_info.info("BERTOS_PATH") + os.sep, "")
270         path = replaceSeparators(path)
271         cfiles.append(path + "/" + filename)
272     # .s files related to the module and the cpu architecture
273     for filename, path in project_info.searchFiles(module + ".s") + \
274             project_info.searchFiles(module + ".S"):
275         path = path.replace(project_info.info("BERTOS_PATH") + os.sep, "")
276         path = replaceSeparators(path)
277         sfiles.append(path + "/" + filename)
278     # .c and .s files related to the module and the cpu tags
279     tags = project_info.info("CPU_INFOS")["CPU_TAGS"]
280
281     # Awful, but secure check for version
282     # TODO: split me in a method/function
283     try:
284         version_string = bertosVersion(project_info.info("BERTOS_PATH"))
285         version_list = [int(i) for i in version_string.split()[-1].split('.')]
286         if version_list < [2, 5]:
287             # For older versions of BeRTOS add the toolchain to the tags
288             tags.append(project_info.info("CPU_INFOS")["TOOLCHAIN"])
289     except ValueError:
290         # If the version file hasn't a valid version number do nothing
291         pass
292
293     for tag in tags:
294         for filename, path in project_info.searchFiles(module + "_" + tag + ".c"):
295             path = path.replace(project_info.info("BERTOS_PATH") + os.sep, "")
296             if os.sep != "/":
297                 path = replaceSeparators(path)
298             cfiles.append(path + "/" + filename)
299         for filename, path in project_info.searchFiles(module + "_" + tag + ".s") + \
300                 project_info.searchFiles(module + "_" + tag + ".S"):
301             path = path.replace(project_info.info("BERTOS_PATH") + os.sep, "")
302             path = replaceSeparators(path)
303             sfiles.append(path + "/" + filename)
304     return cfiles, sfiles
305
306 def replaceSeparators(path):
307     """
308     Replace the separators in the given path with unix standard separator.
309     """
310     if os.sep != "/":
311         while path.find(os.sep) != -1:
312             path = path.replace(os.sep, "/")
313     return path
314
315 def getSystemPath():
316     path = os.environ["PATH"]
317     if os.name == "nt":
318         path = path.split(";")
319     else:
320         path = path.split(":")
321     return path
322
323 def findToolchains(path_list):
324     toolchains = []
325     for element in path_list:
326         for toolchain in glob.glob(element+ "/" + const.GCC_NAME):
327             toolchains.append(toolchain)
328     return list(set(toolchains))
329
330 def getToolchainInfo(output):
331     info = {}
332     expr = re.compile("Target: .*")
333     target = expr.findall(output)
334     if len(target) == 1:
335         info["target"] = target[0].split("Target: ")[1]
336     expr = re.compile("gcc version [0-9,.]*")
337     version = expr.findall(output)
338     if len(version) == 1:
339         info["version"] = version[0].split("gcc version ")[1]
340     expr = re.compile("gcc version [0-9,.]* \(.*\)")
341     build = expr.findall(output)
342     if len(build) == 1:
343         build = build[0].split("gcc version ")[1]
344         build = build[build.find("(") + 1 : build.find(")")]
345         info["build"] = build
346     expr = re.compile("Configured with: .*")
347     configured = expr.findall(output)
348     if len(configured) == 1:
349         info["configured"] = configured[0].split("Configured with: ")[1]
350     expr = re.compile("Thread model: .*")
351     thread = expr.findall(output)
352     if len(thread) == 1:
353         info["thread"] = thread[0].split("Thread model: ")[1]
354     return info
355
356 def getToolchainName(toolchain_info):
357     name = "GCC " + toolchain_info["version"] + " - " + toolchain_info["target"].strip()
358     return name
359
360 def getTagSet(cpu_info):
361     tag_set = set([])
362     for cpu in cpu_info:
363         tag_set |= set([cpu["CPU_NAME"]])
364         tag_set |= set(cpu["CPU_TAGS"])
365         tag_set |= set([cpu["TOOLCHAIN"]])
366     return tag_set
367         
368
369 def getInfos(definition):
370     D = {}
371     D.update(const.CPU_DEF)
372     def include(filename, dict = D, directory=definition[1]):
373         execfile(directory + "/" + filename, {}, D)
374     D["include"] = include
375     include(definition[0], D)
376     D["CPU_NAME"] = definition[0].split(".")[0]
377     D["DEFINITION_PATH"] = definition[1] + "/" + definition[0]
378     del D["include"]
379     return D
380
381 def getCommentList(string):
382     comment_list = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/", string)
383     comment_list = [re.findall(r"^\s*\* *(.*?)$", comment, re.MULTILINE) for comment in comment_list]
384     return comment_list
385
386 def loadModuleDefinition(first_comment):
387     to_be_parsed = False
388     module_definition = {}
389     for num, line in enumerate(first_comment):
390         index = line.find("$WIZ$")
391         if index != -1:
392             to_be_parsed = True
393             try:
394                 exec line[index + len("$WIZ$ "):] in {}, module_definition
395             except:
396                 raise ParseError(num, line[index:])
397         elif line.find("\\brief") != -1:
398             module_definition["module_description"] = line[line.find("\\brief") + len("\\brief "):]
399     module_dict = {}
400     if "module_name" in module_definition:
401         module_name = module_definition[const.MODULE_DEFINITION["module_name"]]
402         del module_definition[const.MODULE_DEFINITION["module_name"]]
403         module_dict[module_name] = {}
404         if const.MODULE_DEFINITION["module_depends"] in module_definition:
405             depends = module_definition[const.MODULE_DEFINITION["module_depends"]]
406             del module_definition[const.MODULE_DEFINITION["module_depends"]]
407             if type(depends) == str:
408                 depends = (depends,)
409             module_dict[module_name]["depends"] = depends
410         else:
411             module_dict[module_name]["depends"] = ()
412         if const.MODULE_DEFINITION["module_configuration"] in module_definition:
413             module_dict[module_name]["configuration"] = module_definition[const.MODULE_DEFINITION["module_configuration"]]
414             del module_definition[const.MODULE_DEFINITION["module_configuration"]]
415         else:
416             module_dict[module_name]["configuration"] = ""
417         if "module_description" in module_definition:
418             module_dict[module_name]["description"] = module_definition["module_description"]
419             del module_definition["module_description"]
420         if const.MODULE_DEFINITION["module_harvard"] in module_definition:
421             harvard = module_definition[const.MODULE_DEFINITION["module_harvard"]]
422             module_dict[module_name]["harvard"] = harvard
423             del module_definition[const.MODULE_DEFINITION["module_harvard"]]
424         if const.MODULE_DEFINITION["module_hw"] in module_definition:
425             hw = module_definition[const.MODULE_DEFINITION["module_hw"]]
426             del module_definition[const.MODULE_DEFINITION["module_hw"]]
427             if type(hw) == str:
428                 hw = (hw, )
429             module_dict[module_name]["hw"] = hw
430         else:
431             module_dict[module_name]["hw"] = ()
432         if const.MODULE_DEFINITION["module_supports"] in module_definition:
433             supports = module_definition[const.MODULE_DEFINITION["module_supports"]]
434             del module_definition[const.MODULE_DEFINITION["module_supports"]]
435             module_dict[module_name]["supports"] = supports
436         module_dict[module_name]["constants"] = module_definition
437         module_dict[module_name]["enabled"] = False
438     return to_be_parsed, module_dict
439
440 def isSupported(project, module=None, property_id=None):
441     if not module and property_id:
442         item = project.info("CONFIGURATIONS")[property_id[0]][property_id[1]]["informations"]
443     else:
444         item = project.info("MODULES")[module]
445     tag_dict = project.info("ALL_CPU_TAGS")
446     if "supports" in item:
447         support_string = item["supports"]
448         supported = {}
449         try:
450             exec "supported = " + support_string in tag_dict, supported
451         except:
452             raise SupportedException(support_string)
453         return supported["supported"]
454     else:
455         return True
456
457 def loadDefineLists(comment_list):
458     define_list = {}
459     for comment in comment_list:
460         for num, line in enumerate(comment):
461             index = line.find("$WIZ$")
462             if index != -1:
463                 try:
464                     exec line[index + len("$WIZ$ "):] in {}, define_list
465                 except:
466                     raise ParseError(num, line[index:])
467     for key, value in define_list.items():
468         if type(value) == str:
469             define_list[key] = (value,)
470     return define_list
471
472 def getDescriptionInformations(comment):
473     """
474     Take the doxygen comment and strip the wizard informations, returning the tuple
475     (comment, wizard_information)
476     """
477     brief = ""
478     description = ""
479     information = {}
480     for num, line in enumerate(comment):
481         index = line.find("$WIZ$")
482         if index != -1:
483             if len(brief) == 0:
484                 brief += line[:index].strip()
485             else:
486                 description += " " + line[:index]
487             try:
488                 exec line[index + len("$WIZ$ "):] in {}, information
489             except:
490                 raise ParseError(num, line[index:])
491         else:
492             if len(brief) == 0:
493                 brief += line.strip()
494             else:
495                 description += " " + line
496                 description = description.strip()
497     return brief.strip(), description.strip(), information
498
499 def getDefinitionBlocks(text):
500     """
501     Take a text and return a list of tuple (description, name-value).
502     """
503     block = []
504     block_tmp = re.finditer(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)
505     for match in block_tmp:
506         # Only the first element is needed
507         comment = match.group(1)
508         define = match.group(2)
509         start = match.start()
510         block.append(([re.findall(r"^\s*\* *(.*?)$", line, re.MULTILINE)[0] for line in comment.splitlines()], define, start))
511     for match in re.finditer(r"/{3}\s*([^<].*?)\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
512         comment = match.group(1)
513         define = match.group(2)
514         start = match.start()
515         block.append(([comment], define, start))
516     for match in re.finditer(r"#define\s*(.*?)\s*/{3}<\s*(.+?)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
517         comment = match.group(2)
518         define = match.group(1)
519         start = match.start()
520         block.append(([comment], define, start))
521     return block
522
523 def formatParamNameValue(text):
524     """
525     Take the given string and return a tuple with the name of the parameter in the first position
526     and the value in the second.
527     """
528     block = re.findall("\s*([^\s]+)\s*(.+?)\s*$", text, re.MULTILINE)
529     return block[0]
530
531 def loadConfigurationInfos(path):
532     """
533     Return the module configurations found in the given file as a dict with the
534     parameter name as key and a dict containig the fields above as value:
535         "value": the value of the parameter
536         "description": the description of the parameter
537         "informations": a dict containig optional informations:
538             "type": "int" | "boolean" | "enum"
539             "min": the minimum value for integer parameters
540             "max": the maximum value for integer parameters
541             "long": boolean indicating if the num is a long
542             "unsigned": boolean indicating if the num is an unsigned
543             "value_list": the name of the enum for enum parameters
544             "conditional_deps": the list of conditional dependencies for boolean parameters
545     """
546     configuration_infos = {}
547     configuration_infos["paramlist"] = []
548     for comment, define, start in getDefinitionBlocks(open(path, "r").read()):
549         name, value = formatParamNameValue(define)
550         brief, description, informations = getDescriptionInformations(comment)
551         configuration_infos["paramlist"].append((start, name))
552         configuration_infos[name] = {}
553         configuration_infos[name]["value"] = value
554         configuration_infos[name]["informations"] = informations
555         if not "type" in configuration_infos[name]["informations"]:
556             configuration_infos[name]["informations"]["type"] = findParameterType(configuration_infos[name])
557         if ("type" in configuration_infos[name]["informations"] and
558                 configuration_infos[name]["informations"]["type"] == "int" and
559                 configuration_infos[name]["value"].find("L") != -1):
560             configuration_infos[name]["informations"]["long"] = True
561             configuration_infos[name]["value"] = configuration_infos[name]["value"].replace("L", "")
562         if ("type" in configuration_infos[name]["informations"] and
563                 configuration_infos[name]["informations"]["type"] == "int" and
564                 configuration_infos[name]["value"].find("U") != -1):
565             configuration_infos[name]["informations"]["unsigned"] = True
566             configuration_infos[name]["value"] = configuration_infos[name]["value"].replace("U", "")
567         if "conditional_deps" in configuration_infos[name]["informations"]:
568             if (type(configuration_infos[name]["informations"]["conditional_deps"]) == str or
569                     type(configuration_infos[name]["informations"]["conditional_deps"]) == unicode):
570                 configuration_infos[name]["informations"]["conditional_deps"] = (configuration_infos[name]["informations"]["conditional_deps"], )
571             elif type(configuration_infos[name]["informations"]["conditional_deps"]) == tuple:
572                 pass
573             else:
574                 configuration_infos[name]["informations"]["conditional_deps"] = ()
575         configuration_infos[name]["description"] = description
576         configuration_infos[name]["brief"] = brief
577     return configuration_infos
578
579 def updateConfigurationValues(def_conf, user_conf):
580     for param in def_conf["paramlist"]:
581         if param[1] in user_conf and "value" in user_conf[param[1]]:
582             def_conf[param[1]]["value"] = user_conf[param[1]]["value"]
583     return def_conf
584
585 def findParameterType(parameter):
586     if "value_list" in parameter["informations"]:
587         return "enum"
588     if "min" in parameter["informations"] or "max" in parameter["informations"] or re.match(r"^\d+U?L?$", parameter["value"]) != None:
589         return "int"
590
591 def sub(string, parameter, value):
592     """
593     Substitute the given value at the given parameter define in the given string
594     """
595     return re.sub(r"(?P<define>#define\s+" + parameter + r"\s+)([^\s]+)", r"\g<define>" + value, string)
596
597 def isInt(informations):
598     """
599     Return True if the value is a simple int.
600     """
601     if ("long" not in informatios or not informations["long"]) and ("unsigned" not in informations or informations["unsigned"]):
602         return True
603     else:
604         return False
605
606 def isLong(informations):
607     """
608     Return True if the value is a long.
609     """
610     if "long" in informations and informations["long"] and "unsigned" not in informations:
611         return True
612     else:
613         return False
614
615 def isUnsigned(informations):
616     """
617     Return True if the value is an unsigned.
618     """
619     if "unsigned" in informations and informations["unsigned"] and "long" not in informations:
620         return True
621     else:
622         return False
623
624 def isUnsignedLong(informations):
625     """
626     Return True if the value is an unsigned long.
627     """
628     if "unsigned" in informations and "long" in informations and informations["unsigned"] and informations["long"]:
629         return True
630     else:
631         return False
632
633 class ParseError(Exception):
634     def __init__(self, line_number, line):
635         Exception.__init__(self)
636         self.line_number = line_number
637         self.line = line
638
639 class SupportedException(Exception):
640     def __init__(self, support_string):
641         Exception.__init__(self)
642         self.support_string = support_string