Makefile does not find target











up vote
0
down vote

favorite












I have the following Makefile, but it does not work. When I call



make html


I get a



make: *** No rule to make target `docs/index.html', needed by `html'.  Stop.


error, even though I think I have defined it.



SRCDIR = source
OUTDIR = docs

RMD = $(wildcard $(SRCDIR)/*.Rmd)

TMP = $(RMD:.Rmd=.html)
HTML = ${subst $(SRCDIR),$(OUTDIR),$(TMP)}


test:
echo $(RMD)
echo $(TMP)
echo $(HTML)


all: clean update html

html: $(HTML)

%.html: %.Rmd
echo $(HTML)
@Rscript -e "rmarkdown::render('$<', output_format = 'prettydoc::html_pretty', output_dir = './$(OUTDIR)/')"

update:
@Rscript -e "devtools::load_all(here::here()); microcosmScheme:::updateFromGoogleSheet(token = './source/googlesheets_token.rds')"


## from https://stackoverflow.com/a/26339924/632423
list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs

.PHONY: update clean cleanhtml all list


The variables seem to be correct:



15:21 $ make test
echo source/index.Rmd
source/index.Rmd
echo source/index.html
source/index.html
echo docs/index.html
docs/index.html


If I change it as follow it works, but the target points to the SRCDIR, but I want it to point to the OUTDIR:



RMD = $(wildcard $(SRCDIR)/*.Rmd)

HTML = $(RMD:.Rmd=.html)
# HTML = ${subst $(SRCDIR),$(OUTDIR),$(TMP)}


I am sure it is one small thing...










share|improve this question
























  • Is there a reason why you did not declare help as phony?
    – Renaud Pacalet
    Nov 21 at 17:12










  • Do i have a ‚help‘ target?
    – Rainer
    Nov 21 at 17:50










  • Sorry, I meant html (I too frequently have a phony help target as my default goal).
    – Renaud Pacalet
    Nov 21 at 18:29










  • That is exactly what I do not want. But thanks for pointing the=at option out.
    – Rainer
    Nov 22 at 9:06















up vote
0
down vote

favorite












I have the following Makefile, but it does not work. When I call



make html


I get a



make: *** No rule to make target `docs/index.html', needed by `html'.  Stop.


error, even though I think I have defined it.



SRCDIR = source
OUTDIR = docs

RMD = $(wildcard $(SRCDIR)/*.Rmd)

TMP = $(RMD:.Rmd=.html)
HTML = ${subst $(SRCDIR),$(OUTDIR),$(TMP)}


test:
echo $(RMD)
echo $(TMP)
echo $(HTML)


all: clean update html

html: $(HTML)

%.html: %.Rmd
echo $(HTML)
@Rscript -e "rmarkdown::render('$<', output_format = 'prettydoc::html_pretty', output_dir = './$(OUTDIR)/')"

update:
@Rscript -e "devtools::load_all(here::here()); microcosmScheme:::updateFromGoogleSheet(token = './source/googlesheets_token.rds')"


## from https://stackoverflow.com/a/26339924/632423
list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs

.PHONY: update clean cleanhtml all list


The variables seem to be correct:



15:21 $ make test
echo source/index.Rmd
source/index.Rmd
echo source/index.html
source/index.html
echo docs/index.html
docs/index.html


If I change it as follow it works, but the target points to the SRCDIR, but I want it to point to the OUTDIR:



RMD = $(wildcard $(SRCDIR)/*.Rmd)

HTML = $(RMD:.Rmd=.html)
# HTML = ${subst $(SRCDIR),$(OUTDIR),$(TMP)}


I am sure it is one small thing...










share|improve this question
























  • Is there a reason why you did not declare help as phony?
    – Renaud Pacalet
    Nov 21 at 17:12










  • Do i have a ‚help‘ target?
    – Rainer
    Nov 21 at 17:50










  • Sorry, I meant html (I too frequently have a phony help target as my default goal).
    – Renaud Pacalet
    Nov 21 at 18:29










  • That is exactly what I do not want. But thanks for pointing the=at option out.
    – Rainer
    Nov 22 at 9:06













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have the following Makefile, but it does not work. When I call



make html


I get a



make: *** No rule to make target `docs/index.html', needed by `html'.  Stop.


error, even though I think I have defined it.



SRCDIR = source
OUTDIR = docs

RMD = $(wildcard $(SRCDIR)/*.Rmd)

TMP = $(RMD:.Rmd=.html)
HTML = ${subst $(SRCDIR),$(OUTDIR),$(TMP)}


test:
echo $(RMD)
echo $(TMP)
echo $(HTML)


all: clean update html

html: $(HTML)

%.html: %.Rmd
echo $(HTML)
@Rscript -e "rmarkdown::render('$<', output_format = 'prettydoc::html_pretty', output_dir = './$(OUTDIR)/')"

update:
@Rscript -e "devtools::load_all(here::here()); microcosmScheme:::updateFromGoogleSheet(token = './source/googlesheets_token.rds')"


## from https://stackoverflow.com/a/26339924/632423
list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs

.PHONY: update clean cleanhtml all list


The variables seem to be correct:



15:21 $ make test
echo source/index.Rmd
source/index.Rmd
echo source/index.html
source/index.html
echo docs/index.html
docs/index.html


If I change it as follow it works, but the target points to the SRCDIR, but I want it to point to the OUTDIR:



RMD = $(wildcard $(SRCDIR)/*.Rmd)

HTML = $(RMD:.Rmd=.html)
# HTML = ${subst $(SRCDIR),$(OUTDIR),$(TMP)}


I am sure it is one small thing...










share|improve this question















I have the following Makefile, but it does not work. When I call



make html


I get a



make: *** No rule to make target `docs/index.html', needed by `html'.  Stop.


error, even though I think I have defined it.



SRCDIR = source
OUTDIR = docs

RMD = $(wildcard $(SRCDIR)/*.Rmd)

TMP = $(RMD:.Rmd=.html)
HTML = ${subst $(SRCDIR),$(OUTDIR),$(TMP)}


test:
echo $(RMD)
echo $(TMP)
echo $(HTML)


all: clean update html

html: $(HTML)

%.html: %.Rmd
echo $(HTML)
@Rscript -e "rmarkdown::render('$<', output_format = 'prettydoc::html_pretty', output_dir = './$(OUTDIR)/')"

update:
@Rscript -e "devtools::load_all(here::here()); microcosmScheme:::updateFromGoogleSheet(token = './source/googlesheets_token.rds')"


## from https://stackoverflow.com/a/26339924/632423
list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs

.PHONY: update clean cleanhtml all list


The variables seem to be correct:



15:21 $ make test
echo source/index.Rmd
source/index.Rmd
echo source/index.html
source/index.html
echo docs/index.html
docs/index.html


If I change it as follow it works, but the target points to the SRCDIR, but I want it to point to the OUTDIR:



RMD = $(wildcard $(SRCDIR)/*.Rmd)

HTML = $(RMD:.Rmd=.html)
# HTML = ${subst $(SRCDIR),$(OUTDIR),$(TMP)}


I am sure it is one small thing...







makefile directory target






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 16:38









Mike Kinghan

29.4k762107




29.4k762107










asked Nov 21 at 14:24









Rainer

5,36811216




5,36811216












  • Is there a reason why you did not declare help as phony?
    – Renaud Pacalet
    Nov 21 at 17:12










  • Do i have a ‚help‘ target?
    – Rainer
    Nov 21 at 17:50










  • Sorry, I meant html (I too frequently have a phony help target as my default goal).
    – Renaud Pacalet
    Nov 21 at 18:29










  • That is exactly what I do not want. But thanks for pointing the=at option out.
    – Rainer
    Nov 22 at 9:06


















  • Is there a reason why you did not declare help as phony?
    – Renaud Pacalet
    Nov 21 at 17:12










  • Do i have a ‚help‘ target?
    – Rainer
    Nov 21 at 17:50










  • Sorry, I meant html (I too frequently have a phony help target as my default goal).
    – Renaud Pacalet
    Nov 21 at 18:29










  • That is exactly what I do not want. But thanks for pointing the=at option out.
    – Rainer
    Nov 22 at 9:06
















Is there a reason why you did not declare help as phony?
– Renaud Pacalet
Nov 21 at 17:12




Is there a reason why you did not declare help as phony?
– Renaud Pacalet
Nov 21 at 17:12












Do i have a ‚help‘ target?
– Rainer
Nov 21 at 17:50




Do i have a ‚help‘ target?
– Rainer
Nov 21 at 17:50












Sorry, I meant html (I too frequently have a phony help target as my default goal).
– Renaud Pacalet
Nov 21 at 18:29




Sorry, I meant html (I too frequently have a phony help target as my default goal).
– Renaud Pacalet
Nov 21 at 18:29












That is exactly what I do not want. But thanks for pointing the=at option out.
– Rainer
Nov 22 at 9:06




That is exactly what I do not want. But thanks for pointing the=at option out.
– Rainer
Nov 22 at 9:06












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










This rule:



%.html : %.Rmd
....


tells make how to build a file foo.html from a file foo.Rmd, or a file source/foo.html from a file source/foo.Rmd, or a file docs/foo.html from a file docs/foo.Rmd.



It doesn't tell make how to build a file docs/foo.html from a file source/foo.Rmd, because the stem that matches the pattern % is not the same.



If you want to write a pattern for docs/foo.html to be built from source/foo.Rmd, you have to write it like this:



$(OUTDIR)/%.html : $(SRCDIR)/%.Rmd
....


so that the part that matches the pattern % is identical.



ETA Some other notes: you should be using := with the wildcard function as it's much better performing. Also you shouldn't use subst here because it replaces all occurrences of the string which could break things if any of your .Rmd files contain the string source for example (e.g., source/my_source_file.Rmd. This is much better written with patsubst, as in:



RMD := $(wildcard $(SRCDIR)/*.Rmd)
HTML := $(patsubst $(SRCDIR)/%.Rmd,$(OBJDIR)/%.html,$(RMD))


Finally, you don't show what the clean target does but it's unusual to have the clean target depended on by all. Usually it's a separate target that is invoked only when you want it, like make clean.






share|improve this answer























  • Makes sense. But I now changed the Makefile as suggested, but I still get the same error. I posted it as a gist at gist.github.com/rkrug/f060bab62b3b0c1b20a7360e86cd0652
    – Rainer
    Nov 22 at 9:09










  • It's because I incorrectly used the variable SOURCE in my example pattern rule when the variable you used was SRCDIR, and you blindly copied my mistake :). Unknown variables expand to the empty string so your pattern rule was docs/%.html : /%.Rmd which of course won't work.
    – MadScientist
    Nov 22 at 14:47










  • Thanks. Workshop perfectly now.
    – Rainer
    Nov 23 at 15:56











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414206%2fmakefile-does-not-find-target%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










This rule:



%.html : %.Rmd
....


tells make how to build a file foo.html from a file foo.Rmd, or a file source/foo.html from a file source/foo.Rmd, or a file docs/foo.html from a file docs/foo.Rmd.



It doesn't tell make how to build a file docs/foo.html from a file source/foo.Rmd, because the stem that matches the pattern % is not the same.



If you want to write a pattern for docs/foo.html to be built from source/foo.Rmd, you have to write it like this:



$(OUTDIR)/%.html : $(SRCDIR)/%.Rmd
....


so that the part that matches the pattern % is identical.



ETA Some other notes: you should be using := with the wildcard function as it's much better performing. Also you shouldn't use subst here because it replaces all occurrences of the string which could break things if any of your .Rmd files contain the string source for example (e.g., source/my_source_file.Rmd. This is much better written with patsubst, as in:



RMD := $(wildcard $(SRCDIR)/*.Rmd)
HTML := $(patsubst $(SRCDIR)/%.Rmd,$(OBJDIR)/%.html,$(RMD))


Finally, you don't show what the clean target does but it's unusual to have the clean target depended on by all. Usually it's a separate target that is invoked only when you want it, like make clean.






share|improve this answer























  • Makes sense. But I now changed the Makefile as suggested, but I still get the same error. I posted it as a gist at gist.github.com/rkrug/f060bab62b3b0c1b20a7360e86cd0652
    – Rainer
    Nov 22 at 9:09










  • It's because I incorrectly used the variable SOURCE in my example pattern rule when the variable you used was SRCDIR, and you blindly copied my mistake :). Unknown variables expand to the empty string so your pattern rule was docs/%.html : /%.Rmd which of course won't work.
    – MadScientist
    Nov 22 at 14:47










  • Thanks. Workshop perfectly now.
    – Rainer
    Nov 23 at 15:56















up vote
2
down vote



accepted










This rule:



%.html : %.Rmd
....


tells make how to build a file foo.html from a file foo.Rmd, or a file source/foo.html from a file source/foo.Rmd, or a file docs/foo.html from a file docs/foo.Rmd.



It doesn't tell make how to build a file docs/foo.html from a file source/foo.Rmd, because the stem that matches the pattern % is not the same.



If you want to write a pattern for docs/foo.html to be built from source/foo.Rmd, you have to write it like this:



$(OUTDIR)/%.html : $(SRCDIR)/%.Rmd
....


so that the part that matches the pattern % is identical.



ETA Some other notes: you should be using := with the wildcard function as it's much better performing. Also you shouldn't use subst here because it replaces all occurrences of the string which could break things if any of your .Rmd files contain the string source for example (e.g., source/my_source_file.Rmd. This is much better written with patsubst, as in:



RMD := $(wildcard $(SRCDIR)/*.Rmd)
HTML := $(patsubst $(SRCDIR)/%.Rmd,$(OBJDIR)/%.html,$(RMD))


Finally, you don't show what the clean target does but it's unusual to have the clean target depended on by all. Usually it's a separate target that is invoked only when you want it, like make clean.






share|improve this answer























  • Makes sense. But I now changed the Makefile as suggested, but I still get the same error. I posted it as a gist at gist.github.com/rkrug/f060bab62b3b0c1b20a7360e86cd0652
    – Rainer
    Nov 22 at 9:09










  • It's because I incorrectly used the variable SOURCE in my example pattern rule when the variable you used was SRCDIR, and you blindly copied my mistake :). Unknown variables expand to the empty string so your pattern rule was docs/%.html : /%.Rmd which of course won't work.
    – MadScientist
    Nov 22 at 14:47










  • Thanks. Workshop perfectly now.
    – Rainer
    Nov 23 at 15:56













up vote
2
down vote



accepted







up vote
2
down vote



accepted






This rule:



%.html : %.Rmd
....


tells make how to build a file foo.html from a file foo.Rmd, or a file source/foo.html from a file source/foo.Rmd, or a file docs/foo.html from a file docs/foo.Rmd.



It doesn't tell make how to build a file docs/foo.html from a file source/foo.Rmd, because the stem that matches the pattern % is not the same.



If you want to write a pattern for docs/foo.html to be built from source/foo.Rmd, you have to write it like this:



$(OUTDIR)/%.html : $(SRCDIR)/%.Rmd
....


so that the part that matches the pattern % is identical.



ETA Some other notes: you should be using := with the wildcard function as it's much better performing. Also you shouldn't use subst here because it replaces all occurrences of the string which could break things if any of your .Rmd files contain the string source for example (e.g., source/my_source_file.Rmd. This is much better written with patsubst, as in:



RMD := $(wildcard $(SRCDIR)/*.Rmd)
HTML := $(patsubst $(SRCDIR)/%.Rmd,$(OBJDIR)/%.html,$(RMD))


Finally, you don't show what the clean target does but it's unusual to have the clean target depended on by all. Usually it's a separate target that is invoked only when you want it, like make clean.






share|improve this answer














This rule:



%.html : %.Rmd
....


tells make how to build a file foo.html from a file foo.Rmd, or a file source/foo.html from a file source/foo.Rmd, or a file docs/foo.html from a file docs/foo.Rmd.



It doesn't tell make how to build a file docs/foo.html from a file source/foo.Rmd, because the stem that matches the pattern % is not the same.



If you want to write a pattern for docs/foo.html to be built from source/foo.Rmd, you have to write it like this:



$(OUTDIR)/%.html : $(SRCDIR)/%.Rmd
....


so that the part that matches the pattern % is identical.



ETA Some other notes: you should be using := with the wildcard function as it's much better performing. Also you shouldn't use subst here because it replaces all occurrences of the string which could break things if any of your .Rmd files contain the string source for example (e.g., source/my_source_file.Rmd. This is much better written with patsubst, as in:



RMD := $(wildcard $(SRCDIR)/*.Rmd)
HTML := $(patsubst $(SRCDIR)/%.Rmd,$(OBJDIR)/%.html,$(RMD))


Finally, you don't show what the clean target does but it's unusual to have the clean target depended on by all. Usually it's a separate target that is invoked only when you want it, like make clean.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 at 14:53

























answered Nov 21 at 18:24









MadScientist

45k44765




45k44765












  • Makes sense. But I now changed the Makefile as suggested, but I still get the same error. I posted it as a gist at gist.github.com/rkrug/f060bab62b3b0c1b20a7360e86cd0652
    – Rainer
    Nov 22 at 9:09










  • It's because I incorrectly used the variable SOURCE in my example pattern rule when the variable you used was SRCDIR, and you blindly copied my mistake :). Unknown variables expand to the empty string so your pattern rule was docs/%.html : /%.Rmd which of course won't work.
    – MadScientist
    Nov 22 at 14:47










  • Thanks. Workshop perfectly now.
    – Rainer
    Nov 23 at 15:56


















  • Makes sense. But I now changed the Makefile as suggested, but I still get the same error. I posted it as a gist at gist.github.com/rkrug/f060bab62b3b0c1b20a7360e86cd0652
    – Rainer
    Nov 22 at 9:09










  • It's because I incorrectly used the variable SOURCE in my example pattern rule when the variable you used was SRCDIR, and you blindly copied my mistake :). Unknown variables expand to the empty string so your pattern rule was docs/%.html : /%.Rmd which of course won't work.
    – MadScientist
    Nov 22 at 14:47










  • Thanks. Workshop perfectly now.
    – Rainer
    Nov 23 at 15:56
















Makes sense. But I now changed the Makefile as suggested, but I still get the same error. I posted it as a gist at gist.github.com/rkrug/f060bab62b3b0c1b20a7360e86cd0652
– Rainer
Nov 22 at 9:09




Makes sense. But I now changed the Makefile as suggested, but I still get the same error. I posted it as a gist at gist.github.com/rkrug/f060bab62b3b0c1b20a7360e86cd0652
– Rainer
Nov 22 at 9:09












It's because I incorrectly used the variable SOURCE in my example pattern rule when the variable you used was SRCDIR, and you blindly copied my mistake :). Unknown variables expand to the empty string so your pattern rule was docs/%.html : /%.Rmd which of course won't work.
– MadScientist
Nov 22 at 14:47




It's because I incorrectly used the variable SOURCE in my example pattern rule when the variable you used was SRCDIR, and you blindly copied my mistake :). Unknown variables expand to the empty string so your pattern rule was docs/%.html : /%.Rmd which of course won't work.
– MadScientist
Nov 22 at 14:47












Thanks. Workshop perfectly now.
– Rainer
Nov 23 at 15:56




Thanks. Workshop perfectly now.
– Rainer
Nov 23 at 15:56


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414206%2fmakefile-does-not-find-target%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks