diff --git a/.gitignore b/.gitignore index 66a4031..0e99af1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ lagueirto .vscode/* +lagueirto.exe diff --git a/main.cpp b/main.cpp index 803be1a..5d8b828 100644 --- a/main.cpp +++ b/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -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 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;