- Soport de per a Windows i la seua barra invertida de merda. Fuck the system.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
lagueirto
|
lagueirto
|
||||||
.vscode/*
|
.vscode/*
|
||||||
|
lagueirto.exe
|
||||||
|
|||||||
20
main.cpp
20
main.cpp
@@ -3,6 +3,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -11,6 +12,11 @@ std::string cppflags = "";
|
|||||||
std::string executable = "out";
|
std::string executable = "out";
|
||||||
std::string source_path = "";
|
std::string source_path = "";
|
||||||
std::string build_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"};
|
std::vector<std::string> keys = {"libs", "cppflags", "executable", "sourcepath", "buildpath"};
|
||||||
enum tokens {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::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::string filename = path.substr(slashpos+1);
|
||||||
|
|
||||||
std::size_t dotpos = filename.find_last_of(".");
|
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)
|
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
|
// si el objecte no existeix, fa falta recompilar
|
||||||
if (!std::filesystem::exists(object_file))
|
if (!std::filesystem::exists(object_file))
|
||||||
@@ -248,7 +254,7 @@ void MaybeRecompile(std::string source_file)
|
|||||||
{
|
{
|
||||||
if (MustRecompile(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;
|
must_link = true;
|
||||||
std::string command = "g++ " + source_file + " " + cppflags + " -c -o " + object_file;
|
std::string command = "g++ " + source_file + " " + cppflags + " -c -o " + object_file;
|
||||||
std::cout << command << std::endl;
|
std::cout << command << std::endl;
|
||||||
@@ -292,6 +298,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
for (auto src_path : source_paths)
|
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_directory(src_path))
|
||||||
{
|
{
|
||||||
if (std::filesystem::is_regular_file(src_path) && getFileExtension(src_path)=="cpp")
|
if (std::filesystem::is_regular_file(src_path) && getFileExtension(src_path)=="cpp")
|
||||||
@@ -302,7 +312,7 @@ int main(int argc, char *argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::string path = "./" + src_path;
|
std::string path = "." + folder_char + src_path;
|
||||||
for (const auto & entry : std::filesystem::directory_iterator(path))
|
for (const auto & entry : std::filesystem::directory_iterator(path))
|
||||||
{
|
{
|
||||||
std::string source_file = entry.path().string();
|
std::string source_file = entry.path().string();
|
||||||
@@ -317,7 +327,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (must_link)
|
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;
|
std::cout << command << std::endl;
|
||||||
if (system(command.c_str()) != 0) {
|
if (system(command.c_str()) != 0) {
|
||||||
std::cout << "ABORTED!" << std::endl;
|
std::cout << "ABORTED!" << std::endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user