bugmake - Bugs: bug #62162, patsubst not working in...

 
 

bug #62162: patsubst not working in prerequisites under .SECONDEXPANSION

Submitter:  None
Submitted:  Thu 10 Mar 2022 10:06:34 AM UTC
   
 
Severity:  3 - Normal Item Group:  Bug
Status:  Not A Bug Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  4.3 Operating System:  POSIX-Based
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 11 Mar 2022 06:22:39 AM UTC, comment #5: 

Oh, I got it now, % expands as a stem of static pattern rule, and not being used by patsubst.

The issue is resolved.

Thanks,
Mikhail

Mikhail <mikpom>
Fri 11 Mar 2022 03:22:07 AM UTC, comment #4: 

Thanks, $$(percent) trick makes the job done.

However what is happening is still obscure. For example, here patsubst does everything correctly


lib1_SRCS := main.c try.c test.c
lib2_SRCS := lib.c api.c

.SECONDEXPANSION:
lib1 lib2: $$(patsubst %.c,%.o,$$($$@_SRCS))


and lib1  depends on main.o, try.o and test.o.

Reworking it in static pattern rule fashion results in prerequisites main.c, try.c and test.c for lib1, i.e. patsubst does nothing.


lib1_SRCS := main.c try.c test.c
lib2_SRCS := lib.c api.c

.SECONDEXPANSION:
lib1 lib2: lib% : $$(patsubst %.c,%.o,$$(lib$$*_SRCS))


Mikhail <mikpom>
Thu 10 Mar 2022 06:28:16 PM UTC, comment #3: 

A typo, ofcourse should be $$(percent)



percent:=%
$(files) : %.ext : $$(patsubst r$$(percent),$$(percent),$$(lastword $$(subst .stem., ,$$*)))-prereq


Dmitry Goncharov <dgoncharov>
Thu 10 Mar 2022 06:26:43 PM UTC, comment #2: 

You can store % in a variable


percent:=%
$(files) : %.ext : $$(patsubst r$(percent),$(percent),$$(lastword $$(subst .stem., ,$$*)))-prereq


Dmitry Goncharov <dgoncharov>
Thu 10 Mar 2022 11:04:39 AM UTC, comment #1: 

The replacement of % by the stem happens before the secondary expansion is performed.

Andreas Schwab <schwab>
Thu 10 Mar 2022 10:06:34 AM UTC, original submission:  

For some reason `patsubst` function doesn't do its work in the following snippet.

```
prereq_files = 1-prereq 2-prereq
all: prefix.stem.r1.ext

files = $(foreach file,$(prereq_files),prefix.stem.r$(patsubst %-prereq,%,$(file)).ext)
# Files is prefix.stem.r1.ext prefix.stem.r2.ext
$(files) : %.ext : $$(patsubst r%,%,$$(lastword $$(subst .stem., ,$$*)))-prereq
cat $< > $@
```

I get `make: * No rule to make target 'r1-prereq'` error, when trying to make `prefix.stem.r1.ext` which by design should depend on `1-prereq`. patsubst doesn't do its job and makes it depend on r1-prereq which is non-existent. Weirdly if I just use $(subst r,,<...>) everything is fine.

Any ideas?
-Mikhail

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #52975:  Makefile added by None (253B - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by psmith (Updated the item)
  • -email is unavailable- added by mikpom (Posted a comment)
  • -email is unavailable- added by dgoncharov (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-04-23 psmith StatusNone Not A Bug
        Open/ClosedOpen Closed
    2022-03-10 None Attached File- Added Makefile, #52975

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code