- Soport de per a Windows i la seua barra invertida de merda. Fuck the system.

This commit is contained in:
2025-11-18 09:20:05 +01:00
parent 70ae6d57f2
commit 6f1dfd4649
2 changed files with 16 additions and 5 deletions

View File

@@ -3,6 +3,7 @@
#include <filesystem>
#include <vector>
#include <chrono>
#include <algorithm>
#include <string.h>
@@ -11,6 +12,11 @@ std::string cppflags = "";
std::string executable = "out";
std::string source_path = "";
std::string build_path = "";
#ifdef _WIN32
std::string folder_char = "\\";
#else
std::string folder_char = "/";
#endif
std::vector<std::string> keys = {"libs", "cppflags", "executable", "sourcepath", "buildpath"};
enum tokens {LIBS, CPPFLAGS, EXECUTABLE, SOURCEPATH, BUILDPATH};
@@ -95,7 +101,7 @@ std::string getFileExtension(std::string path)
std::string getFileNameWithoutExtension(std::string path)
{
std::size_t slashpos = path.find_last_of("/");
std::size_t slashpos = path.find_last_of(folder_char);
std::string filename = path.substr(slashpos+1);
std::size_t dotpos = filename.find_last_of(".");
@@ -217,7 +223,7 @@ bool HeadersNeedRecompile(std::string file, std::filesystem::file_time_type obje
bool MustRecompile(std::string source_file)
{
std::string object_file = build_path + "/" + getFileNameWithoutExtension(source_file)+".o";
std::string object_file = build_path + folder_char + getFileNameWithoutExtension(source_file)+".o";
// si el objecte no existeix, fa falta recompilar
if (!std::filesystem::exists(object_file))
@@ -248,7 +254,7 @@ void MaybeRecompile(std::string source_file)
{
if (MustRecompile(source_file))
{
std::string object_file = build_path + "/" + getFileNameWithoutExtension(source_file)+".o";
std::string object_file = build_path + folder_char + getFileNameWithoutExtension(source_file)+".o";
must_link = true;
std::string command = "g++ " + source_file + " " + cppflags + " -c -o " + object_file;
std::cout << command << std::endl;
@@ -292,6 +298,10 @@ int main(int argc, char *argv[])
for (auto src_path : source_paths)
{
#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) && getFileExtension(src_path)=="cpp")
@@ -302,7 +312,7 @@ int main(int argc, char *argv[])
exit(1);
}
} else {
std::string path = "./" + src_path;
std::string path = "." + folder_char + src_path;
for (const auto & entry : std::filesystem::directory_iterator(path))
{
std::string source_file = entry.path().string();
@@ -317,7 +327,7 @@ int main(int argc, char *argv[])
if (must_link)
{
std::string command = "g++ " + build_path + "/*.o " + libs + " -o " + executable;
std::string command = "g++ " + build_path + folder_char + "*.o " + libs + " -o " + executable;
std::cout << command << std::endl;
if (system(command.c_str()) != 0) {
std::cout << "ABORTED!" << std::endl;