Skip to content

Commit

Permalink
Merge pull request #7 from linuxlizard/dpoole/issue-6-patsubst-shortcut
Browse files Browse the repository at this point in the history
fix issue 6 patsubst shortcut
  • Loading branch information
linuxlizard committed Jun 27, 2023
2 parents 7ce1a6c + 591c2c4 commit 1e995ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pymake/symtablemk.py
Expand Up @@ -323,14 +323,15 @@ def _parse_abbrev_patsubst(self, key):
def _eval_abbrev_patsubst(self, key):
# allow exception(s) to propagate
varname, pat1, pat2 = self._parse_abbrev_patsubst(key)
# logger.debug("abbrev varname=%r pat1=%r pat2=%4", varname, pat1, pat2)

pat1_len = len(pat1)
def maybe_replace(s,pat1,pat2):
if s.endswith(pat1):
return s[:-pat1_len] + pat2
return s
value = self.fetch(varname)
new_value = " ".join([maybe_replace(s,pat1,pat2) for s in value.split()])
if pat1_len == 0:
# pat1 empty so it's a simple append operation
return " ".join([s+pat2 for s in value.split()])

new_value = " ".join([s[:-pat1_len] + pat2 if s.endswith(pat1) else s for s in value.split()])
return new_value

def fetch(self, key, pos=None):
Expand Down
16 changes: 15 additions & 1 deletion tests/patsubst.mk
@@ -1,6 +1,9 @@
SRC=hello.c there.c all.c you.c rabbits.c
OBJ=$(patsubst %.c,%.o,$(SRC))

$(info OBJ=$(OBJ))
OBJ=$(SRC:.c=.o)
$(info OBJ=$(OBJ))
OBJ=$(SRC:.rs=.o)
$(info OBJ=$(OBJ))

$(info emptyc=$(patsubst %.c,%.o,.c .o))
Expand Down Expand Up @@ -106,5 +109,16 @@ $(info corner=$(patsubst [],qqq,[] [] [] [])) # tabs
$(info corner=$(patsubst c,h,hello.c there.c all.c you.c rabbits.c))
$(info corner=$(patsubst c, ,hello.c there.c all.c you.c rabbits.c))

SUBS=gpl usr lib modules
$(info clean-rule=$(SUBS:=-clean))

# whitespace is removed
SUBS= gpl usr lib modules
$(info clean-rule=$(SUBS:=-clean))

EXE:=cc.exe ld.exe as.exe ar.exe command.com
$(info EXE=$(EXE:.exe=))


@:;@:

0 comments on commit 1e995ea

Please sign in to comment.