Makefile strange variable substitution
My Makefile
looks like this:
%.foo: %.bar
cp $< $@
test: *.foo
echo *.foo
I have 2 files in the directory: a.bar
and b.bar
. When I run make test
it outputs:
cp b.bar *.foo
echo *.foo
*.foo
It also creates a file *.foo
in the current directory.
I am actually expecting to see this:
cp a.bar a.foo
cp b.bar b.foo
echo *.foo
a.foo b.foo
And also creating a.foo
and b.foo
. How to achieve that?
make
add a comment |
My Makefile
looks like this:
%.foo: %.bar
cp $< $@
test: *.foo
echo *.foo
I have 2 files in the directory: a.bar
and b.bar
. When I run make test
it outputs:
cp b.bar *.foo
echo *.foo
*.foo
It also creates a file *.foo
in the current directory.
I am actually expecting to see this:
cp a.bar a.foo
cp b.bar b.foo
echo *.foo
a.foo b.foo
And also creating a.foo
and b.foo
. How to achieve that?
make
add a comment |
My Makefile
looks like this:
%.foo: %.bar
cp $< $@
test: *.foo
echo *.foo
I have 2 files in the directory: a.bar
and b.bar
. When I run make test
it outputs:
cp b.bar *.foo
echo *.foo
*.foo
It also creates a file *.foo
in the current directory.
I am actually expecting to see this:
cp a.bar a.foo
cp b.bar b.foo
echo *.foo
a.foo b.foo
And also creating a.foo
and b.foo
. How to achieve that?
make
My Makefile
looks like this:
%.foo: %.bar
cp $< $@
test: *.foo
echo *.foo
I have 2 files in the directory: a.bar
and b.bar
. When I run make test
it outputs:
cp b.bar *.foo
echo *.foo
*.foo
It also creates a file *.foo
in the current directory.
I am actually expecting to see this:
cp a.bar a.foo
cp b.bar b.foo
echo *.foo
a.foo b.foo
And also creating a.foo
and b.foo
. How to achieve that?
make
make
asked 2 hours ago
Martin ŽdilaMartin Ždila
155115
155115
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
In this case you need to handle wildcards explicitly, with the wildcard
function (at least in GNU Make):
%.foo: %.bar
cp $< $@
foos = $(patsubst %.bar,%.foo,$(wildcard *.bar))
test: $(foos)
echo $(foos)
$(wildcard *.bar)
expands to all the files ending in .bar
, the patsubst
call replaces .bar
with .foo
, and all the targets are then processed as you’d expect.
add a comment |
There is no *.foo file to begin with. So what make does is look for how to make *.foo
literaly and the first rule does this. Make expands $<
to the first pre-requisite (*.bar
, which happens to be b.bar
in this case). Make then runs the shell command cp b.bar *.foo
. Since there is no *.foo, shell expands it to cp b.bar *.foo
literally. That's how you get a *.foo
file.
You can verify this by running make -d test
.
You can get the effect you want by generating the list of targets based on list of prerequisites.
TARGETS = $(patsubst %.bar,%.foo,$(wildcard *.bar))
%.foo: %.bar
@cp $< $@
test: $(TARGETS)
@echo $(TARGETS)
echo *.foo
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2funix.stackexchange.com%2fquestions%2f505735%2fmakefile-strange-variable-substitution%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In this case you need to handle wildcards explicitly, with the wildcard
function (at least in GNU Make):
%.foo: %.bar
cp $< $@
foos = $(patsubst %.bar,%.foo,$(wildcard *.bar))
test: $(foos)
echo $(foos)
$(wildcard *.bar)
expands to all the files ending in .bar
, the patsubst
call replaces .bar
with .foo
, and all the targets are then processed as you’d expect.
add a comment |
In this case you need to handle wildcards explicitly, with the wildcard
function (at least in GNU Make):
%.foo: %.bar
cp $< $@
foos = $(patsubst %.bar,%.foo,$(wildcard *.bar))
test: $(foos)
echo $(foos)
$(wildcard *.bar)
expands to all the files ending in .bar
, the patsubst
call replaces .bar
with .foo
, and all the targets are then processed as you’d expect.
add a comment |
In this case you need to handle wildcards explicitly, with the wildcard
function (at least in GNU Make):
%.foo: %.bar
cp $< $@
foos = $(patsubst %.bar,%.foo,$(wildcard *.bar))
test: $(foos)
echo $(foos)
$(wildcard *.bar)
expands to all the files ending in .bar
, the patsubst
call replaces .bar
with .foo
, and all the targets are then processed as you’d expect.
In this case you need to handle wildcards explicitly, with the wildcard
function (at least in GNU Make):
%.foo: %.bar
cp $< $@
foos = $(patsubst %.bar,%.foo,$(wildcard *.bar))
test: $(foos)
echo $(foos)
$(wildcard *.bar)
expands to all the files ending in .bar
, the patsubst
call replaces .bar
with .foo
, and all the targets are then processed as you’d expect.
answered 2 hours ago
Stephen KittStephen Kitt
175k24400478
175k24400478
add a comment |
add a comment |
There is no *.foo file to begin with. So what make does is look for how to make *.foo
literaly and the first rule does this. Make expands $<
to the first pre-requisite (*.bar
, which happens to be b.bar
in this case). Make then runs the shell command cp b.bar *.foo
. Since there is no *.foo, shell expands it to cp b.bar *.foo
literally. That's how you get a *.foo
file.
You can verify this by running make -d test
.
You can get the effect you want by generating the list of targets based on list of prerequisites.
TARGETS = $(patsubst %.bar,%.foo,$(wildcard *.bar))
%.foo: %.bar
@cp $< $@
test: $(TARGETS)
@echo $(TARGETS)
echo *.foo
add a comment |
There is no *.foo file to begin with. So what make does is look for how to make *.foo
literaly and the first rule does this. Make expands $<
to the first pre-requisite (*.bar
, which happens to be b.bar
in this case). Make then runs the shell command cp b.bar *.foo
. Since there is no *.foo, shell expands it to cp b.bar *.foo
literally. That's how you get a *.foo
file.
You can verify this by running make -d test
.
You can get the effect you want by generating the list of targets based on list of prerequisites.
TARGETS = $(patsubst %.bar,%.foo,$(wildcard *.bar))
%.foo: %.bar
@cp $< $@
test: $(TARGETS)
@echo $(TARGETS)
echo *.foo
add a comment |
There is no *.foo file to begin with. So what make does is look for how to make *.foo
literaly and the first rule does this. Make expands $<
to the first pre-requisite (*.bar
, which happens to be b.bar
in this case). Make then runs the shell command cp b.bar *.foo
. Since there is no *.foo, shell expands it to cp b.bar *.foo
literally. That's how you get a *.foo
file.
You can verify this by running make -d test
.
You can get the effect you want by generating the list of targets based on list of prerequisites.
TARGETS = $(patsubst %.bar,%.foo,$(wildcard *.bar))
%.foo: %.bar
@cp $< $@
test: $(TARGETS)
@echo $(TARGETS)
echo *.foo
There is no *.foo file to begin with. So what make does is look for how to make *.foo
literaly and the first rule does this. Make expands $<
to the first pre-requisite (*.bar
, which happens to be b.bar
in this case). Make then runs the shell command cp b.bar *.foo
. Since there is no *.foo, shell expands it to cp b.bar *.foo
literally. That's how you get a *.foo
file.
You can verify this by running make -d test
.
You can get the effect you want by generating the list of targets based on list of prerequisites.
TARGETS = $(patsubst %.bar,%.foo,$(wildcard *.bar))
%.foo: %.bar
@cp $< $@
test: $(TARGETS)
@echo $(TARGETS)
echo *.foo
answered 2 hours ago
Satya MishraSatya Mishra
35615
35615
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2funix.stackexchange.com%2fquestions%2f505735%2fmakefile-strange-variable-substitution%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