Skip to content

Remove -soname and --version-script flags from generated makefiles #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions server/src/printers/NativeMakefilePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,31 @@ namespace printer {
}
}

static void removeLinkerFlag(std::string &argument, std::string const &flag) {
static bool removeLinkerFlag(std::string &argument, std::string const &flag, bool isFlagNext) {
auto options = StringUtils::split(argument, ',');
size_t erased = CollectionUtils::erase_if(options, [&flag](std::string const &option) {
return StringUtils::startsWith(option, flag);
return StringUtils::startsWith(option, flag + '=');
});
std::vector<std::string> result;
for (std::string const &option : options) {
if (option == flag) {
isFlagNext = true;
erased++;
continue;
}
if (isFlagNext && option != "-Wl") {
isFlagNext = false;
erased++;
continue;
}
result.push_back(option);
}
if (erased == 0) {
return;
return false;
}
argument = StringUtils::joinWith(options, ",");
argument = StringUtils::joinWith(result, ",");
eraseIfWlOnly(argument);
return isFlagNext;
}

// transforms -Wl,<arg>,<arg2>... to <arg> <arg2>...
Expand All @@ -92,27 +107,12 @@ namespace printer {
argument = StringUtils::joinWith(options, " ");
}

static void removeScriptFlag(std::string &argument) {
removeLinkerFlag(argument, "--version-script");
static bool removeScriptFlag(std::string &argument, bool isFlagNext) {
return removeLinkerFlag(argument, "--version-script", isFlagNext);
}

static void removeSonameFlag(std::string &argument) {
auto options = StringUtils::split(argument, ',');
bool isSonameNext = false;
std::vector<std::string> result;
for (std::string const &option : options) {
if (option == "-soname") {
isSonameNext = true;
continue;
}
if (isSonameNext) {
isSonameNext = false;
continue;
}
result.push_back(option);
}
argument = StringUtils::joinWith(result, ",");
eraseIfWlOnly(argument);
static bool removeSonameFlag(std::string &argument, bool isFlagNext) {
return removeLinkerFlag(argument, "-soname", isFlagNext);
}

NativeMakefilePrinter::NativeMakefilePrinter(
Expand Down Expand Up @@ -378,9 +378,10 @@ namespace printer {
StringUtils::startsWith(argument, libraryDirOption) ||
StringUtils::startsWith(argument, linkFlag);
});
bool isScriptNext = false, isSonameNext = false;
for (std::string &argument : dynamicLinkCommand.getCommandLine()) {
removeScriptFlag(argument);
removeSonameFlag(argument);
isScriptNext = removeScriptFlag(argument, isScriptNext);
isSonameNext = removeSonameFlag(argument, isSonameNext);
}
dynamicLinkCommand.setOptimizationLevel(OPTIMIZATION_FLAG);
dynamicLinkCommand.addFlagsToBegin(
Expand Down Expand Up @@ -539,9 +540,10 @@ namespace printer {
CompilationUtils::getCompilerName(linkCommand.getBuildTool())));
}
std::vector <std::string> libraryDirectoriesFlags;
bool isScriptNext = false, isSonameNext = false;
for (std::string &argument : linkCommand.getCommandLine()) {
removeScriptFlag(argument);
removeSonameFlag(argument);
isScriptNext = removeScriptFlag(argument, isScriptNext);
isSonameNext = removeSonameFlag(argument, isSonameNext);
auto optionalLibraryAbsolutePath =
getLibraryAbsolutePath(argument, linkCommand.getDirectory());
if (optionalLibraryAbsolutePath.has_value()) {
Expand Down