From 58180dbafe987c0482b160cc2026b8562ecf5827 Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Thu, 2 Aug 2018 09:09:07 -0500 Subject: [PATCH] Use shell escaping instead of quoting OSs don't agree on what the quote chars mean --- tools/export/makefile/Makefile.tmpl | 6 +++--- tools/export/makefile/__init__.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/export/makefile/Makefile.tmpl b/tools/export/makefile/Makefile.tmpl index 3d2c722cb6..83a7f2b039 100644 --- a/tools/export/makefile/Makefile.tmpl +++ b/tools/export/makefile/Makefile.tmpl @@ -75,11 +75,11 @@ SREC_CAT = srec_cat {%- endif %} {%- block additional_executables -%}{%- endblock %} -{% for flag in c_flags %}C_FLAGS += "{{flag}}" +{% for flag in c_flags %}C_FLAGS += {{shell_escape(flag)}} {% endfor %} -{% for flag in cxx_flags %}CXX_FLAGS += "{{flag}}" +{% for flag in cxx_flags %}CXX_FLAGS += {{shell_escape(flag)}} {% endfor %} -{% for flag in asm_flags %}ASM_FLAGS += "{{flag}}" +{% for flag in asm_flags %}ASM_FLAGS += {{shell_escape(flag)}} {% endfor %} LD_FLAGS :={%- block ld_flags -%} {{ld_flags|join(" ")}} {% endblock %} diff --git a/tools/export/makefile/__init__.py b/tools/export/makefile/__init__.py index 91d8afc11f..e812e2be49 100644 --- a/tools/export/makefile/__init__.py +++ b/tools/export/makefile/__init__.py @@ -29,6 +29,15 @@ from tools.export.exporters import Exporter, apply_supported_whitelist from tools.utils import NotSupportedException from tools.targets import TARGET_MAP +SHELL_ESCAPE_TABLE = { + "(": "\(", + ")": "\)", +} + + +def shell_escape(string): + return "".join(SHELL_ESCAPE_TABLE.get(char, char) for char in string) + class Makefile(Exporter): """Generic Makefile template that mimics the behavior of the python build @@ -97,6 +106,7 @@ class Makefile(Exporter): 'link_script_option': self.LINK_SCRIPT_OPTION, 'user_library_flag': self.USER_LIBRARY_FLAG, 'needs_asm_preproc': self.PREPROCESS_ASM, + 'shell_escape': shell_escape, } if hasattr(self.toolchain, "preproc"):