From 8a4dfbbbe76a2aef35427b7915d6e28bab165c43 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 12 May 2024 16:07:53 +0200 Subject: Build static and dynamic libs --- Builder.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 20 deletions(-) (limited to 'Builder.cpp') diff --git a/Builder.cpp b/Builder.cpp index cc756f2..4850be3 100644 --- a/Builder.cpp +++ b/Builder.cpp @@ -55,7 +55,13 @@ namespace { // iterate over all elements for (const auto& element: ptree.get_child(topelement)) { if (is_match(element, target)) { - result.push_back(element.second.get("name")); + fs::path target_name{element.second.get("name")}; + result.push_back(target_name); + + // special case dynamic lib: add links automatically + if (is_dynamic_lib(target_name)) { + result.push_back(soname_short(target_name)); + } } } @@ -285,22 +291,33 @@ std::vector Builder::make_depfile_from(const fs::path& p) const return deps_from_depfile(depfile); } -std::unordered_map> Builder::get_dependencies(const pt::ptree& ptree) const +std::unordered_map> Builder::get_dependencies(const pt::ptree& ptree, bool include_sources) const { std::unordered_map> dependencies; for (const auto& element: ptree.get_child(topelement)) { if (is_match(element, _target)) { - dependencies.emplace(get_target(element.second), get_objects(element.second)); - - std::vector sources{get_sources(element.second)}; - for (const auto& p: sources) { - fs::path p_obj{p}; - p_obj.replace_extension("o"); - std::vector deps {make_depfile_from(p)}; - // keep .d files for now to speed dependencies detection on following runs - //fs::remove(depfile_name_from(p)); - dependencies.emplace(p_obj, deps); + // add target + fs::path target{get_target(element.second)}; + dependencies.emplace(target, get_objects(element.second)); + + // add dynamic lib links + if (is_dynamic_lib(target)) { + dependencies.emplace(soname_shorter(target), std::vector{{target}}); + dependencies.emplace(soname_short(target), std::vector{{soname_shorter(target)}}); + } + + if (include_sources) { + // add source dependencies of *.o + std::vector sources{get_sources(element.second)}; + for (const auto& p: sources) { + fs::path p_obj{p}; + p_obj.replace_extension("o"); + std::vector deps {make_depfile_from(p)}; + // keep .d files for now to speed dependencies detection on following runs + //fs::remove(depfile_name_from(p)); + dependencies.emplace(p_obj, deps); + } } } } @@ -397,9 +414,8 @@ void Builder::build_filelist() { } } -// build everything according to specified configuration -void Builder::build() { - _dependencies = get_dependencies(_ptree); +std::unordered_set Builder::get_buildlist(std::function outdated_pred) { + std::unordered_set result; // create build list by depth-first search //std::cout << "Calculating build list..." << std::endl; @@ -418,11 +434,20 @@ void Builder::build() { container.push(i); } - if (is_outdated(current) && is_buildable_by_extension(current)) { - _buildlist.insert(current); + if (outdated_pred(current) && is_buildable_by_extension(current)) { + result.insert(current); } } + return result; +} + +// build everything according to specified configuration +void Builder::build() { + _dependencies = get_dependencies(_ptree); + + _buildlist = get_buildlist([&](const fs::path& i)->bool{return is_outdated(i);}); + //std::cout << "Build list:" << std::endl; //for (auto &i: _buildlist) { // std::cout << " " << i << std::endl; @@ -431,9 +456,16 @@ void Builder::build() { build_filelist(); } -void Builder::clean() const { - std::vector cleanlist{_all_objects}; - std::copy(_all_targets.cbegin(), _all_targets.cend(), std::back_inserter(cleanlist)); +void Builder::clean() { + _dependencies = get_dependencies(_ptree, false); + std::unordered_set cleanlist{get_buildlist([](const fs::path& i)->bool{ return true;})}; + + std::unordered_set add; + for (const auto& i: cleanlist) { + std::vector deps{dependencies_of(i)}; + std::copy(deps.begin(), deps.end(), std::inserter(add, add.begin())); + } + std::copy(add.begin(), add.end(), std::inserter(cleanlist, cleanlist.begin())); std::vector commands; for (auto &i: cleanlist) { -- cgit v1.2.3