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