aboutsummaryrefslogtreecommitdiff
path: root/yapymake/makefile/__init__.py
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-03-25 21:21:07 -0600
committerMelody Horn <melody@boringcactus.com>2021-03-25 21:21:07 -0600
commit383c904c0f2667e8afabc76568a5e8376e617696 (patch)
treeef3e292a688ee43cbbeab222c58feafc9a13aff2 /yapymake/makefile/__init__.py
parent40c9e2383d2e989cf5e51f6f855b869c7235f694 (diff)
downloadyapymake-383c904c0f2667e8afabc76568a5e8376e617696.tar.gz
yapymake-383c904c0f2667e8afabc76568a5e8376e617696.zip
allow GNUish macro assignments (`?=`, `+=`)
Diffstat (limited to 'yapymake/makefile/__init__.py')
-rw-r--r--yapymake/makefile/__init__.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/yapymake/makefile/__init__.py b/yapymake/makefile/__init__.py
index 52e2262..b5f96f1 100644
--- a/yapymake/makefile/__init__.py
+++ b/yapymake/makefile/__init__.py
@@ -196,23 +196,50 @@ class Makefile:
comment_split = value.split_once('#')
if comment_split is not None:
value, _ = comment_split
+ # GNU make allows for weird assignment operators
+ expand_value = False
+ skip_if_defined = False
+ append = False
+ if name_tokens.endswith('::'):
+ self._warn('warning: non-POSIXful `::=` in macro')
+ name_tokens.rstrip(':')
+ expand_value = True
+ elif name_tokens.endswith(':'):
+ self._warn('warning: non-POSIXful `:=` in macro')
+ name_tokens.rstrip(':')
+ expand_value = True
+ elif name_tokens.endswith('?'):
+ self._warn('warning: non-POSIXful `?=` in macro')
+ name_tokens.rstrip('?')
+ skip_if_defined = True
+ elif name_tokens.endswith('+'):
+ self._warn('warning: non-POSIXful `+=` in macro')
+ name_tokens.rstrip('+')
+ append = True
# > Any <blank> characters immediately before or after the <equals-sign> shall be ignored.
name_tokens.rstrip()
value.lstrip()
# > Macros in the string before the <equals-sign> in a macro definition shall be evaluated when the
# > macro assignment is made.
name = self.expand_macros(name_tokens)
+ if expand_value:
+ value = TokenString.text(self.expand_macros(value))
# > Macros defined in the makefile(s) shall override macro definitions that occur before them in the
# > makefile(s) and macro definitions from source 4. If the -e option is not specified, macros defined
# > in the makefile(s) shall override macro definitions from source 3. Macros defined in the makefile(s)
# > shall not override macro definitions from source 1 or source 2.
if name in self._macros:
+ if skip_if_defined:
+ continue
source, _ = self._macros[name]
inviolate_sources = [MacroSource.CommandLine, MacroSource.MAKEFLAGS]
if self.args.environment_overrides:
inviolate_sources.append(MacroSource.Environment)
if any(x is source for x in inviolate_sources):
continue
+ if append and name in self._macros:
+ _, old_value = self._macros[name]
+ value = old_value.concat(TokenString.text(' ')).concat(value)
self._macros[name] = (MacroSource.File, value)
def expand_macros(self, text: TokenString, current_target: Optional['Target'] = None) -> str: