![如何在 Windows 上移植 $(shell find . -name '*.cpp') ?](https://rvso.com/image/1543363/%E5%A6%82%E4%BD%95%E5%9C%A8%20Windows%20%E4%B8%8A%E7%A7%BB%E6%A4%8D%20%24(shell%20find%20.%20-name%20'*.cpp')%20%EF%BC%9F.png)
我在 makefile 中有這個:
# find cpp files in subdirectories
SOURCES := $(shell find . -name '*.cpp')
所以我想製作FIND
在 Windows 和 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
當然,我甚至不知道如何為linux製作參數化查找模板。但更重要的是,我找不到按模式找到所有文件的命令。 Windows 有這個:
dir * /s/b | findstr \.cpp$
這很漂亮,但是使用正則表達式...我如何正確移植它,以便 find 在兩個系統上都表現良好? makefile 沒有自己的查找文件的方法嗎?