In the following makefile

Input:=$(wildcard $(InputLocation)/*.md)
Output:=$(patsubst $(InputLocation)/%, $(OutputLocation)/%, $(Input:Input=Output))

.PHONY: all
all: $(Output)

$(OutputLocation)/%.md : $(InputLocation)/%.md
    cp -rf $< $@;
    #cp -rf $(ActualFilePath) $(InterimFile1Path);

cp -rf $< $@; copies file successfully.

While cp -rf $(ActualFilePath) $(InterimFile1Path) gives an error cp: missing file operand

Why is it so?


Run make -n to see the commands that would be executed, or run make without options and look at the commands that are executed. Doing this would probably already answer your question, and if not, it would allow us to know what happens.

From the fragment you show, it seems you want to assign shell variables and later use make variables. So TargetLocation seems to be a make variable, while ActualFilePath="$<" seems to be a command meant for the shell.

Depending on the rest of the file, this may work:

ActualFilePath="$<"; \
InterimFile1="tempHTML.md"; \
InterimFile1Path="$(TargetLocation)/$${InterimFile1}" ; \
cp -rf $${ActualFilePath} $${InterimFile1Path};


In the indented part of the rules, you are not assigning make variables, you specify shell commands.

This should work:

$(OutputLocation)/%.md : $(InputLocation)/%.md
    cp -rf $< $@;
    ActualFilePath="$<"; \
    InterimFile1Path="$@"; \
    cp -rf $${ActualFilePath} $${InterimFile1Path}

And this should work, too:

$(OutputLocation)/%.md : $(InputLocation)/%.md
    cp -rf $(ActualFilePath) $(InterimFile1Path);
  • 2
    $(InterimFile1) is also make variable. I think $$(InterimFile1) this will be wrong as $$(InterimFile1) gets converted by make to $(InterimFile1) and passed to shell. And for shell $(InterimFile1) is not correct way of variable substitution. – Nikhil Sep 16 '18 at 12:44
  • 1
    Sorry about the typos. Still, if you want help, create a minimal but complete makefile that exposes the problem and include it in the question. – RalfFriedl Sep 16 '18 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.