diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2023-01-21 16:31:54 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2023-01-21 22:15:33 +0100 |
commit | a38c6682e4fb1f45aa1f37d10c2480aa517ea3bc (patch) | |
tree | d767d3f18eab231fdd0cff8fdd0c602869c42848 /src/configure.cc | |
parent | e4ccfe780f52cdb6c0764074effcd60235d33762 (diff) |
Make sure libctor itself is built in the 'build' system and not 'host' system. Only detect tooling for the system/tools actually required in the tasks.
Diffstat (limited to 'src/configure.cc')
-rw-r--r-- | src/configure.cc | 353 |
1 files changed, 253 insertions, 100 deletions
diff --git a/src/configure.cc b/src/configure.cc index b4829ac..c08ed88 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -30,7 +30,7 @@ const ctor::configuration& __attribute__((weak)) ctor::get_configuration() static bool initialised{false}; if(!initialised) { - cfg.host_toolchain = getToolChain(cfg.get(ctor::cfg::host_cxx, "g++")); + cfg.build_toolchain = getToolChain(cfg.get(ctor::cfg::build_cxx, "/usr/bin/g++")); initialised = true; } return cfg; @@ -374,31 +374,101 @@ int regenerateCache(ctor::settings& settings, } auto tasks = getTasks(settings, {}, false); -/* - bool needs_cpp{false}; - bool needs_c{false}; - bool needs_ar{false}; - bool needs_asm{false}; + + bool needs_build{true}; // we always need to compile ctor itself + bool needs_build_c{false}; + bool needs_build_cxx{true}; // we always need to compile ctor itself + bool needs_build_ld{true}; // we always need to compile ctor itself + bool needs_build_ar{false}; + bool needs_build_asm{false}; + + bool needs_host_c{false}; + bool needs_host{false}; + bool needs_host_cxx{false}; + bool needs_host_ld{false}; + bool needs_host_ar{false}; + bool needs_host_asm{false}; + for(const auto& task :tasks) { - switch(task->sourceLanguage()) + switch(task->outputSystem()) { - case Language::Auto: - std::cerr << "TargetLanguage not deduced!\n"; - exit(1); - break; - case Language::C: - needs_cpp = false; - break; - case Language::Cpp: - needs_c = true; + case ctor::output_system::build: + needs_build = true; + switch(task->targetType()) + { + case ctor::target_type::executable: + case ctor::target_type::unit_test: + case ctor::target_type::dynamic_library: + needs_build_ld = true; + break; + case ctor::target_type::static_library: + case ctor::target_type::unit_test_library: + needs_build_ar = true; + break; + case ctor::target_type::object: + switch(task->sourceLanguage()) + { + case ctor::language::automatic: + std::cerr << "TargetLanguage not deduced!\n"; + exit(1); + break; + case ctor::language::c: + needs_build_c = true; + break; + case ctor::language::cpp: + needs_build_cxx = true; + break; + case ctor::language::assembler: + needs_build_asm = true; + break; + } + break; + case ctor::target_type::function: + case ctor::target_type::automatic: + case ctor::target_type::unknown: + break; + } break; - case Language::Asm: - needs_asm = true; + case ctor::output_system::host: + needs_host = true; + switch(task->targetType()) + { + case ctor::target_type::executable: + case ctor::target_type::unit_test: + case ctor::target_type::dynamic_library: + needs_host_ld = true; + break; + case ctor::target_type::static_library: + case ctor::target_type::unit_test_library: + needs_host_ar = true; + break; + case ctor::target_type::object: + switch(task->sourceLanguage()) + { + case ctor::language::automatic: + std::cerr << "TargetLanguage not deduced!\n"; + exit(1); + break; + case ctor::language::c: + needs_host_c = true; + break; + case ctor::language::cpp: + needs_host_cxx = true; + break; + case ctor::language::assembler: + needs_host_asm = true; + break; + } + break; + case ctor::target_type::function: + case ctor::target_type::automatic: + case ctor::target_type::unknown: + break; + } break; } } -*/ auto cc_env = env.find("CC"); if(cc_env != env.end()) @@ -432,94 +502,141 @@ int regenerateCache(ctor::settings& settings, paths = get_paths(path_env->second); } - // Host detection - auto host_cc = locate(cc_prog, paths, host_arch_prefix); - if(host_cc.empty()) + std::string host_cc; + std::string host_cxx; + std::string host_ld; + std::string host_ar; + ctor::toolchain host_toolchain{ctor::toolchain::none}; + ctor::arch host_arch{ctor::arch::unknown}; + if(needs_host) { - std::cerr << "Could not locate host_cc prog" << std::endl; - return 1; - } + // Host detection + if(needs_host_c) + { + 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; - } + if(needs_host_cxx) + { + 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; - } + if(needs_host_ar) + { + 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; - } + if(needs_host_ld) + { + 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); - auto host_arch = get_arch(ctor::output_system::host, host_arch_str); + if(needs_host_asm) + { + // TODO + } - std::cout << "** Host architecture '" << host_arch_str << "': " << host_arch << std::endl; + host_toolchain = getToolChain(host_cxx); + auto host_arch_str = get_arch(ctor::output_system::host); + host_arch = get_arch(ctor::output_system::host, host_arch_str); - if(host_arch == ctor::arch::unknown) - { - std::cerr << "Could not detect host architecture" << std::endl; - return 1; - } + std::cout << "** Host architecture '" << host_arch_str << "': " << host_arch << std::endl; - // Build detection - 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; + if(host_arch == ctor::arch::unknown) + { + std::cerr << "Could not detect host architecture" << std::endl; + return 1; + } } - auto build_cxx = locate(cxx_prog, paths, build_arch_prefix); - if(build_cxx.empty()) + std::string build_cc; + std::string build_cxx; + std::string build_ld; + std::string build_ar; + ctor::toolchain build_toolchain{ctor::toolchain::none}; + ctor::arch build_arch{ctor::arch::unknown}; + if(needs_build) { - std::cerr << "Could not locate build_cxx prog" << std::endl; - return 1; - } + // Build detection + if(needs_build_c) + { + 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_ar = locate(ar_prog, paths, build_arch_prefix); - if(build_ar.empty()) - { - std::cerr << "Could not locate build_ar prog" << std::endl; - return 1; - } + if(needs_build_cxx) + { + 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_ld = locate(ld_prog, paths, build_arch_prefix); - if(build_ld.empty()) - { - std::cerr << "Could not locate build_ld prog" << std::endl; - return 1; - } + if(needs_build_ar) + { + 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_toolchain = getToolChain(build_cxx); - auto build_arch_str = get_arch(ctor::output_system::build); - auto build_arch = get_arch(ctor::output_system::build, build_arch_str); + if(needs_build_ld) + { + 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; + } + } - std::cout << "** Build architecture '" << build_arch_str << "': " << build_arch << std::endl; + if(needs_build_asm) + { + // TODO + } - if(build_arch == ctor::arch::unknown) - { - std::cerr << "Could not detect build architecture" << std::endl; - return 1; - } + build_toolchain = getToolChain(build_cxx); + auto build_arch_str = get_arch(ctor::output_system::build); + build_arch = get_arch(ctor::output_system::build, build_arch_str); - if(!host_cxx.empty()) - { - // This is needed for bootstrapping (when running configure for the first time) - ctor::conf_values[ctor::cfg::host_cxx] = host_cxx; + 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; + } } + // Store current values for execution in this execution context. if(!ctor_includedir.empty()) { @@ -544,10 +661,16 @@ int regenerateCache(ctor::settings& settings, istr << "{\n"; istr << " static ctor::configuration cfg =\n"; istr << " {\n"; - istr << " .host_toolchain = " << host_toolchain << ",\n"; - istr << " .host_arch = " << host_arch << ",\n"; - istr << " .build_toolchain = " << build_toolchain << ",\n"; - istr << " .build_arch = " << build_arch << ",\n"; + if(needs_host) + { + istr << " .host_toolchain = " << host_toolchain << ",\n"; + istr << " .host_arch = " << host_arch << ",\n"; + } + if(needs_build) + { + istr << " .build_toolchain = " << build_toolchain << ",\n"; + istr << " .build_arch = " << build_arch << ",\n"; + } istr << " .args = {"; for(const auto& arg : args) { @@ -567,14 +690,44 @@ int regenerateCache(ctor::settings& settings, istr << " { \"" << ctor::cfg::builddir << "\", \"" << esc(builddir) << "\" },\n"; ctor::builddir = builddir; } - istr << " { \"" << ctor::cfg::host_cc << "\", \"" << esc(host_cc) << "\" },\n"; - istr << " { \"" << ctor::cfg::host_cxx << "\", \"" << esc(host_cxx) << "\" },\n"; - istr << " { \"" << ctor::cfg::host_ar << "\", \"" << esc(host_ar) << "\" },\n"; - istr << " { \"" << ctor::cfg::host_ld << "\", \"" << esc(host_ld) << "\" },\n"; - istr << " { \"" << ctor::cfg::build_cc << "\", \"" << esc(build_cc) << "\" },\n"; - istr << " { \"" << ctor::cfg::build_cxx << "\", \"" << esc(build_cxx) << "\" },\n"; - istr << " { \"" << ctor::cfg::build_ar << "\", \"" << esc(build_ar) << "\" },\n"; - istr << " { \"" << ctor::cfg::build_ld << "\", \"" << esc(build_ld) << "\" },\n"; + if(needs_host) + { + if(needs_host_c) + { + istr << " { \"" << ctor::cfg::host_cc << "\", \"" << esc(host_cc) << "\" },\n"; + } + if(needs_host_cxx) + { + istr << " { \"" << ctor::cfg::host_cxx << "\", \"" << esc(host_cxx) << "\" },\n"; + } + if(needs_host_ar) + { + istr << " { \"" << ctor::cfg::host_ar << "\", \"" << esc(host_ar) << "\" },\n"; + } + if(needs_host_ld) + { + istr << " { \"" << ctor::cfg::host_ld << "\", \"" << esc(host_ld) << "\" },\n"; + } + } + if(needs_build) + { + if(needs_build_c) + { + istr << " { \"" << ctor::cfg::build_cc << "\", \"" << esc(build_cc) << "\" },\n"; + } + if(needs_build_cxx) + { + istr << " { \"" << ctor::cfg::build_cxx << "\", \"" << esc(build_cxx) << "\" },\n"; + } + if(needs_build_ar) + { + istr << " { \"" << ctor::cfg::build_ar << "\", \"" << esc(build_ar) << "\" },\n"; + } + if(needs_build_ld) + { + istr << " { \"" << ctor::cfg::build_ld << "\", \"" << esc(build_ld) << "\" },\n"; + } + } if(!ctor_includedir.empty()) { istr << " { \"" << ctor::cfg::ctor_includedir << "\", \"" << esc(ctor_includedir) << "\" },\n"; |