| 1305 | } |
| 1306 | |
| 1307 | std::string cmLocalUnixMakefileGenerator3::CreateMakeVariable( |
| 1308 | std::string const& s, std::string const& s2) |
| 1309 | { |
| 1310 | std::string unmodified = cmStrCat(s, s2); |
| 1311 | // if there is no restriction on the length of make variables |
| 1312 | // and there are no "." characters in the string, then return the |
| 1313 | // unmodified combination. |
| 1314 | if ((!this->MakefileVariableSize && |
| 1315 | unmodified.find('.') == std::string::npos) && |
| 1316 | (!this->MakefileVariableSize && |
| 1317 | unmodified.find('+') == std::string::npos) && |
| 1318 | (!this->MakefileVariableSize && |
| 1319 | unmodified.find('-') == std::string::npos)) { |
| 1320 | return unmodified; |
| 1321 | } |
| 1322 | |
| 1323 | // see if the variable has been defined before and return |
| 1324 | // the modified version of the variable |
| 1325 | auto i = this->MakeVariableMap.find(unmodified); |
| 1326 | if (i != this->MakeVariableMap.end()) { |
| 1327 | return i->second; |
| 1328 | } |
| 1329 | // start with the unmodified variable |
| 1330 | std::string ret = unmodified; |
| 1331 | // if this there is no value for this->MakefileVariableSize then |
| 1332 | // the string must have bad characters in it |
| 1333 | if (!this->MakefileVariableSize) { |
| 1334 | std::replace(ret.begin(), ret.end(), '.', '_'); |
| 1335 | cmSystemTools::ReplaceString(ret, "-", "__"); |
| 1336 | cmSystemTools::ReplaceString(ret, "+", "___"); |
| 1337 | int ni = 0; |
| 1338 | char buffer[12]; |
| 1339 | // make sure the _ version is not already used, if |
| 1340 | // it is used then add number to the end of the variable |
| 1341 | while (this->ShortMakeVariableMap.count(ret) && ni < 1000) { |
| 1342 | ++ni; |
| 1343 | snprintf(buffer, sizeof(buffer), "%04d", ni); |
| 1344 | ret = unmodified + buffer; |
| 1345 | } |
| 1346 | this->ShortMakeVariableMap[ret] = "1"; |
| 1347 | this->MakeVariableMap[unmodified] = ret; |
| 1348 | return ret; |
| 1349 | } |
| 1350 | |
| 1351 | // if the string is greater than 32 chars it is an invalid variable name |
| 1352 | // for borland make |
| 1353 | if (static_cast<int>(ret.size()) > this->MakefileVariableSize) { |
| 1354 | int keep = this->MakefileVariableSize - 8; |
| 1355 | int size = keep + 3; |
| 1356 | std::string str1 = s; |
| 1357 | std::string str2 = s2; |
| 1358 | // we must shorten the combined string by 4 characters |
| 1359 | // keep no more than 24 characters from the second string |
| 1360 | if (static_cast<int>(str2.size()) > keep) { |
| 1361 | str2 = str2.substr(0, keep); |
| 1362 | } |
| 1363 | if (static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size) { |
| 1364 | str1 = str1.substr(0, size - str2.size()); |