remove patterned prefix from list in gnu make
up vote
0
down vote
favorite
If I have a list of files:
files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
Is there any way of removing everything up to the last underscore from the list to get foo1.c foo2.c bar1.c bar2.c
?
I was looking into using patsubst
, but I would need two%
's -- one for the first part to be ignored, and one for the last part to be kept.
makefile gnu-make
add a comment |
up vote
0
down vote
favorite
If I have a list of files:
files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
Is there any way of removing everything up to the last underscore from the list to get foo1.c foo2.c bar1.c bar2.c
?
I was looking into using patsubst
, but I would need two%
's -- one for the first part to be ignored, and one for the last part to be kept.
makefile gnu-make
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
If I have a list of files:
files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
Is there any way of removing everything up to the last underscore from the list to get foo1.c foo2.c bar1.c bar2.c
?
I was looking into using patsubst
, but I would need two%
's -- one for the first part to be ignored, and one for the last part to be kept.
makefile gnu-make
If I have a list of files:
files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
Is there any way of removing everything up to the last underscore from the list to get foo1.c foo2.c bar1.c bar2.c
?
I was looking into using patsubst
, but I would need two%
's -- one for the first part to be ignored, and one for the last part to be kept.
makefile gnu-make
makefile gnu-make
asked Nov 9 at 20:03
HardcoreHenry
1,208318
1,208318
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
It can be done but it's a little gross. You want something like this:
final := $(foreach F,$(files),$(word $(words $(subst _, ,$F)),$(subst _, ,$F)))
This says, for each element in files
we convert the _
to a space, now we can use our per-word functions to manipulate it: extract the last word in the list of words.
ETA
ReAl points out below that this can be simplified using lastword
:
final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
– HardcoreHenry
Nov 9 at 22:13
2
or evenfinal := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
– ReAl
Nov 9 at 22:13
Oh yeah... hah!! Forgot about lastword :p :)
– MadScientist
Nov 9 at 22:19
add a comment |
up vote
2
down vote
As I see it you are using the underscore as separating character between hierarchical names. GNUmake is well equipped to work with such a scheme if the character is /
: file name functions.
So your example should simply boil down to
$(notdir $(subst _,/,$(files))
add a comment |
up vote
0
down vote
Use the external program — sed
— and enjoy all its power
files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
f := `echo $(files) | sed -e "s/[[:alnum:]]*_//g"`
all:
echo $(f)
Nah. Always prefer make mechanisms over the shell.
– bobbogo
Nov 12 at 10:17
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
It can be done but it's a little gross. You want something like this:
final := $(foreach F,$(files),$(word $(words $(subst _, ,$F)),$(subst _, ,$F)))
This says, for each element in files
we convert the _
to a space, now we can use our per-word functions to manipulate it: extract the last word in the list of words.
ETA
ReAl points out below that this can be simplified using lastword
:
final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
– HardcoreHenry
Nov 9 at 22:13
2
or evenfinal := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
– ReAl
Nov 9 at 22:13
Oh yeah... hah!! Forgot about lastword :p :)
– MadScientist
Nov 9 at 22:19
add a comment |
up vote
2
down vote
accepted
It can be done but it's a little gross. You want something like this:
final := $(foreach F,$(files),$(word $(words $(subst _, ,$F)),$(subst _, ,$F)))
This says, for each element in files
we convert the _
to a space, now we can use our per-word functions to manipulate it: extract the last word in the list of words.
ETA
ReAl points out below that this can be simplified using lastword
:
final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
– HardcoreHenry
Nov 9 at 22:13
2
or evenfinal := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
– ReAl
Nov 9 at 22:13
Oh yeah... hah!! Forgot about lastword :p :)
– MadScientist
Nov 9 at 22:19
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
It can be done but it's a little gross. You want something like this:
final := $(foreach F,$(files),$(word $(words $(subst _, ,$F)),$(subst _, ,$F)))
This says, for each element in files
we convert the _
to a space, now we can use our per-word functions to manipulate it: extract the last word in the list of words.
ETA
ReAl points out below that this can be simplified using lastword
:
final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
It can be done but it's a little gross. You want something like this:
final := $(foreach F,$(files),$(word $(words $(subst _, ,$F)),$(subst _, ,$F)))
This says, for each element in files
we convert the _
to a space, now we can use our per-word functions to manipulate it: extract the last word in the list of words.
ETA
ReAl points out below that this can be simplified using lastword
:
final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
edited Nov 10 at 17:27
answered Nov 9 at 22:06
MadScientist
44.7k44764
44.7k44764
a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
– HardcoreHenry
Nov 9 at 22:13
2
or evenfinal := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
– ReAl
Nov 9 at 22:13
Oh yeah... hah!! Forgot about lastword :p :)
– MadScientist
Nov 9 at 22:19
add a comment |
a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
– HardcoreHenry
Nov 9 at 22:13
2
or evenfinal := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
– ReAl
Nov 9 at 22:13
Oh yeah... hah!! Forgot about lastword :p :)
– MadScientist
Nov 9 at 22:19
a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
– HardcoreHenry
Nov 9 at 22:13
a little gross?? I feel sorry for the guys who have to maintain it. :) It does what I need though. Thanks.
– HardcoreHenry
Nov 9 at 22:13
2
2
or even
final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
– ReAl
Nov 9 at 22:13
or even
final := $(foreach F,$(files),$(lastword $(subst _, ,$F)))
– ReAl
Nov 9 at 22:13
Oh yeah... hah!! Forgot about lastword :p :)
– MadScientist
Nov 9 at 22:19
Oh yeah... hah!! Forgot about lastword :p :)
– MadScientist
Nov 9 at 22:19
add a comment |
up vote
2
down vote
As I see it you are using the underscore as separating character between hierarchical names. GNUmake is well equipped to work with such a scheme if the character is /
: file name functions.
So your example should simply boil down to
$(notdir $(subst _,/,$(files))
add a comment |
up vote
2
down vote
As I see it you are using the underscore as separating character between hierarchical names. GNUmake is well equipped to work with such a scheme if the character is /
: file name functions.
So your example should simply boil down to
$(notdir $(subst _,/,$(files))
add a comment |
up vote
2
down vote
up vote
2
down vote
As I see it you are using the underscore as separating character between hierarchical names. GNUmake is well equipped to work with such a scheme if the character is /
: file name functions.
So your example should simply boil down to
$(notdir $(subst _,/,$(files))
As I see it you are using the underscore as separating character between hierarchical names. GNUmake is well equipped to work with such a scheme if the character is /
: file name functions.
So your example should simply boil down to
$(notdir $(subst _,/,$(files))
answered Nov 11 at 22:23
Vroomfondel
1,104719
1,104719
add a comment |
add a comment |
up vote
0
down vote
Use the external program — sed
— and enjoy all its power
files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
f := `echo $(files) | sed -e "s/[[:alnum:]]*_//g"`
all:
echo $(f)
Nah. Always prefer make mechanisms over the shell.
– bobbogo
Nov 12 at 10:17
add a comment |
up vote
0
down vote
Use the external program — sed
— and enjoy all its power
files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
f := `echo $(files) | sed -e "s/[[:alnum:]]*_//g"`
all:
echo $(f)
Nah. Always prefer make mechanisms over the shell.
– bobbogo
Nov 12 at 10:17
add a comment |
up vote
0
down vote
up vote
0
down vote
Use the external program — sed
— and enjoy all its power
files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
f := `echo $(files) | sed -e "s/[[:alnum:]]*_//g"`
all:
echo $(f)
Use the external program — sed
— and enjoy all its power
files := xx_foo1.c yy_foo2.c zz_bar1.c aa_bb_bar2.c
f := `echo $(files) | sed -e "s/[[:alnum:]]*_//g"`
all:
echo $(f)
answered Nov 9 at 21:51
ReAl
548215
548215
Nah. Always prefer make mechanisms over the shell.
– bobbogo
Nov 12 at 10:17
add a comment |
Nah. Always prefer make mechanisms over the shell.
– bobbogo
Nov 12 at 10:17
Nah. Always prefer make mechanisms over the shell.
– bobbogo
Nov 12 at 10:17
Nah. Always prefer make mechanisms over the shell.
– bobbogo
Nov 12 at 10:17
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232595%2fremove-patterned-prefix-from-list-in-gnu-make%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown