From b387cba85947db7101726a9f743f272d6dcea269 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Thu, 25 Mar 2021 20:01:56 -0600 Subject: allow (but lint for) inferring commands on explicit targets --- yapymake/makefile/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'yapymake/makefile/__init__.py') diff --git a/yapymake/makefile/__init__.py b/yapymake/makefile/__init__.py index 0290e9f..4617047 100644 --- a/yapymake/makefile/__init__.py +++ b/yapymake/makefile/__init__.py @@ -254,7 +254,9 @@ class Makefile: def target(self, name: str) -> 'Target': # TODO implement .DEFAULT - if name not in self._targets: + # it's not POSIXful, but GNU make will use inference rules for defined targets with no commands, + follow_gnu = True # TODO implement .POSIX and scope it properly + if name not in self._targets or (follow_gnu and len(self._targets[name].commands) == 0): # > When no target rule is found to update a target, the inference rules shall be checked. The suffix of # > the target (.s1) to be built... suffix = PurePath(name).suffix @@ -269,6 +271,10 @@ class Makefile: # > whose prerequisite file ($*.s2) exists. prerequisite_path = PurePath(name).with_suffix(rule.s2) if ImpurePath(prerequisite_path).exists(): + if name in self._targets: + # we got here by following GNU + print('warning: non-POSIX use of inference rule', f'{rule.s1}{rule.s2}', + 'on explicit target', name) self._targets[name] = Target(name, [str(prerequisite_path)], rule.commands) break if name not in self._targets: -- cgit v1.2.3