diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-06-21 21:39:46 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-06-21 21:39:46 +0200 |
commit | b25810b9668abe8f7cc7db24326a98c1b017966e (patch) | |
tree | 40cda88ffbf8dccfc2d2335783f608966874c58e /libcppbuild.cc | |
parent | c53e622b648635539e4870fd0c9159c5d8c3be4a (diff) |
Distinguish between host and target builds.
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r-- | libcppbuild.cc | 140 |
1 files changed, 113 insertions, 27 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc index 1fa1bc3..5cd4dc9 100644 --- a/libcppbuild.cc +++ b/libcppbuild.cc @@ -230,7 +230,7 @@ void recompileCheck(const Settings& settings, int argc, char* argv[]) if(dirty) { std::cout << "Rebuilding config\n"; - auto tool = getConfiguration("host-cpp", "/usr/bin/g++"); + auto tool = getConfiguration(cfg::host_cpp, "/usr/bin/g++"); auto ret = execute(tool, args, settings.verbose > 0); if(ret != 0) { @@ -276,8 +276,74 @@ std::list<std::shared_ptr<Task>> getTasks(const Settings& settings) return tasks; } -int configure(int argc, char* argv[],const Settings& settings) +/* +int configure(int argc, char* argv[]) { + Settings settings; + + settings.builddir = "build"; + + std::string cmd_str; + for(int i = 0; i < argc; ++i) + { + if(i > 0) + { + cmd_str += " "; + } + cmd_str += argv[i]; + } + + dg::Options opt; + int key{256}; + + std::string build_arch; + std::string host_arch; + + opt.add("build-dir", required_argument, 'b', + "Set output directory for build files (default: '" + + settings.builddir + "').", + [&]() { + settings.builddir = optarg; + return 0; + }); + + opt.add("verbose", no_argument, 'v', + "Be verbose. Add multiple times for more verbosity.", + [&]() { + settings.verbose++; + return 0; + }); + + opt.add("build", required_argument, key++, + "Configure for building on specified architecture.", + [&]() { + build_arch = optarg; + return 0; + }); + + opt.add("host", required_argument, key++, + "Cross-compile to build programs to run on specified architecture.", + [&]() { + host_arch = optarg; + return 0; + }); + + opt.add("help", no_argument, 'h', + "Print this help text.", + [&]() { + std::cout << "configure usage stuff\n"; + opt.help(); + exit(0); + return 0; + }); + + opt.process(argc, argv); + + if(host_arch.empty()) + { + host_arch = build_arch; + } + auto tasks = getTasks(settings); bool needs_cpp{false}; @@ -285,7 +351,7 @@ int configure(int argc, char* argv[],const Settings& settings) bool needs_ar{false}; for(const auto& task :tasks) { - switch(task->language()) + switch(task->sourceLanguage()) { case Language::Auto: std::cerr << "TargetLanguage not deduced!\n"; @@ -299,46 +365,53 @@ int configure(int argc, char* argv[],const Settings& settings) break; } } - std::ofstream istr(configurationFile); - istr << "#include \"libcppbuild.h\"\n\n"; - istr << "const std::map<std::string, std::string>& configuration()\n"; - istr << "{\n"; - istr << " static std::map<std::string, std::string> c =\n"; - istr << " {\n"; - istr << " { \"builddir\", \"build\" },\n"; - istr << " { \"host-cc\", \"/usr/bin/gcc\" },\n"; - istr << " { \"host-cpp\", \"/usr/bin/g++\" },\n"; - istr << " { \"host-ar\", \"/usr/bin/ar\" },\n"; - istr << " { \"host-ld\", \"/usr/bin/ld\" },\n"; - istr << " { \"target-cc\", \"/usr/bin/gcc\" },\n"; - istr << " { \"target-cpp\", \"/usr/bin/g++\" },\n"; - istr << " { \"target-ar\", \"/usr/bin/ar\" },\n"; - istr << " { \"target-ld\", \"/usr/bin/ld\" },\n"; - istr << " };\n"; - istr << " return c;\n"; - istr << "}\n"; + + { + std::ofstream istr(configurationFile); + istr << "#include \"libcppbuild.h\"\n\n"; + istr << "const std::map<std::string, std::string>& configuration()\n"; + istr << "{\n"; + istr << " static std::map<std::string, std::string> c =\n"; + istr << " {\n"; + istr << " { \"cmd\", \"" << cmd_str << "\" },\n"; + istr << " { \"" << cfg::builddir << "\", \"" << settings.builddir << "\" },\n"; + istr << " { \"" << cfg::target_cc << "\", \"/usr/bin/gcc\" },\n"; + istr << " { \"" << cfg::target_cpp << "\", \"/usr/bin/g++\" },\n"; + istr << " { \"" << cfg::target_ar << "\", \"/usr/bin/ar\" },\n"; + istr << " { \"" << cfg::target_ld << "\", \"/usr/bin/ld\" },\n"; + istr << " { \"" << cfg::host_cc << "\", \"/usr/bin/gcc\" },\n"; + istr << " { \"" << cfg::host_cpp << "\", \"/usr/bin/g++\" },\n"; + istr << " { \"" << cfg::host_ar << "\", \"/usr/bin/ar\" },\n"; + istr << " { \"" << cfg::host_ld << "\", \"/usr/bin/ld\" },\n"; + istr << " };\n"; + istr << " return c;\n"; + istr << "}\n"; + } + return 0; } int main(int argc, char* argv[]) { + if(argc > 1 && std::string(argv[1]) == "configure") + { + return configure(argc, argv); + } + Settings settings{}; - settings.builddir = getConfiguration("builddir", "build"); + settings.builddir = getConfiguration(cfg::builddir, "build"); settings.parallel_processes = std::max(1u, std::thread::hardware_concurrency() * 2 - 1); settings.verbose = 0; bool write_compilation_database{false}; std::string compilation_database; - - if(argc > 1 && std::string(argv[1]) == "configure") - { - return configure(argc, argv, settings); - } + bool print_configure_cmd{false}; dg::Options opt; + int key{256}; opt.add("jobs", required_argument, 'j', "Number of parallel jobs. (default: cpucount * 2 - 1 )", @@ -370,6 +443,13 @@ int main(int argc, char* argv[]) return 0; }); + opt.add("configure-cmd", no_argument, key++, + "Print commandline for last configure.", + [&]() { + print_configure_cmd = true; + return 0; + }); + opt.add("database", required_argument, 'd', "Write compilation database json file.", [&]() { @@ -421,6 +501,12 @@ int main(int argc, char* argv[]) istr << "\n]\n"; } + if(print_configure_cmd) + { + std::cout << getConfiguration("cmd") << "\n"; + return 0; + } + for(auto task : tasks) { if(task->registerDepTasks(tasks)) |