@@ -336,31 +336,34 @@ make_regexp (const char *triplet_regexp, const char *compiler)
{
std::stringstream buf;
- buf << "^" << triplet_regexp << "-";
+ buf << "^" << triplet_regexp;
- // Quote the compiler name in case it has something funny in it.
- for (const char *p = compiler; *p; ++p)
+ if (compiler[0] != '\0')
{
- switch (*p)
+ // Quote the compiler name in case it has something funny in it.
+ for (const char *p = compiler; *p; ++p)
{
- case '.':
- case '^':
- case '$':
- case '*':
- case '+':
- case '?':
- case '(':
- case ')':
- case '[':
- case '{':
- case '\\':
- case '|':
- buf << '\\';
- break;
+ switch (*p)
+ {
+ case '.':
+ case '^':
+ case '$':
+ case '*':
+ case '+':
+ case '?':
+ case '(':
+ case ')':
+ case '[':
+ case '{':
+ case '\\':
+ case '|':
+ buf << '\\';
+ break;
+ }
+ buf << *p;
}
- buf << *p;
+ buf << "$";
}
- buf << "$";
return buf.str ();
}
@@ -382,12 +385,30 @@ libcc1::compiler::find (std::string &compiler ATTRIBUTE_UNUSED) const
char *
libcc1::compiler_triplet_regexp::find (std::string &compiler) const
{
- std::string rx = make_regexp (triplet_regexp_.c_str (), C_COMPILER_NAME);
+ regex_t triplet;
+ bool c_compiler_has_triplet = false;
+
+ // Some distros, like Debian, choose to use a prefix and a suffix
+ // in their C_COMPILER_NAME, so we try to check if that's the case
+ // here and adjust the regexp's accordingly.
+ std::string triplet_rx = make_regexp (triplet_regexp_.c_str (), "");
+ int code = regcomp (&triplet, triplet_rx.c_str (), REG_EXTENDED | REG_NOSUB);
+
+ if (code == 0)
+ {
+ if (regexec (&triplet, C_COMPILER_NAME, 0, NULL, 0) == 0)
+ c_compiler_has_triplet = true;
+
+ regfree (&triplet);
+ }
+
+ std::string rx = make_regexp (c_compiler_has_triplet
+ ? "" : triplet_regexp_.c_str (),
+ C_COMPILER_NAME);
if (self_->verbose)
fprintf (stderr, _("searching for compiler matching regex %s\n"),
rx.c_str());
- regex_t triplet;
- int code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
+ code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
if (code != 0)
{
size_t len = regerror (code, &triplet, NULL, 0);
@@ -360,31 +360,34 @@ make_regexp (const char *triplet_regexp, const char *compiler)
{
std::stringstream buf;
- buf << "^" << triplet_regexp << "-";
+ buf << "^" << triplet_regexp;
- // Quote the compiler name in case it has something funny in it.
- for (const char *p = compiler; *p; ++p)
+ if (compiler[0] != '\0')
{
- switch (*p)
+ // Quote the compiler name in case it has something funny in it.
+ for (const char *p = compiler; *p; ++p)
{
- case '.':
- case '^':
- case '$':
- case '*':
- case '+':
- case '?':
- case '(':
- case ')':
- case '[':
- case '{':
- case '\\':
- case '|':
- buf << '\\';
- break;
+ switch (*p)
+ {
+ case '.':
+ case '^':
+ case '$':
+ case '*':
+ case '+':
+ case '?':
+ case '(':
+ case ')':
+ case '[':
+ case '{':
+ case '\\':
+ case '|':
+ buf << '\\';
+ break;
+ }
+ buf << *p;
}
- buf << *p;
+ buf << "$";
}
- buf << "$";
return buf.str ();
}
@@ -406,12 +409,30 @@ libcp1::compiler::find (std::string &compiler ATTRIBUTE_UNUSED) const
char *
libcp1::compiler_triplet_regexp::find (std::string &compiler) const
{
- std::string rx = make_regexp (triplet_regexp_.c_str (), CP_COMPILER_NAME);
+ regex_t triplet;
+ bool cp_compiler_name_has_triplet = false;
+
+ // Some distros, like Debian, choose to use a prefix and a suffix
+ // in their CP_COMPILER_NAME, so we try to check if that's the case
+ // here and adjust the regexp's accordingly.
+ std::string triplet_rx = make_regexp (triplet_regexp_.c_str (), "");
+ int code = regcomp (&triplet, triplet_rx.c_str (), REG_EXTENDED | REG_NOSUB);
+
+ if (code == 0)
+ {
+ if (regexec (&triplet, CP_COMPILER_NAME, 0, NULL, 0) == 0)
+ cp_compiler_name_has_triplet = true;
+
+ regfree (&triplet);
+ }
+
+ std::string rx = make_regexp (cp_compiler_name_has_triplet
+ ? "" : triplet_regexp_.c_str (),
+ CP_COMPILER_NAME);
if (self_->verbose)
fprintf (stderr, _("searching for compiler matching regex %s\n"),
rx.c_str());
- regex_t triplet;
- int code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
+ code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
if (code != 0)
{
size_t len = regerror (code, &triplet, NULL, 0);