diff --git a/src/kmake/build/DistroBuilder.hpp b/src/kmake/build/DistroBuilder.hpp new file mode 100644 index 0000000..05cfd73 --- /dev/null +++ b/src/kmake/build/DistroBuilder.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include + +namespace kmake { + + class DistroBuilder { + public: + + Distro& distro; + + /** + * The list of sources to use. + */ + vector sources; + + /** + * A map of the binaries to create, for + * each source file. + */ + map binaries; + + /** + * A map of the dependencies to create, for + * each source file. + */ + map dependencies; + + public: + + DistroBuilder(Distro& d); + + ~DistroBuilder(); + + public: + + /** + * Obtains all sources that are newer than their + * binary counterparts. + */ + void getSources(); + + /** + * Obtains a counterpart (of the source file) to another + * directory like out, bin or dep. The relative path is + * the same from each origin. + */ + fs::path counterpart(fs::path path, fs::path counter_path); + + }; + +} diff --git a/src/kmake/kmake.cpp b/src/kmake/kmake.cpp index bac06e7..4060f00 100644 --- a/src/kmake/kmake.cpp +++ b/src/kmake/kmake.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include namespace kmake { @@ -23,8 +22,6 @@ namespace kmake { } void createProject() { - namespace fs = std::filesystem; - fs::path cwd = fs::current_path(); string parent_dir = cwd.filename().string(); diff --git a/src/kmake/kmake.hpp b/src/kmake/kmake.hpp index 0aeb87b..740f673 100644 --- a/src/kmake/kmake.hpp +++ b/src/kmake/kmake.hpp @@ -1,12 +1,16 @@ #pragma once #include + #include +#include namespace kmake { using namespace ckitty; + namespace fs = std::filesystem; + enum class Verbosity : int { LOW = 0, NORMAL = 1, diff --git a/src/kmake/project/Distro.hpp b/src/kmake/project/Distro.hpp index be8eb6e..06d5f3d 100644 --- a/src/kmake/project/Distro.hpp +++ b/src/kmake/project/Distro.hpp @@ -4,6 +4,8 @@ #include +#include + namespace kmake { class Distro { @@ -11,6 +13,7 @@ namespace kmake { Project* project; + string name; map vars; vector start; vector deps; @@ -18,14 +21,39 @@ namespace kmake { vector link; vector end; + fs::path out, bin, dep; + public: Distro(); ~Distro(); + + public: + + /** + * Will create the directories for the distro. + * A distro_name/ folder will be added to + * Out, Bin and Dep directories. + * + * After this method, out, bin and dep + * variables will be set. + */ + void ensureDirs(); public: + /** + * Returns a populated vector of strings. + */ + vector populate(const vector& v); + + /** + * This method will populate the placeholders with the distro + * variables. Variables not found will not get replaced. + */ + string populate(const string& str); + optional getVar(const string& name); }; diff --git a/src/kmake/project/Project.cpp b/src/kmake/project/Project.cpp index aef262c..5af775f 100644 --- a/src/kmake/project/Project.cpp +++ b/src/kmake/project/Project.cpp @@ -101,9 +101,10 @@ namespace kmake { } } - static Distro parse_distro(Project* p, c4::yml::ConstNodeRef node, const std::string& path, std::vector& log) { + static Distro parse_distro(Project* p, const std::string& name, c4::yml::ConstNodeRef node, const std::string& path, std::vector& log) { Distro d; d.project = p; + d.name = name; if (node.has_child("vars")) parse_string_map(node["vars"], d.vars, path + ".vars", log); if (node.has_child("start")) parse_string_list(node["start"], d.start, path + ".start", log); if (node.has_child("deps")) parse_string_list(node["deps"], d.deps, path + ".deps", log); @@ -268,7 +269,7 @@ namespace kmake { for (ryml::ConstNodeRef child : d_node.children()) { if (child.has_key()) { string distro_name = to_string(child.key()); - distros[distro_name] = parse_distro(this, child, "distros." + distro_name, logs); + distros[distro_name] = parse_distro(this, distro_name, child, "distros." + distro_name, logs); } } } else {