2

I am new to makefiles. I want to recursively find all the files in a root_folder and store it to a variable. The code I have written to achieve this in makefile is as below:

dirs:=$(root_folder)/*/
SOURCE:=$(foreach dir,$(dirs),$(wildcard $(dir)/*.cpp))

But the .cpp files are not getting included to the SOURCE variable with this implementation.I think my approach is wrong.Any help in this matter will much be appreciated.

Regards,
newbie_in

newbie_in
  • 55
  • 1
  • 8
  • 2
    Possible duplicate of [Recursive wildcards in GNU make?](http://stackoverflow.com/questions/2483182/recursive-wildcards-in-gnu-make) – user657267 Apr 18 '16 at 12:54

1 Answers1

0

Assuming you're using linux, use find:

SOURCE:=$(shell find $(root_folder) -name *.cpp)

or

SOURCE:=$(shell cd $(root_folder) && find . -name *.cpp)
John
  • 3,400
  • 3
  • 31
  • 47
  • Thank you for the comment.But what if the OS is windows with cygwin installation,will it work fine in that environment also? – newbie_in Apr 19 '16 at 04:25
  • 1
    `$(shell ...)` runs a command in the shell environment, and cygwin mimics linux, so it should support the find command -- BUT, apparently it's possible for the windows find command to override the cygwin version. See [here](http://superuser.com/questions/126123/find-command-doesnt-seem-to-work-in-cygwin) for more info. (I don't have cygwin, so I can't try it). Good luck. – John Apr 20 '16 at 20:30
  • Is there any way to achieve this through windows command prompt without cygwin? – newbie_in Jul 15 '16 at 11:04