- [NEW] Ara es poden especificar també arxius cpp solts a compilar (a part de directoris sencers, com abans)

This commit is contained in:
2025-05-28 15:53:32 +02:00
parent e33f21166b
commit eebc67e088

View File

@@ -15,6 +15,8 @@ std::string build_path = "";
std::vector<std::string> keys = {"libs", "cppflags", "executable", "sourcepath", "buildpath"};
enum tokens {LIBS, CPPFLAGS, EXECUTABLE, SOURCEPATH, BUILDPATH};
bool must_link = false;
char *getBufferFromFile(const char* filename)
{
FILE *f = fopen(filename, "rb");
@@ -169,35 +171,7 @@ std::vector<std::string> split(std::string str)
return strings;
}
int main(int argc, char *argv[])
{
if (argc>1) std::filesystem::current_path(argv[1]);
loadLagueirtoFile();
bool must_link = false;
std::chrono::steady_clock::time_point begin_all = std::chrono::steady_clock::now();
if (!std::filesystem::is_directory(build_path))
{
std::filesystem::create_directory(build_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();
if (getFileExtension(source_file)=="cpp")
void MaybeRecompile(std::string source_file)
{
bool must_recompile = false;
std::string object_file = build_path + "/" + getFileNameWithoutExtension(source_file)+".o";
@@ -227,6 +201,10 @@ int main(int argc, char *argv[])
auto include_files = getIncludes(source_file);
for (auto include : include_files)
{
std::filesystem::path fullpath(source_file);
auto path_without_filename = fullpath.remove_filename();
std::string src_path = path_without_filename.string();
std::string include_file = src_path + "/" + include;
if (!std::filesystem::exists(include_file))
{
@@ -264,6 +242,43 @@ int main(int argc, char *argv[])
//std::cout << object_file << " està actualitzat" << std::endl;
}
}
int main(int argc, char *argv[])
{
if (argc>1) std::filesystem::current_path(argv[1]);
loadLagueirtoFile();
std::chrono::steady_clock::time_point begin_all = std::chrono::steady_clock::now();
if (!std::filesystem::is_directory(build_path))
{
std::filesystem::create_directory(build_path);
}
auto source_paths = split(source_path);
for (auto src_path : source_paths)
{
if (!std::filesystem::is_directory(src_path))
{
if (std::filesystem::is_regular_file(src_path) && getFileExtension(src_path)=="cpp")
{
MaybeRecompile(src_path);
} else {
std::cout << "ERROR: '" << src_path <<"' does not exists." << std::endl;
exit(1);
}
} else {
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")
{
MaybeRecompile(source_file);
}
}
}
}