multiples directoris amb codi. Es pot especificar el directori arrel

This commit is contained in:
2024-11-18 17:53:38 +01:00
parent 752e7c7bbd
commit e33f21166b

View File

@@ -55,23 +55,23 @@ void loadLagueirtoFile()
{ {
case LIBS: case LIBS:
libs = token; libs = token;
std::cout << "LIBS: " << libs << std::endl; //std::cout << "LIBS: " << libs << std::endl;
break; break;
case CPPFLAGS: case CPPFLAGS:
cppflags = token; cppflags = token;
std::cout << "CPPFLAGS: " << cppflags << std::endl; //std::cout << "CPPFLAGS: " << cppflags << std::endl;
break; break;
case EXECUTABLE: case EXECUTABLE:
executable = token; executable = token;
std::cout << "EXECUTABLE: " << executable << std::endl; //std::cout << "EXECUTABLE: " << executable << std::endl;
break; break;
case SOURCEPATH: case SOURCEPATH:
source_path = token; source_path = token;
std::cout << "SOURCEPATH: " << source_path << std::endl; //std::cout << "SOURCEPATH: " << source_path << std::endl;
break; break;
case BUILDPATH: case BUILDPATH:
build_path = token; build_path = token;
std::cout << "BUILDPATH: " << build_path << std::endl; //std::cout << "BUILDPATH: " << build_path << std::endl;
break; break;
} }
} }
@@ -147,15 +147,34 @@ std::vector<std::string> getIncludes(std::string filename)
return includes; return includes;
} }
int main() std::vector<std::string> split(std::string str)
{ {
std::vector<std::string> strings;
char tmp[100];
int tmp_p = 0, str_p = 0;
while (str[str_p]!=0)
{
if (str[str_p]!=32)
tmp[tmp_p++] = str[str_p++];
else
{
tmp[tmp_p]=0;
strings.push_back(tmp);
tmp_p=0; while (str[str_p]==32) str_p++;
}
}
tmp[tmp_p]=0;
strings.push_back(tmp);
return strings;
}
int main(int argc, char *argv[])
{
if (argc>1) std::filesystem::current_path(argv[1]);
loadLagueirtoFile(); loadLagueirtoFile();
bool must_link = false; bool must_link = false;
if (!std::filesystem::is_directory(source_path))
{
std::cout << "ERROR: Directory '" << source_path <<"' does not exists." << std::endl;
exit(1);
}
std::chrono::steady_clock::time_point begin_all = std::chrono::steady_clock::now(); std::chrono::steady_clock::time_point begin_all = std::chrono::steady_clock::now();
@@ -164,7 +183,17 @@ int main()
std::filesystem::create_directory(build_path); std::filesystem::create_directory(build_path);
} }
std::string path = "./" + source_path; auto source_paths = split(source_path);
for (auto src_path : source_paths)
{
if (!std::filesystem::is_directory(src_path))
{
std::cout << "ERROR: Directory '" << src_path <<"' does not exists." << std::endl;
exit(1);
}
std::string path = "./" + 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(); std::string source_file = entry.path();
@@ -198,7 +227,7 @@ int main()
auto include_files = getIncludes(source_file); auto include_files = getIncludes(source_file);
for (auto include : include_files) for (auto include : include_files)
{ {
std::string include_file = source_path + "/" + include; std::string include_file = src_path + "/" + include;
if (!std::filesystem::exists(include_file)) if (!std::filesystem::exists(include_file))
{ {
std::cout << "WARNING: Include file '" << include_file << "' not found." << std::endl; std::cout << "WARNING: Include file '" << include_file << "' not found." << std::endl;
@@ -236,6 +265,8 @@ int main()
} }
} }
} }
}
if (must_link) if (must_link)
{ {
std::string command = "g++ " + build_path + "/*.o " + libs + " -o " + executable; std::string command = "g++ " + build_path + "/*.o " + libs + " -o " + executable;