Skip to content

Commit 9d386b2

Browse files
committed
export: Fix Windows problems with Sw4STM32
Quoting linker preprocessor command, if path contains parentheses. Using relative path to shorten list of included directories. Using Eclipse variables to get path to preprocessor.
1 parent e1d163b commit 9d386b2

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

tools/export/sw4stm32/__init__.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ def process_sw_options(self, opts, flags_in):
313313
item = opts['ld']['flags'][index]
314314
if not item.startswith('-Wl,'):
315315
opts['ld']['flags'][index] = '-Wl,' + item
316+
# Assembler options
317+
for as_def in self.as_defines:
318+
if '=' in as_def:
319+
opts['as']['other'] += ' --defsym ' + as_def
320+
else:
321+
opts['as']['other'] += ' --defsym ' + as_def + '=1'
316322

317323
def generate(self):
318324
"""
@@ -349,8 +355,9 @@ def generate(self):
349355
self.cpp_defines = self.c_defines
350356
print 'Symbols: {0}'.format(len(self.c_defines))
351357

352-
self.include_path = [self.filter_dot(s)
353-
for s in self.resources.inc_dirs]
358+
self.include_path = []
359+
for s in self.resources.inc_dirs:
360+
self.include_path.append("../" + self.filter_dot(s))
354361
print ('Include folders: {0}'.format(len(self.include_path)))
355362

356363
self.compute_exclusions()
@@ -362,6 +369,15 @@ def generate(self):
362369

363370
lib_dirs = [self.filter_dot(s) for s in self.resources.lib_dirs]
364371

372+
preproc_cmd = ""
373+
# Hack for Windows. Build fails if command contains parentheses.
374+
if ('(' in self.toolchain.preproc[0] or ')' in self.toolchain.preproc[0]) and self.toolchain.preproc[0][0] != "'":
375+
preproc_cmd = '"' + \
376+
self.toolchain.preproc[0] + '"' + " " + \
377+
" ".join(self.toolchain.preproc[1:])
378+
else:
379+
preproc_cmd = " ".join(self.toolchain.preproc)
380+
365381
for id in ['debug', 'release']:
366382
opts = {}
367383
opts['common'] = {}
@@ -407,13 +423,6 @@ def generate(self):
407423

408424
self.process_sw_options(opts, flags)
409425

410-
if opts['as']['usepreprocessor']:
411-
opts['as']['other'] += ' -x assembler-with-cpp'
412-
for as_def in self.as_defines:
413-
if '=' in as_def:
414-
opts['as']['other'] += ' -Wa,--defsym ' + as_def
415-
else:
416-
opts['as']['other'] += ' -Wa,--defsym ' + as_def + '=1'
417426
opts['c']['defines'] = self.c_defines
418427
opts['cpp']['defines'] = self.cpp_defines
419428

@@ -447,7 +456,7 @@ def generate(self):
447456
'libraries': libraries,
448457
'board_name': self.BOARDS[self.target.upper()]['name'],
449458
'mcu_name': self.BOARDS[self.target.upper()]['mcuId'],
450-
'cpp_cmd': " ".join(self.toolchain.preproc),
459+
'cpp_cmd': preproc_cmd,
451460
'options': options,
452461
# id property of 'u' will generate new random identifier every time
453462
# when called.

tools/export/sw4stm32/cproject_common.tmpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</extensions>
1717
</storageModule>
1818
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
19-
<configuration artifactExtension="elf" artifactName="${ProjName}-{{cfg_id}}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.{{cfg_id}}" cleanCommand="rm -rf" description="" id="fr.ac6.managedbuild.config.gnu.cross.exe.{{cfg_id}}.{{opts['uid']['config']}}" name="{{opts['name']}}" parent="fr.ac6.managedbuild.config.gnu.cross.exe.{{cfg_id}}" postannouncebuildStep="Generating binary and Printing size information:" postbuildStep="arm-none-eabi-objcopy -O binary &quot;${BuildArtifactFileBaseName}.elf&quot; &quot;${ProjName}.bin&quot; &amp;&amp; arm-none-eabi-size -B &quot;${BuildArtifactFileName}&quot; &amp;&amp; make ldclean">
19+
<configuration artifactExtension="elf" artifactName="${ProjName}-{{cfg_id}}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.{{cfg_id}}" cleanCommand="rm -rf" description="" id="fr.ac6.managedbuild.config.gnu.cross.exe.{{cfg_id}}.{{opts['uid']['config']}}" name="{{opts['name']}}" parent="fr.ac6.managedbuild.config.gnu.cross.exe.{{cfg_id}}" postannouncebuildStep="Generating binary and Printing size information:" postbuildStep="arm-none-eabi-objcopy -O binary &quot;${BuildArtifactFileBaseName}.elf&quot; &quot;${ProjName}.bin&quot; &amp;&amp; arm-none-eabi-size -B &quot;${BuildArtifactFileName}&quot; &amp;&amp; make ldclean" preannouncebuildStep="Creating makefile.defs:" prebuildStep="echo &quot;export PREPROC_CMD = ${openstm32_compiler_path}/${compiler_prefix}cpp -E -P&quot; &gt; ${ProjDirPath}/makefile.defs">
2020
<folderInfo id="fr.ac6.managedbuild.config.gnu.cross.exe.{{cfg_id}}.{{opts['uid']['config']}}." name="/" resourcePath="">
2121
<toolChain id="fr.ac6.managedbuild.toolchain.gnu.cross.exe.{{cfg_id}}.{{u.id}}" name="Ac6 STM32 MCU GCC" superClass="fr.ac6.managedbuild.toolchain.gnu.cross.exe.{{cfg_id}}">
2222
<option id="fr.ac6.managedbuild.option.gnu.cross.mcu.{{u.id}}" name="Mcu" superClass="fr.ac6.managedbuild.option.gnu.cross.mcu" value="{{mcu_name}}" valueType="string"/>
@@ -39,7 +39,7 @@
3939
{% endif %}
4040
<option id="gnu.c.compiler.option.include.paths.{{u.id}}" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
4141
{% for path in include_paths %}
42-
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/{{path}}&quot;"/>
42+
<listOptionValue builtIn="false" value="&quot;{{path}}&quot;"/>
4343
{% endfor %}
4444
</option>
4545
<option id="gnu.c.compiler.option.preprocessor.def.symbols.{{u.id}}" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" useByScannerDiscovery="false" valueType="definedSymbols">
@@ -124,7 +124,7 @@
124124
{% endif %}
125125
<option id="gnu.cpp.compiler.option.include.paths.{{u.id}}" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
126126
{% for path in include_paths %}
127-
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/{{path}}&quot;"/>
127+
<listOptionValue builtIn="false" value="&quot;{{path}}&quot;"/>
128128
{% endfor %}
129129
</option>
130130
<option id="gnu.cpp.compiler.option.preprocessor.def.{{u.id}}" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" valueType="definedSymbols">
@@ -196,8 +196,8 @@
196196
</tool>
197197
<tool id="fr.ac6.managedbuild.tool.gnu.cross.cpp.linker.{{u.id}}" name="MCU G++ Linker" superClass="fr.ac6.managedbuild.tool.gnu.cross.cpp.linker">
198198
<option id="fr.ac6.managedbuild.tool.gnu.cross.cpp.linker.script.{{u.id}}" name="Linker Script (-T)" superClass="fr.ac6.managedbuild.tool.gnu.cross.cpp.linker.script" value="${ProjDirPath}/{{opts['name']}}/{{opts['ld']['script']}}" valueType="string"/>
199-
{% if opts['ld']['flags'] != '' %}
200-
<option id="gnu.cpp.link.option.flags.{{u.id}}" name="Linker flags" superClass="gnu.cpp.link.option.flags" value="{{ opts['ld']['flags']|join(' ') }}" valueType="string"/>
199+
{% if opts['ld']['flags'] != '' or opts['ld']['other'] != '' %}
200+
<option id="gnu.cpp.link.option.flags.{{u.id}}" name="Linker flags" superClass="gnu.cpp.link.option.flags" value="{{ opts['ld']['flags']|join(' ') }} {{opts['ld']['other']}}" valueType="string"/>
201201
{% endif %}
202202
<option id="gnu.cpp.link.option.userobjs.{{u.id}}" name="Other objects" superClass="gnu.cpp.link.option.userobjs" valueType="userObjs">
203203
{% for path in object_files %}
@@ -256,7 +256,7 @@
256256
<tool id="fr.ac6.managedbuild.tool.gnu.cross.assembler.{{u.id}}" name="MCU GCC Assembler" superClass="fr.ac6.managedbuild.tool.gnu.cross.assembler">
257257
<option id="gnu.both.asm.option.include.paths.{{u.id}}" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath">
258258
{% for path in include_paths %}
259-
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/{{path}}&quot;"/>
259+
<listOptionValue builtIn="false" value="&quot;{{path}}&quot;"/>
260260
{% endfor %}
261261
</option>
262262
<option id="gnu.both.asm.option.flags.{{u.id}}" superClass="gnu.both.asm.option.flags" useByScannerDiscovery="false" value="{{opts['as']['other']}}" valueType="string"/>

tools/export/sw4stm32/makefile.targets.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# DO NOT REMOVE! Generated by the SW4STM32 exporter from the mbed project.
22

3+
ifeq ($(strip $(PREPROC_CMD)),)
4+
PREPROC_CMD := {{cpp_cmd}}
5+
endif
6+
37
ldclean:
48
{% for config, opts in options.iteritems() %}
59
$(RM) {{opts['ld']['script']}}
610
{% endfor %}
711

812
{% for config, opts in options.iteritems() %}
913
{{opts['ld']['script']}}: ../{{ld_script}}
10-
{{cpp_cmd}} {{opts.ld.other}} $< -o $@
14+
$(PREPROC_CMD) {{opts.ld.other}} $< -o $@
1115

1216
{{name}}-{{config}}.elf: {{opts['ld']['script']}}
1317

0 commit comments

Comments
 (0)