summaryrefslogtreecommitdiff
path: root/src/configure.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2023-01-11 19:57:00 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2023-01-11 20:06:56 +0100
commit6af7742c35ecdf2831908443ca0e04bf23317a96 (patch)
tree9ada42d1d4b6bcb2618c1325f155429d2035808a /src/configure.cc
parent648c89e879f739f82ed6dba7df7243e54b98601f (diff)
Rename Configuation struct to configuration and make get/has functions member functions.
Diffstat (limited to 'src/configure.cc')
-rw-r--r--src/configure.cc75
1 files changed, 35 insertions, 40 deletions
diff --git a/src/configure.cc b/src/configure.cc
index 129fa42..76103c6 100644
--- a/src/configure.cc
+++ b/src/configure.cc
@@ -24,31 +24,32 @@ std::filesystem::path configHeaderFile("config.h");
std::map<std::string, std::string> external_includedir;
std::map<std::string, std::string> external_libdir;
-namespace ctor {
-const Configuration default_configuration{};
-const Configuration& __attribute__((weak)) configuration()
+const ctor::configuration default_configuration{};
+const ctor::configuration& __attribute__((weak)) ctor::get_configuration()
{
return default_configuration;
}
+namespace ctor {
std::optional<std::string> includedir;
std::optional<std::string> libdir;
std::optional<std::string> builddir;
std::map<std::string, std::string> conf_values;
+} // ctor::
-bool hasConfiguration(const std::string& key)
+bool ctor::configuration::has(const std::string& key) const
{
- if(key == cfg::ctor_includedir && ctor::includedir)
+ if(key == ctor::cfg::ctor_includedir && ctor::includedir)
{
return true;
}
- if(key == cfg::ctor_libdir && ctor::libdir)
+ if(key == ctor::cfg::ctor_libdir && ctor::libdir)
{
return true;
}
- if(key == cfg::builddir && ctor::builddir)
+ if(key == ctor::cfg::builddir && ctor::builddir)
{
return true;
}
@@ -58,24 +59,22 @@ bool hasConfiguration(const std::string& key)
return true;
}
- const auto& c = configuration();
- return c.tools.find(key) != c.tools.end();
+ return tools.find(key) != tools.end();
}
-const std::string& getConfiguration(const std::string& key,
- const std::string& defaultValue)
+const std::string& ctor::configuration::get(const std::string& key, const std::string& default_value) const
{
- if(key == cfg::ctor_includedir && ctor::includedir)
+ if(key == ctor::cfg::ctor_includedir && ctor::includedir)
{
return *ctor::includedir;
}
- if(key == cfg::ctor_libdir && ctor::libdir)
+ if(key == ctor::cfg::ctor_libdir && ctor::libdir)
{
return *ctor::libdir;
}
- if(key == cfg::builddir && ctor::builddir)
+ if(key == ctor::cfg::builddir && ctor::builddir)
{
return *ctor::builddir;
}
@@ -85,15 +84,13 @@ const std::string& getConfiguration(const std::string& key,
return ctor::conf_values[key];
}
- const auto& c = configuration();
- if(hasConfiguration(key))
+ if(has(key))
{
- return c.tools.at(key);
+ return tools.at(key);
}
- return defaultValue;
+ return default_value;
}
-} // namespace ctor::
std::string locate(const std::string& arch, const std::string& app)
{
@@ -403,27 +400,26 @@ int regenerateCache(ctor::settings& settings,
// Store current values for execution in this execution context.
if(!ctor_includedir.empty())
{
- ctor::conf_values[cfg::ctor_includedir] = ctor_includedir;
+ ctor::conf_values[ctor::cfg::ctor_includedir] = ctor_includedir;
}
if(!ctor_libdir.empty())
{
- ctor::conf_values[cfg::ctor_libdir] = ctor_libdir;
+ ctor::conf_values[ctor::cfg::ctor_libdir] = ctor_libdir;
}
if(!builddir.empty())
{
- ctor::conf_values[cfg::builddir] = builddir;
+ ctor::conf_values[ctor::cfg::builddir] = builddir;
}
- ctor::conf_values[cfg::host_cxx] = host_cxx;
- ctor::conf_values[cfg::build_cxx] = build_cxx;
+ ctor::conf_values[ctor::cfg::host_cxx] = host_cxx;
+ ctor::conf_values[ctor::cfg::build_cxx] = build_cxx;
std::cout << "Writing results to: " << configurationFile.string() << "\n";
{
std::ofstream istr(configurationFile);
istr << "#include <ctor.h>\n\n";
- istr << "namespace ctor {\n";
- istr << "const Configuration& configuration()\n";
+ istr << "const ctor::configuration& ctor::get_configuration()\n";
istr << "{\n";
- istr << " static Configuration cfg =\n";
+ istr << " static ctor::configuration cfg =\n";
istr << " {\n";
istr << " .args = {";
for(const auto& arg : args)
@@ -441,25 +437,25 @@ int regenerateCache(ctor::settings& settings,
istr << " .tools = {\n";
if(!builddir.empty())
{
- istr << " { \"" << cfg::builddir << "\", \"" << builddir << "\" },\n";
+ istr << " { \"" << ctor::cfg::builddir << "\", \"" << builddir << "\" },\n";
ctor::builddir = builddir;
}
- istr << " { \"" << cfg::host_cc << "\", \"" << host_cc << "\" },\n";
- istr << " { \"" << cfg::host_cxx << "\", \"" << host_cxx << "\" },\n";
- istr << " { \"" << cfg::host_ar << "\", \"" << host_ar << "\" },\n";
- istr << " { \"" << cfg::host_ld << "\", \"" << host_ld << "\" },\n";
- istr << " { \"" << cfg::build_cc << "\", \"" << build_cc << "\" },\n";
- istr << " { \"" << cfg::build_cxx << "\", \"" << build_cxx << "\" },\n";
- istr << " { \"" << cfg::build_ar << "\", \"" << build_ar << "\" },\n";
- istr << " { \"" << cfg::build_ld << "\", \"" << build_ld << "\" },\n";
+ istr << " { \"" << ctor::cfg::host_cc << "\", \"" << host_cc << "\" },\n";
+ istr << " { \"" << ctor::cfg::host_cxx << "\", \"" << host_cxx << "\" },\n";
+ istr << " { \"" << ctor::cfg::host_ar << "\", \"" << host_ar << "\" },\n";
+ istr << " { \"" << ctor::cfg::host_ld << "\", \"" << host_ld << "\" },\n";
+ istr << " { \"" << ctor::cfg::build_cc << "\", \"" << build_cc << "\" },\n";
+ istr << " { \"" << ctor::cfg::build_cxx << "\", \"" << build_cxx << "\" },\n";
+ istr << " { \"" << ctor::cfg::build_ar << "\", \"" << build_ar << "\" },\n";
+ istr << " { \"" << ctor::cfg::build_ld << "\", \"" << build_ld << "\" },\n";
if(!ctor_includedir.empty())
{
- istr << " { \"" << cfg::ctor_includedir << "\", \"" << ctor_includedir << "\" },\n";
+ istr << " { \"" << ctor::cfg::ctor_includedir << "\", \"" << ctor_includedir << "\" },\n";
ctor::includedir = ctor_includedir;
}
if(!ctor_libdir.empty())
{
- istr << " { \"" << cfg::ctor_libdir << "\", \"" << ctor_libdir << "\" },\n";
+ istr << " { \"" << ctor::cfg::ctor_libdir << "\", \"" << ctor_libdir << "\" },\n";
ctor::libdir = ctor_libdir;
}
@@ -531,7 +527,6 @@ int regenerateCache(ctor::settings& settings,
istr << " };\n";
istr << " return cfg;\n";
istr << "}\n";
- istr << "} // namespace ctor::\n\n";
}
{
@@ -607,7 +602,7 @@ int reconfigure(const ctor::settings& global_settings, int argc, char* argv[])
args.push_back(argv[i]);
}
- const auto& cfg = configuration();
+ const auto& cfg = ctor::get_configuration();
std::cout << "Re-running configure:\n";
for(const auto& e : cfg.env)