summaryrefslogtreecommitdiff
path: root/src/configure.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2023-01-20 08:37:29 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2023-01-20 09:02:45 +0100
commita5585150f0ff8d27ddd22792f521f1374a3eedd8 (patch)
tree3bb442e835502d452ebe5137ad7fca5f5156bb5f /src/configure.cc
parent3cbadb8f5c55020ece96fab0fc8f4f51da01888e (diff)
Add env to execute function.
Diffstat (limited to 'src/configure.cc')
-rw-r--r--src/configure.cc127
1 files changed, 68 insertions, 59 deletions
diff --git a/src/configure.cc b/src/configure.cc
index 10f3056..b2639cb 100644
--- a/src/configure.cc
+++ b/src/configure.cc
@@ -98,57 +98,6 @@ const std::string& ctor::configuration::get(const std::string& key, const std::s
return default_value;
}
-std::string locate(const std::string& arch, const std::string& app)
-{
- std::string path_env = std::getenv("PATH");
- //std::cout << path_env << "\n";
-
- std::string program = app;
- if(!arch.empty())
- {
- program = arch + "-" + app;
- }
- std::cout << "Looking for: " << program << "\n";
- std::vector<std::string> paths;
-
- {
- std::stringstream ss(path_env);
- std::string path;
- while (std::getline(ss, path, ':'))
- {
- paths.push_back(path);
- }
- }
- for(const auto& path_str : paths)
- {
- std::filesystem::path path(path_str);
- auto prog_path = path / program;
- if(std::filesystem::exists(prog_path))
- {
- std::cout << "Found file " << app << " in path: " << path << "\n";
- auto perms = std::filesystem::status(prog_path).permissions();
- if((perms & std::filesystem::perms::owner_exec) != std::filesystem::perms::none)
- {
- //std::cout << " - executable by owner\n";
- }
- if((perms & std::filesystem::perms::group_exec) != std::filesystem::perms::none)
- {
- //std::cout << " - executable by group\n";
- }
- if((perms & std::filesystem::perms::others_exec) != std::filesystem::perms::none)
- {
- //std::cout << " - executable by others\n";
- }
-
- return prog_path.string();
- }
- }
-
- std::cerr << "Could not locate " << app << " for the " << arch << " architecture\n";
- exit(1);
- return {};
-}
-
class Args
: public std::vector<char*>
{
@@ -475,11 +424,36 @@ int regenerateCache(ctor::settings& settings,
ld_prog = ld_env->second;
}
+ auto paths = get_paths();
+
// Host detection
- auto host_cc = locate(host_arch_prefix, cc_prog);
- auto host_cxx = locate(host_arch_prefix, cxx_prog);
- auto host_ar = locate(host_arch_prefix, ar_prog);
- auto host_ld = locate(host_arch_prefix, ld_prog);
+ auto host_cc = locate(cc_prog, paths, host_arch_prefix);
+ if(host_cc.empty())
+ {
+ std::cerr << "Could not locate host_cc prog" << std::endl;
+ return 1;
+ }
+
+ auto host_cxx = locate(cxx_prog, paths, host_arch_prefix);
+ if(host_cxx.empty())
+ {
+ std::cerr << "Could not locate host_cxx prog" << std::endl;
+ return 1;
+ }
+
+ auto host_ar = locate(ar_prog, paths, host_arch_prefix);
+ if(host_ar.empty())
+ {
+ std::cerr << "Could not locate host_ar prog" << std::endl;
+ return 1;
+ }
+
+ auto host_ld = locate(ld_prog, paths, host_arch_prefix);
+ if(host_ld.empty())
+ {
+ std::cerr << "Could not locate host_ld prog" << std::endl;
+ return 1;
+ }
auto host_toolchain = getToolChain(host_cxx);
auto host_arch_str = get_arch(ctor::output_system::host);
@@ -487,11 +461,40 @@ int regenerateCache(ctor::settings& settings,
std::cout << "** Host architecture '" << host_arch_str << "': " << host_arch << std::endl;
+ if(host_arch == ctor::arch::unknown)
+ {
+ std::cerr << "Could not detect host architecture" << std::endl;
+ return 1;
+ }
+
// Build detection
- auto build_cc = locate(build_arch_prefix, cc_prog);
- auto build_cxx = locate(build_arch_prefix, cxx_prog);
- auto build_ar = locate(build_arch_prefix, ar_prog);
- auto build_ld = locate(build_arch_prefix, ld_prog);
+ auto build_cc = locate(cc_prog, paths, build_arch_prefix);
+ if(build_cc.empty())
+ {
+ std::cerr << "Could not locate build_cc prog" << std::endl;
+ return 1;
+ }
+
+ auto build_cxx = locate(cxx_prog, paths, build_arch_prefix);
+ if(build_cxx.empty())
+ {
+ std::cerr << "Could not locate build_cxx prog" << std::endl;
+ return 1;
+ }
+
+ auto build_ar = locate(ar_prog, paths, build_arch_prefix);
+ if(build_ar.empty())
+ {
+ std::cerr << "Could not locate build_ar prog" << std::endl;
+ return 1;
+ }
+
+ auto build_ld = locate(ld_prog, paths, build_arch_prefix);
+ if(build_ld.empty())
+ {
+ std::cerr << "Could not locate build_ld prog" << std::endl;
+ return 1;
+ }
auto build_toolchain = getToolChain(build_cxx);
auto build_arch_str = get_arch(ctor::output_system::build);
@@ -499,6 +502,12 @@ int regenerateCache(ctor::settings& settings,
std::cout << "** Build architecture '" << build_arch_str << "': " << build_arch << std::endl;
+ if(build_arch == ctor::arch::unknown)
+ {
+ std::cerr << "Could not detect build architecture" << std::endl;
+ return 1;
+ }
+
if(!host_cxx.empty())
{
// This is needed for bootstrapping (when running configure for the first time)