-2

I'm using mingw-w64 to build my program using gcc on windows.
In my makefile, I'm doing the following to find all source files:

SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s')

As you can see below, the FIND command makes my build crash.

File not found - *.cpp
FIND: Parameter format not correct
# ...

After using make -d to see what's happening under the hood, I discovered that my makefile use system32\find.exe instead of the find provided by MinGW.

$ make -d
# ...
Reading makefile 'Makefile'...
CreateProcess(C:\WINDOWS\system32\find.exe,find ./src -name *.cpp -or -name *.c -or -name 
File not found - *.cpp
*.s,...)
# ...

Is there a way to force make to use the proper find command?
If not, how to address this portability issue?


EDIT:

It looks like I'm punished for doing fancy stuff.
As mentioned in the comments, minGW-w64 doesn't come with a FIND util.

My new problem is therefore to translate the following lines for windows:

SRC_DIRS := ./src
SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s')
INC_DIRS := $(shell find $(SRC_DIRS) -type d)

Thank you all for your answers.

gberth
  • 467
  • 5
  • 13

1 Answers1

0

You can go several ways to bypass this.

  1. Short way. Use full path: /bin/find

  2. Hard way. Parse the output from where find and take the first one path without a prefix path from WINDIR variable. To port this to Linux - parse which where before where find.

I like the hard way:

# `which` to avoid recursion in `function find`
SHELL_FIND=`which find`

# detect `find.exe` in Windows behind `%SYSTEMROOT%\System32\find.exe`
if which where >/dev/null 2>&1; then
  for path in `where find 2>/dev/null`; do
    case "$path" in
      "$WINDIR"\\*)
        ;;
      *)
        SHELL_FIND="$path"
        break
        ;;
    esac
  done
fi

To silently replace the find:

function find()
{
  "$SHELL_FIND" "$@"
}

function find.exe()
{
  "$SHELL_FIND" "$@"
}
Andry
  • 2,273
  • 29
  • 28