I'd like to generate two output words for each input word, that they be consecutive, and apply patsubst to them.
A non-working prototype of what I want:
$(patsubst %.o,%.a.o %.so.o,$(OBJ))
The second apearance of % is not substituted, and instead a plain % appears.
A working version that does not give the desired order:
$(patsubst %.o,%.a.o,$(OBJ)) $(patsubst %.o,%.so.o,$(OBJ))
Example:
Input:
foo.o bar.o
Desired output:
foo.a.o foo.so.o bar.a.o bar.so.o
How can I get the desired output?
The join make function takes two word lists and concatenate them word by word. Not exactly what you want because there would be no space between foo.a.o and foo.so.o, but not far from it.
Assuming you know for sure that some string will never be part of your file names (e.g. !!!) you can combine substitution references (or the equivalent patsubst), join and subst:
$(subst !!!, ,$(join $(OBJ:o=a.o!!!),$(OBJ:o=so.o)))
Or, even simpler, if you know for sure that .a.o cannot be part of your files' basename:
$(subst .a.o,.a.o ,$(join $(OBJ:o=a.o),$(OBJ:o=so.o)))
Two nested foreach loop could be solve your problem. One for the files and the other one for extensions. The below code should solve your problem.
OBJS = foo.o bar.o
EXTS = a.o so.o
OUT = $(foreach file, ${OBJS}, \
$(foreach ext, ${EXTS}, \
$(patsubst %.o, %.${ext}, ${file})))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With