2

we have few html file title with spaces in a folder which is a prerequisite for make rule. while executing, the rule has failed stating there is no rule to make the target.

do we have anything to handle spaces in make file prerequisite?

prerequisite = $(wildcard D:/HtmlHelp/*.html)

the above variable results below files list

D:/HtmlHelp/Order Coordination.html D:/HtmlHelp/OverThres.html D:/HtmlHelp/Pmu.html

First file name has a space , which executing the rule with this prerequisite list ,make returns below error.

gmake[2]: *** No rule to make target `D:/HtmlHelp/Order', needed by `rule1'.  Stop.
melpomene
  • 84,125
  • 8
  • 85
  • 148
AnRedd
  • 156
  • 8
  • Is there a specific reason you need to use `wildcard` function? I suppose if you just used wildcards in your rule prerequisites, it should work as expected (at least with GNU Make that seems to be the case). – Ondrej K. Jan 09 '19 at 12:31
  • prerequisite = D:/HtmlHelp/*.html this will also get the same result , hence removed wildcard from prerequisite list , but issue still exists. Thank you very much! – AnRedd Jan 09 '19 at 14:02
  • 1
    Just a node: make doesn't work well with filenames containing whitespace. You may work around problems here or there but you'll continue to run into them and be frustrated by them. You should avoid using whitespace in filenames if you want to use make to manipulate them. – MadScientist Jan 09 '19 at 15:51

1 Answers1

0

If you replace:

prerequisite = $(wildcard D:/HtmlHelp/*.html)

with simply:

prerequisite = D:/HtmlHelp/*.html

then GNU make will work, although you will need to replace in your rules $@ with "$@", etc. The wildcard expansion will then happen in the rules, as https://www.gnu.org/software/make/manual/html_node/Wildcard-Function.html states:

Wildcard expansion happens automatically in rules. But wildcard expansion does not normally take place when a variable is set...

You can see this by inserting the statement:

$(info $(prerequisite))

into your makefile.

Another approach, from Using makefile wildcard command for file names with spaces, would be to use something like:

prerequisite = $(shell find 'D:/HtmlHelp/' -name '*.html' | sed 's/ /\\ /g')

to escape the spaces.

Finally, Can GNU make handle filenames with spaces? has a number of suggestions, with several referencing the blog post https://www.cmcrossroads.com/article/gnu-make-meets-file-names-spaces-them.

Joseph Quinsey
  • 9,553
  • 10
  • 54
  • 77
  • Thank you @Joseph Quinsey for this solution , this is working fine when i try that from bash , but not working from matlab gmake. I have tried with below command CON = $(shell find ../M/App/Po/Con/ -name '*.*' | sed 's/ /\\ /g') , matlab gmake returned this error "FIND: Parameter format not correct" – AnRedd Jan 09 '19 at 13:55
  • Your `find` appears to be the Microsoft `find`, not the Unix version. See https://en.wikipedia.org/wiki/Find_(Windows). – Joseph Quinsey Jan 09 '19 at 14:05
  • @AnRedd: Perhaps `ls` will work instead of `find`. Try `prerequisite = $(shell ls -1 D:/HtmlHelp/*.html | sed 's/ /\\ /g')`. – Joseph Quinsey Jan 09 '19 at 14:22
  • Thank you very much for you help on this. Can i get the files list recursively , i tried with this command "ls -R1 ../M/App/Po/Con/ | sed 's/ /\. /g'" but displaying as usual recursive switch output including folders list and separation between each subfolder. I am looking for only recursive files list , i have tried with different regex's as well. – AnRedd Jan 09 '19 at 16:44
  • `ls -R` will not work. You could try `ls -d1 $PWD/* $PWD/*/*` for example to look at two levels. But the Unix `find` is the best bet, if you can find a way to invoke it in your environment. – Joseph Quinsey Jan 09 '19 at 17:15
  • @AnRedd: Did you have any success in resolving your problem? – Joseph Quinsey Jan 13 '19 at 03:41
  • no , it is not yet resolved. removed all paths with spaces. Stuck with another issue , rules are always being executed, though prerequisites are not changed and target is not cleaned. – AnRedd Jan 13 '19 at 17:31