From 4d3f2801f2b05401d10f04bb9a671d393a1ee23a Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Wed, 13 May 2026 14:04:48 +0200 Subject: [PATCH] =?UTF-8?q?VERSI=C3=93=202.1.0:=20-=20[NEW]=20Afegit=20Mak?= =?UTF-8?q?efile=20para=20mayor=20comodidad=20de=20los=20usuarios=20(linux?= =?UTF-8?q?,=20windows=20i=20macos)=20-=20[NEW]=20El=20lagueirtofile=20adj?= =?UTF-8?q?unt=20pot=20recompilar=20lagueirto=20amb=20el=20propi=20lagueir?= =?UTF-8?q?to=20-=20[NEW]=20Nova=20opci=C3=B3=20"compiler"=20per=20a=20esp?= =?UTF-8?q?ecificar=20qu=C3=A9=20usar=20per=20a=20compilar=20("g++",=20"cl?= =?UTF-8?q?ang++"...)=20-=20[NEW]=20Compilaci=C3=B3=20paralela=20amb=20thr?= =?UTF-8?q?eads=20(autodetecci=C3=B3=20de=20nombre=20de=20threads=20=C3=B3?= =?UTF-8?q?ptim)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 12 +++++ lagueirtofile | 7 ++- main.cpp | 114 ++++++++++++++++++++++++++++++++++++++++------- publish_gitea.sh | 2 +- version.h | 2 +- 5 files changed, 116 insertions(+), 21 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f15dd40 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +executable = lagueirto +source = main.cpp + +windows: + @echo off + g++ $(source) -O3 -o "$(executable).exe" + +macos: + clang++ $(source) -O3 -o "$(executable)" + +linux: + g++ $(source) -O3 -o "$(executable)" diff --git a/lagueirtofile b/lagueirtofile index 712f892..5019a8f 100644 --- a/lagueirtofile +++ b/lagueirtofile @@ -1,5 +1,4 @@ -libs = -lSDL2 -lSDL2_mixer -cppflags = -D DEBUG -g -executable = thepool_debug -sourcepath = source +cppflags = -O3 +executable = lagueirto +sourcepath = . buildpath = build diff --git a/main.cpp b/main.cpp index 94304da..f64591b 100644 --- a/main.cpp +++ b/main.cpp @@ -7,6 +7,10 @@ #include #include #include +#include +#include +#include +#include #include "version.h" @@ -16,6 +20,7 @@ std::string executable = "out"; std::string source_path = ""; std::vector source_paths; std::string build_path = ""; +std::string compiler = "g++"; #ifdef _WIN32 std::string folder_char = "\\"; #else @@ -24,12 +29,14 @@ std::string folder_char = "/"; std::string loaded_section = ""; std::vector exclude; -std::vector keys = {"libs", "cppflags", "executable", "sourcepath", "buildpath", "exclude"}; -enum tokens {LIBS, CPPFLAGS, EXECUTABLE, SOURCEPATH, BUILDPATH, EXCLUDE}; +std::vector keys = {"libs", "cppflags", "executable", "sourcepath", "buildpath", "exclude", "compiler"}; +enum tokens {LIBS, CPPFLAGS, EXECUTABLE, SOURCEPATH, BUILDPATH, EXCLUDE, COMPILER}; bool must_link = false; bool must_recompile_all = false; +std::mutex progress_mtx; + struct FileInfo { std::string filename; std::filesystem::file_time_type time; @@ -195,6 +202,7 @@ bool loadLagueirtoFile(const std::string §ion_to_load) else if (key == "sourcepath") source_path = value; else if (key == "buildpath") build_path = value; else if (key == "exclude") exclude = split(value); + else if (key == "compiler") compiler = value; } return !(found_any_section && section_to_load.empty() && !found_default); } @@ -335,7 +343,7 @@ bool MustRecompile(FileInfo file) { void Recompile(std::string source_file) { std::string object_file = build_path + folder_char + std::filesystem::path(source_file).stem().string() + ".o"; must_link = true; - std::string command = "g++ " + source_file + " " + cppflags + " -c -o " + object_file; + std::string command = compiler + " " + source_file + " " + cppflags + " -c -o " + object_file; //std::cout << command << std::endl; if (system(command.c_str()) != 0) { @@ -429,9 +437,79 @@ void processCommand(std::string arg) { if (arg == "-r") must_recompile_all = true; } +void parallel_compile(int thread_count) +{ + std::queue work; + std::mutex mtx; + std::condition_variable cv; + bool done = false; + + // Omplim la cua amb els arxius que necessiten recompilarse + for (auto &file : cpp_files) { + if (MustRecompile(file)) { + work.push(file.filename); + must_link = true; + } + } + + std::atomic completed = 0; + int total = work.size(); + progress_bar(0); + + auto worker = [&]() { + while (true) { + std::string job; + + // Extraure treball + { + std::unique_lock lock(mtx); + cv.wait(lock, [&]() { return !work.empty() || done; }); + + if (work.empty()) return; // ja no hi ha res més que fer + + job = work.front(); + work.pop(); + } + + // Compilar + Recompile(job); + + { + std::lock_guard lock(progress_mtx); + int done_now = ++completed; + progress_bar(100 * done_now / total); + } + } + }; + + // Llançar threads + std::vector threads; + for (int i = 0; i < thread_count; i++) + threads.emplace_back(worker); + + // Notificar als threads + { + std::lock_guard lock(mtx); + done = true; + } + cv.notify_all(); + + // Esperem a que acaben + for (auto &t : threads) + t.join(); + + progress_bar(100); + printf("\n"); +} + int main(int argc, char *argv[]) { - std::cout << "Lagueirto v" << LAGUEIRTO_VERSION << std::endl; +std::cout << " _ _ _ " << std::endl; +std::cout << "| | __ _ __ _ _ _ ___(_)_ __| |_ ___ " << std::endl; +std::cout << "| |/ _` |/ _` | | | |/ _ \\ | '__| __/ _ \\ " << std::endl; +std::cout << "| | (_| | (_| | |_| | __/ | | | || (_) |" << std::endl; +std::cout << "|_|\\__,_|\\__, |\\__,_|\\___|_|_| \\__\\___/ " << std::endl; +std::cout << " |___/ v" << LAGUEIRTO_VERSION << std::endl; std::string configuration_to_use; for (int i = 1; i < argc; ++i) @@ -533,19 +611,25 @@ int main(int argc, char *argv[]) //print_file_tree(0, cpp_files); - int i = 0; - int total = cpp_files.size(); - progress_bar(0); - for (auto& file : cpp_files) { - if (MustRecompile(file)) Recompile(file.filename); - progress_bar(100*float(float(i)/float(total))); - i++; - } - progress_bar(100); - std::cout << std::endl; + int threads = std::thread::hardware_concurrency(); + //printf("threads: %i\n", threads); + if (threads == 0) threads = 4; // fallback + + parallel_compile(threads); + +// int i = 0; +// int total = cpp_files.size(); +// progress_bar(0); +// for (auto& file : cpp_files) { +// if (MustRecompile(file)) Recompile(file.filename); +// progress_bar(100*float(float(i)/float(total))); +// i++; +// } +// progress_bar(100); +// std::cout << std::endl; if (must_link) { - std::string command = "g++ " + build_path + folder_char + "*.o " + libs + " -o " + executable; + std::string command = compiler + " " + build_path + folder_char + "*.o " + libs + " -o " + executable; //std::cout << command << std::endl; std::cout << "Linking..."; fflush(stdout); if (system(command.c_str()) != 0) { diff --git a/publish_gitea.sh b/publish_gitea.sh index 88a066f..6559c1b 100755 --- a/publish_gitea.sh +++ b/publish_gitea.sh @@ -6,7 +6,7 @@ set -e # exit 1 #fi -GITEA_TOKEN="eb44d9c0142f5038c61c5afd17f5a41177bfaedc" +#GITEA_TOKEN="" if [ -z "$GITEA_TOKEN" ]; then echo "ERROR: Debes exportar GITEA_TOKEN" diff --git a/version.h b/version.h index 0f9bd14..0e0bdd0 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ #pragma once -#define LAGUEIRTO_VERSION "2.0.2" +#define LAGUEIRTO_VERSION "2.1.0"