3

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)
   # WINDOWS
   RM = erase /Q
   FIND = ???
else
   # 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')
   endif
endif

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?

Tomáš Zato
  • 4,282
  • 14
  • 48
  • 77
  • 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](https://superuser.com/questions/401495/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 '19 at 05:33

0 Answers0