I have this in makefile:

# find cpp files in subdirectories
SOURCES := $(shell find . -name '*.cpp')

So I wanted to make generic FIND command that behaves correctly on windows and linux:

ifeq ($(OS),Windows_NT)
   RM = erase /Q
   FIND = ???
   # LINUX
   ifeq ($(shell uname), Linux)
      RM = rm -f
      # This is probably wrong too, but I have no idea how to do it right
      FIND = $(find . -name '$1')

Of course, I don't even know how to make parametrized find template for linux. But more importantly, I cannot find command to find all files by pattern. Windows has this:

dir * /s/b | findstr \.cpp$

Which is beautiful, but that uses regular expression... How can I port this right, so that find behaves well on both systems? Doesn't makefile have it's own method for finding files?

  • 1
    Is there any reason a dir *.cpp /s is insufficient? – Seth Oct 12 '17 at 13:56
  • Possible duplicate of Equivalent of Unix find command on Windows – Jeff Zeitlin Oct 12 '17 at 14:00
  • You should look into MinGW/Cygwin. These are collections of Unix utilities that run on Windows, and let you run Unix-originated makefiles on Windows (plus you get a Linux-like shell on Windows...). – xenoid Oct 12 '17 at 15:42
  • Maybe you can take a look at portable build systems, that cope with such differences from conception. – Raúl Salinas-Monteagudo Apr 15 at 5:33

Your Answer

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

Browse other questions tagged or ask your own question.