diff --git a/Makefile b/Makefile index 68c522e5b6..768674f294 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,8 @@ UNIT_TEST_CONFIG ?= default ifeq ($(OS),Windows_NT) # Windows: use `where` – fall back through the three common names PYTHON := $(shell which python 2>nul || which python3 2>nul || which py 2>nul) - # Windows: Use cmd tools to find pins files - PINS_RAW := $(shell cmd //c "dir /s /b Marlin\src\pins\*.h 2>nul | findstr /r ".*Marlin\\\\src\\\\pins\\\\.*\\\\pins_.*\.h"") - PINS := $(subst \,/,$(PINS_RAW)) + # Windows: Use Python script to find pins files + PINS := $(shell $(PYTHON) $(SCRIPTS_DIR)/find.py Marlin/src/pins -mindepth 2 -name 'pins_*.h') else # POSIX: use `command -v` – prefer python3 over python PYTHON := $(shell command -v python3 2>/dev/null || command -v python 2>/dev/null) diff --git a/buildroot/share/scripts/find.py b/buildroot/share/scripts/find.py new file mode 100644 index 0000000000..e0dd925931 --- /dev/null +++ b/buildroot/share/scripts/find.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +# This is a cut-down version of the Linux 'find' command, implemented in Python for Marlin build scripts. +import sys +import os +import fnmatch + +def find_files(root, mindepth, pattern): + results = [] + root = os.path.normpath(root) + for dirpath, dirnames, filenames in os.walk(root): + for filename in filenames: + if fnmatch.fnmatch(filename, pattern): + full_path = os.path.join(dirpath, filename) + rel_path = os.path.relpath(full_path, root) + # mindepth: number of path components in rel_path >= mindepth + if rel_path.count(os.sep) + 1 >= mindepth: + results.append(full_path) + return results + +if __name__ == "__main__": + if len(sys.argv) != 6 or sys.argv[2] != '-mindepth' or sys.argv[4] != '-name': + print("Usage: find.py