4 # This file is part of slimqc.
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.
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.
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
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.
29 # Copyright 2010 Develer S.r.l. (http://www.develer.com/)
33 # Author: Lorenzo Berni <duplo@develer.com>
38 from bertos_utils import replaceSeparators, csrcGenerator
40 def _userMkGenerator(project_info):
41 makefile = open(os.path.join(const.DATA_DIR, "mktemplates/old/template.mk"), "r").read()
42 destination = os.path.join(project_info.prjdir, os.path.basename(project_info.prjdir) + ".mk")
43 # Deadly performances loss was here :(
45 mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH"))
46 mk_data["$main"] = os.path.basename(project_info.info("PROJECT_PATH")) + "/main.c"
48 makefile = makefile.replace(key, mk_data[key])
49 open(destination, "w").write(makefile)
51 def _mkGenerator(project_info):
53 Generates the mk file for the current project.
55 makefile = open(os.path.join(const.DATA_DIR, "mktemplates/old/template_wiz.mk"), "r").read()
56 destination = os.path.join(project_info.prjdir, os.path.basename(project_info.prjdir) + "_wiz.mk")
58 mk_data["$pname"] = project_info.info("PROJECT_NAME")
59 mk_data["$cpuclockfreq"] = project_info.info("SELECTED_FREQ")
60 cpu_mk_parameters = []
61 for key, value in project_info.info("CPU_INFOS").items():
62 if key.startswith(const.MK_PARAM_ID):
63 cpu_mk_parameters.append("%s = %s" %(key.replace("MK", mk_data["$pname"]), value))
64 mk_data["$cpuparameters"] = "\n".join(cpu_mk_parameters)
65 mk_data["$csrc"], mk_data["$pcsrc"], mk_data["$cppasrc"], mk_data["$cxxsrc"], mk_data["$asrc"], mk_data["$constants"] = csrcGenerator(project_info)
66 mk_data["$prefix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[0])
67 mk_data["$suffix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[1])
68 mk_data["$main"] = os.path.basename(project_info.info("PROJECT_PATH")) + "/main.c"
70 makefile = makefile.replace(key, mk_data[key])
71 open(destination, "w").write(makefile)
73 def _makefileGenerator(project_info):
75 Generate the Makefile for the current project.
77 makefile = open(os.path.join(const.DATA_DIR, "mktemplates/old/Makefile"), "r").read()
78 destination = os.path.join(project_info.maindir, "Makefile")
79 # TODO write a general function that works for both the mk file and the Makefile
80 makefile = makefile.replace("$pname", project_info.info("PROJECT_NAME"))
81 open(destination, "w").write(makefile)
83 def updateProject(project_data):
85 Update incrementally the project_data loaded from a BeRTOS Wizard project
88 wizard_version = project_data.get("WIZARD_VERSION", 0)
89 if wizard_version < 1:
90 # Ignore the BERTOS_PATH inside the project file for older project
91 project_data["SOURCES_PATH"] = project_dir
92 if wizard_version < 2:
93 # Use SOURCES_PATH instead of BERTOS_PATH for backward compatibility
94 project_data["BERTOS_PATH"] = project_data["SOURCES_PATH"]
95 if wizard_version < 3:
96 # Use older makefile templates and generators using monkey patching
98 bertos_utils.mkGenerator = _mkGenerator
99 bertos_utils.userMkGenerator = _userMkGenerator
100 bertos_utils.makefileGenerator = _makefileGenerator