@@ -66,16 +66,31 @@ namespace printer {
66
66
}
67
67
}
68
68
69
- static void removeLinkerFlag (std::string &argument, std::string const &flag) {
69
+ static bool removeLinkerFlag (std::string &argument, std::string const &flag, bool isFlagNext ) {
70
70
auto options = StringUtils::split (argument, ' ,' );
71
71
size_t erased = CollectionUtils::erase_if (options, [&flag](std::string const &option) {
72
- return StringUtils::startsWith (option, flag);
72
+ return StringUtils::startsWith (option, flag + ' = ' );
73
73
});
74
+ std::vector<std::string> result;
75
+ for (std::string const &option : options) {
76
+ if (option == flag) {
77
+ isFlagNext = true ;
78
+ erased++;
79
+ continue ;
80
+ }
81
+ if (isFlagNext && option != " -Wl" ) {
82
+ isFlagNext = false ;
83
+ erased++;
84
+ continue ;
85
+ }
86
+ result.push_back (option);
87
+ }
74
88
if (erased == 0 ) {
75
- return ;
89
+ return false ;
76
90
}
77
- argument = StringUtils::joinWith (options , " ," );
91
+ argument = StringUtils::joinWith (result , " ," );
78
92
eraseIfWlOnly (argument);
93
+ return isFlagNext;
79
94
}
80
95
81
96
// transforms -Wl,<arg>,<arg2>... to <arg> <arg2>...
@@ -92,27 +107,12 @@ namespace printer {
92
107
argument = StringUtils::joinWith (options, " " );
93
108
}
94
109
95
- static void removeScriptFlag (std::string &argument) {
96
- removeLinkerFlag (argument, " --version-script" );
110
+ static bool removeScriptFlag (std::string &argument, bool isFlagNext ) {
111
+ return removeLinkerFlag (argument, " --version-script" , isFlagNext );
97
112
}
98
113
99
- static void removeSonameFlag (std::string &argument) {
100
- auto options = StringUtils::split (argument, ' ,' );
101
- bool isSonameNext = false ;
102
- std::vector<std::string> result;
103
- for (std::string const &option : options) {
104
- if (option == " -soname" ) {
105
- isSonameNext = true ;
106
- continue ;
107
- }
108
- if (isSonameNext) {
109
- isSonameNext = false ;
110
- continue ;
111
- }
112
- result.push_back (option);
113
- }
114
- argument = StringUtils::joinWith (result, " ," );
115
- eraseIfWlOnly (argument);
114
+ static bool removeSonameFlag (std::string &argument, bool isFlagNext) {
115
+ return removeLinkerFlag (argument, " -soname" , isFlagNext);
116
116
}
117
117
118
118
NativeMakefilePrinter::NativeMakefilePrinter (
@@ -378,9 +378,10 @@ namespace printer {
378
378
StringUtils::startsWith (argument, libraryDirOption) ||
379
379
StringUtils::startsWith (argument, linkFlag);
380
380
});
381
+ bool isScriptNext = false , isSonameNext = false ;
381
382
for (std::string &argument : dynamicLinkCommand.getCommandLine ()) {
382
- removeScriptFlag (argument);
383
- removeSonameFlag (argument);
383
+ isScriptNext = removeScriptFlag (argument, isScriptNext );
384
+ isSonameNext = removeSonameFlag (argument, isSonameNext );
384
385
}
385
386
dynamicLinkCommand.setOptimizationLevel (OPTIMIZATION_FLAG);
386
387
dynamicLinkCommand.addFlagsToBegin (
@@ -539,9 +540,10 @@ namespace printer {
539
540
CompilationUtils::getCompilerName (linkCommand.getBuildTool ())));
540
541
}
541
542
std::vector <std::string> libraryDirectoriesFlags;
543
+ bool isScriptNext = false , isSonameNext = false ;
542
544
for (std::string &argument : linkCommand.getCommandLine ()) {
543
- removeScriptFlag (argument);
544
- removeSonameFlag (argument);
545
+ isScriptNext = removeScriptFlag (argument, isScriptNext );
546
+ isSonameNext = removeSonameFlag (argument, isSonameNext );
545
547
auto optionalLibraryAbsolutePath =
546
548
getLibraryAbsolutePath (argument, linkCommand.getDirectory ());
547
549
if (optionalLibraryAbsolutePath.has_value ()) {
0 commit comments