summaryrefslogtreecommitdiff
path: root/configure.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-06-23 21:13:39 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-06-23 21:13:39 +0200
commitf834093a8904a076f248d0f7034b66bbe0a5087f (patch)
tree2b4deb11ecadc54c74fcd6c0ad03c1616e3d2bf6 /configure.cc
parentc21a9c55382b930ffeea5042aa7e0dd48b453c4a (diff)
Add configure checks for programs and be more consistent with the use of the phrases build and host systems (inspired by autotools).
Diffstat (limited to 'configure.cc')
-rw-r--r--configure.cc161
1 files changed, 152 insertions, 9 deletions
diff --git a/configure.cc b/configure.cc
index 1979936..c19910e 100644
--- a/configure.cc
+++ b/configure.cc
@@ -38,6 +38,57 @@ const std::string& getConfiguration(const std::string& key,
return defaultValue;
}
+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 {};
+}
+
int configure(int argc, char* argv[])
{
Settings settings;
@@ -58,7 +109,13 @@ int configure(int argc, char* argv[])
int key{128};
std::string build_arch;
+ std::string build_path;
std::string host_arch;
+ std::string host_path;
+ std::string cc_prog = "gcc";
+ std::string cxx_prog = "g++";
+ std::string ar_prog = "ar";
+ std::string ld_prog = "ld";
opt.add("build-dir", required_argument, 'b',
"Set output directory for build files (default: '" +
@@ -75,6 +132,34 @@ int configure(int argc, char* argv[])
return 0;
});
+ opt.add("cc", required_argument, key++,
+ "Use specified c-compiler instead of gcc.",
+ [&]() {
+ cc_prog = optarg;
+ return 0;
+ });
+
+ opt.add("cxx", required_argument, key++,
+ "Use specified c++-compiler instead of g++.",
+ [&]() {
+ cxx_prog = optarg;
+ return 0;
+ });
+
+ opt.add("ar", required_argument, key++,
+ "Use specified archiver instead of ar.",
+ [&]() {
+ ar_prog = optarg;
+ return 0;
+ });
+
+ opt.add("ld", required_argument, key++,
+ "Use specified linker instead of ld.",
+ [&]() {
+ ld_prog = optarg;
+ return 0;
+ });
+
opt.add("build", required_argument, key++,
"Configure for building on specified architecture.",
[&]() {
@@ -82,6 +167,13 @@ int configure(int argc, char* argv[])
return 0;
});
+ opt.add("build-path", required_argument, key++,
+ "Set path to build tool-chain.",
+ [&]() {
+ build_path = optarg;
+ return 0;
+ });
+
opt.add("host", required_argument, key++,
"Cross-compile to build programs to run on specified architecture.",
[&]() {
@@ -89,6 +181,13 @@ int configure(int argc, char* argv[])
return 0;
});
+ opt.add("host-path", required_argument, key++,
+ "Set path to cross-compile tool-chain.",
+ [&]() {
+ host_path = optarg;
+ return 0;
+ });
+
opt.add("help", no_argument, 'h',
"Print this help text.",
[&]() {
@@ -106,10 +205,11 @@ int configure(int argc, char* argv[])
}
auto tasks = getTasks(settings);
-
+/*
bool needs_cpp{false};
bool needs_c{false};
bool needs_ar{false};
+ bool needs_asm{false};
for(const auto& task :tasks)
{
switch(task->sourceLanguage())
@@ -124,8 +224,44 @@ int configure(int argc, char* argv[])
case Language::Cpp:
needs_c = true;
break;
+ case Language::Asm:
+ needs_asm = true;
+ break;
}
}
+*/
+ auto cc_env = getenv("CC");
+ if(cc_env)
+ {
+ cc_prog = cc_env;
+ }
+
+ auto cxx_env = getenv("CXX");
+ if(cxx_env)
+ {
+ cxx_prog = cxx_env;
+ }
+
+ auto ar_env = getenv("AR");
+ if(ar_env)
+ {
+ ar_prog = ar_env;
+ }
+
+ auto ld_env = getenv("LD");
+ if(ld_env)
+ {
+ ld_prog = ld_env;
+ }
+
+ std::string host_cc = locate(host_arch, cc_prog);
+ std::string host_cxx = locate(host_arch, cxx_prog);
+ std::string host_ar = locate(host_arch, ar_prog);
+ std::string host_ld = locate(host_arch, ld_prog);
+ std::string build_cc = locate(build_arch, cc_prog);
+ std::string build_cxx = locate(build_arch, cxx_prog);
+ std::string build_ar = locate(build_arch, ar_prog);
+ std::string build_ld = locate(build_arch, ld_prog);
{
std::ofstream istr(configurationFile);
@@ -136,18 +272,25 @@ int configure(int argc, char* argv[])
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 << " { \"" << 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 << " };\n";
istr << " return c;\n";
istr << "}\n";
}
+ {
+ std::ofstream istr(configHeaderFile);
+ istr << "#pragma once\n\n";
+ istr << "#define HAS_FOO 1\n";
+ istr << "//#define HAS_BAR 1\n";
+ }
+
return 0;
}