multiples directoris amb codi. Es pot especificar el directori arrel
This commit is contained in:
155
main.cpp
155
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,78 +183,90 @@ int main()
|
||||
std::filesystem::create_directory(build_path);
|
||||
}
|
||||
|
||||
std::string path = "./" + source_path;
|
||||
for (const auto & entry : std::filesystem::directory_iterator(path))
|
||||
auto source_paths = split(source_path);
|
||||
|
||||
for (auto src_path : source_paths)
|
||||
{
|
||||
std::string source_file = entry.path();
|
||||
if (getFileExtension(source_file)=="cpp")
|
||||
if (!std::filesystem::is_directory(src_path))
|
||||
{
|
||||
bool must_recompile = false;
|
||||
std::string object_file = build_path + "/" + getFileNameWithoutExtension(source_file)+".o";
|
||||
std::cout << "ERROR: Directory '" << src_path <<"' does not exists." << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// si el objecte no existeix, fa falta recompilar
|
||||
if (!std::filesystem::exists(object_file))
|
||||
std::string path = "./" + src_path;
|
||||
for (const auto & entry : std::filesystem::directory_iterator(path))
|
||||
{
|
||||
std::string source_file = entry.path();
|
||||
if (getFileExtension(source_file)=="cpp")
|
||||
{
|
||||
must_recompile = true;
|
||||
//std::cout << "'" << object_file << "' No existeix. ";
|
||||
bool must_recompile = false;
|
||||
std::string object_file = build_path + "/" + getFileNameWithoutExtension(source_file)+".o";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si sí que existeix, agafem la data de modificació
|
||||
auto object_file_write_time = std::filesystem::last_write_time(object_file);
|
||||
|
||||
// Si la data de modificació del cpp es major que la del objecte, fa falta recompilar
|
||||
auto source_file_write_time = std::filesystem::last_write_time(source_file);
|
||||
if (source_file_write_time > object_file_write_time)
|
||||
// si el objecte no existeix, fa falta recompilar
|
||||
if (!std::filesystem::exists(object_file))
|
||||
{
|
||||
//std::cout << "'" << source_file << "' es més nou. ";
|
||||
must_recompile = true;
|
||||
//std::cout << "'" << object_file << "' No existeix. ";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sino, mirem els includes
|
||||
auto include_files = getIncludes(source_file);
|
||||
for (auto include : include_files)
|
||||
// Si sí que existeix, agafem la data de modificació
|
||||
auto object_file_write_time = std::filesystem::last_write_time(object_file);
|
||||
|
||||
// Si la data de modificació del cpp es major que la del objecte, fa falta recompilar
|
||||
auto source_file_write_time = std::filesystem::last_write_time(source_file);
|
||||
if (source_file_write_time > object_file_write_time)
|
||||
{
|
||||
std::string include_file = source_path + "/" + include;
|
||||
if (!std::filesystem::exists(include_file))
|
||||
//std::cout << "'" << source_file << "' es més nou. ";
|
||||
must_recompile = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sino, mirem els includes
|
||||
auto include_files = getIncludes(source_file);
|
||||
for (auto include : include_files)
|
||||
{
|
||||
std::cout << "WARNING: Include file '" << include_file << "' not found." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto include_file_write_time = std::filesystem::last_write_time(include_file);
|
||||
if (include_file_write_time > object_file_write_time)
|
||||
std::string include_file = src_path + "/" + include;
|
||||
if (!std::filesystem::exists(include_file))
|
||||
{
|
||||
//std::cout << "El include '" << include_file << "' es més nou. ";
|
||||
must_recompile = true;
|
||||
break;
|
||||
std::cout << "WARNING: Include file '" << include_file << "' not found." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto include_file_write_time = std::filesystem::last_write_time(include_file);
|
||||
if (include_file_write_time > object_file_write_time)
|
||||
{
|
||||
//std::cout << "El include '" << include_file << "' es més nou. ";
|
||||
must_recompile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (must_recompile)
|
||||
{
|
||||
must_link = true;
|
||||
//std::cout << object_file << " s'ha de reompilar" << std::endl;
|
||||
std::string command = "g++ " + source_file + " " + cppflags + " -c -o " + object_file;
|
||||
std::cout << command << std::endl;
|
||||
if (must_recompile)
|
||||
{
|
||||
must_link = true;
|
||||
//std::cout << object_file << " s'ha de reompilar" << std::endl;
|
||||
std::string command = "g++ " + source_file + " " + cppflags + " -c -o " + object_file;
|
||||
std::cout << command << std::endl;
|
||||
|
||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
||||
system(command.c_str());
|
||||
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
|
||||
float t = float(std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count())/1000000;
|
||||
std::cout << "(" << t << " seconds)" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << object_file << " està actualitzat" << std::endl;
|
||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
||||
system(command.c_str());
|
||||
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
|
||||
float t = float(std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count())/1000000;
|
||||
std::cout << "(" << t << " seconds)" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << object_file << " està actualitzat" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (must_link)
|
||||
{
|
||||
std::string command = "g++ " + build_path + "/*.o " + libs + " -o " + executable;
|
||||
|
||||
Reference in New Issue
Block a user