From 604517928701b3ef2783ede9a0b3b2f80c92ec92 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 Jan 2013 16:03:52 +0200 Subject: Handle -x option in default options file This can be used, for example, to override the g++ executable path. --- odb/odb.cxx | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/odb/odb.cxx b/odb/odb.cxx index 260f9b8..73aa6bd 100644 --- a/odb/odb.cxx +++ b/odb/odb.cxx @@ -226,6 +226,16 @@ main (int argc, char* argv[]) args.push_back ("g++"); #endif // GXX_NAME + // Default options. + // + args.push_back ("-x"); + args.push_back ("c++"); + args.push_back (""); // Reserve space for -std=c++XX. + args.push_back ("-S"); + args.push_back ("-Wunknown-pragmas"); + args.push_back ("-Wno-deprecated"); + args.push_back ("-fplugin=" + plugin.string ()); + // Parse the default options file if we have one. // strings def_inc_dirs; @@ -246,14 +256,42 @@ main (int argc, char* argv[]) const char* av[4] = {argv[0], "--file", file.string ().c_str (), 0}; cli::argv_file_scanner s (ac, const_cast (av), "--file"); + bool first_x (true); + while (s.more ()) { string a (s.next ()); size_t n (a.size ()); + // -x + // + if (a == "-x") + { + if (!s.more () || (a = s.next ()).empty ()) + { + e << file << ": error: expected argument for the " << a + << " option" << endl; + return 1; + } + + if (first_x) + { + first_x = false; + + // If it doesn't start with '-', then it must be the g++ + // executable name. Update the first argument with it. + // + if (a[0] != '-') + args[0] = a; + else + args.push_back (a); + } + else + args.push_back (a); + } // -I // - if (n > 1 && a[0] == '-' && a[1] == 'I') + else if (n > 1 && a[0] == '-' && a[1] == 'I') { def_inc_dirs.push_back (a); @@ -329,16 +367,6 @@ main (int argc, char* argv[]) } #endif - // Default options. - // - args.push_back ("-x"); - args.push_back ("c++"); - args.push_back (""); // Reserve space for -std=c++XX. - args.push_back ("-S"); - args.push_back ("-Wunknown-pragmas"); - args.push_back ("-Wno-deprecated"); - args.push_back ("-fplugin=" + plugin.string ()); - // Add the default preprocessor defines (-D/-U) before the user-supplied // ones. // -- cgit v1.1