From 7f018ba2a965b90d9f8147b794be11245920d26c Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Wed, 1 Apr 2026 16:54:49 +0200 Subject: [PATCH] - [NEW] Permet compilar en directoris recursius, exemple: "source+" --- main.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/main.cpp b/main.cpp index aedc255..dcf5af4 100644 --- a/main.cpp +++ b/main.cpp @@ -301,37 +301,81 @@ int main(int argc, char *argv[]) std::filesystem::create_directory(build_path); } - auto source_paths = split(source_path); +auto source_paths = split(source_path); - for (auto src_path : source_paths) +for (auto src_path : source_paths) +{ + bool recursive = false; + + if (!src_path.empty() && src_path.back() == '+') { - #ifdef _WIN32 - std::replace(src_path.begin(), src_path.end(), '/', '\\'); - #endif + recursive = true; + src_path.pop_back(); + } - if (!std::filesystem::is_directory(src_path)) + #ifdef _WIN32 + std::replace(src_path.begin(), src_path.end(), '/', '\\'); + #endif + + if (!std::filesystem::is_directory(src_path)) + { + if (std::filesystem::is_regular_file(src_path)) { - if (std::filesystem::is_regular_file(src_path) && getFileExtension(src_path)=="cpp") + std::string ext = getFileExtension(src_path); + if (ext == "cpp" || ext == "c") { MaybeRecompile(src_path); - } else { - std::cout << "ERROR: '" << src_path <<"' does not exists." << std::endl; + } + else + { + std::cout << "ERROR: '" << src_path << "' is not a .c/.cpp file." << std::endl; exit(1); } - } else { - std::string path = "." + folder_char + src_path; - for (const auto & entry : std::filesystem::directory_iterator(path)) + } + else + { + std::cout << "ERROR: '" << src_path << "' does not exist." << std::endl; + exit(1); + } + } + else + { + std::string path = "." + folder_char + src_path; + + if (recursive) + { + for (const auto &entry : std::filesystem::recursive_directory_iterator(path)) { + if (!entry.is_regular_file()) continue; + std::string source_file = entry.path().string(); - std::string file_extension = getFileExtension(source_file); - if (file_extension=="cpp" || file_extension=="c") + std::string ext = getFileExtension(source_file); + + if ((ext == "cpp" || ext == "c") && + !contains(exclude, entry.path().filename())) { - if (!contains(exclude, entry.path().filename())) - MaybeRecompile(source_file); + MaybeRecompile(source_file); + } + } + } + else + { + for (const auto &entry : std::filesystem::directory_iterator(path)) + { + if (!entry.is_regular_file()) continue; + + std::string source_file = entry.path().string(); + std::string ext = getFileExtension(source_file); + + if ((ext == "cpp" || ext == "c") && + !contains(exclude, entry.path().filename())) + { + MaybeRecompile(source_file); } } } } +} if (must_link) {