multiples directoris amb codi. Es pot especificar el directori arrel
This commit is contained in:
57
main.cpp
57
main.cpp
@@ -55,23 +55,23 @@ void loadLagueirtoFile()
|
||||
{
|
||||
case LIBS:
|
||||
libs = token;
|
||||
std::cout << "LIBS: " << libs << std::endl;
|
||||
//std::cout << "LIBS: " << libs << std::endl;
|
||||
break;
|
||||
case CPPFLAGS:
|
||||
cppflags = token;
|
||||
std::cout << "CPPFLAGS: " << cppflags << std::endl;
|
||||
//std::cout << "CPPFLAGS: " << cppflags << std::endl;
|
||||
break;
|
||||
case EXECUTABLE:
|
||||
executable = token;
|
||||
std::cout << "EXECUTABLE: " << executable << std::endl;
|
||||
//std::cout << "EXECUTABLE: " << executable << std::endl;
|
||||
break;
|
||||
case SOURCEPATH:
|
||||
source_path = token;
|
||||
std::cout << "SOURCEPATH: " << source_path << std::endl;
|
||||
//std::cout << "SOURCEPATH: " << source_path << std::endl;
|
||||
break;
|
||||
case BUILDPATH:
|
||||
build_path = token;
|
||||
std::cout << "BUILDPATH: " << build_path << std::endl;
|
||||
//std::cout << "BUILDPATH: " << build_path << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -147,15 +147,34 @@ std::vector<std::string> getIncludes(std::string filename)
|
||||
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();
|
||||
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();
|
||||
|
||||
@@ -164,7 +183,17 @@ int main()
|
||||
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))
|
||||
{
|
||||
std::string source_file = entry.path();
|
||||
@@ -198,7 +227,7 @@ int main()
|
||||
auto include_files = getIncludes(source_file);
|
||||
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))
|
||||
{
|
||||
std::cout << "WARNING: Include file '" << include_file << "' not found." << std::endl;
|
||||
@@ -236,6 +265,8 @@ int main()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (must_link)
|
||||
{
|
||||
std::string command = "g++ " + build_path + "/*.o " + libs + " -o " + executable;
|
||||
|
||||
Reference in New Issue
Block a user