@@ -369,20 +369,24 @@ std::string CompileOtherLanguage(std::string path, DriverOptions &driver) {
369
369
return {};
370
370
}
371
371
372
- void Link (std::vector<std::string> &relocatables, DriverOptions &driver) {
372
+ void Link (std::vector<std::string> &liblist, std::vector<std::string> &objects,
373
+ DriverOptions &driver) {
373
374
if (!ParentProcess ()) {
374
375
std::vector<char *> argv;
375
376
for (size_t j{0 }; j < driver.F18_FCArgs .size (); ++j) {
376
377
argv.push_back (driver.F18_FCArgs [j].data ());
377
378
}
378
- for (auto &relo : relocatables ) {
379
- argv.push_back (relo .data ());
379
+ for (auto &obj : objects ) {
380
+ argv.push_back (obj .data ());
380
381
}
381
382
if (!driver.outputPath .empty ()) {
382
383
char dashO[3 ] = " -o" ;
383
384
argv.push_back (dashO);
384
385
argv.push_back (driver.outputPath .data ());
385
386
}
387
+ for (auto &lib : liblist) {
388
+ argv.push_back (lib.data ());
389
+ }
386
390
Exec (argv, driver.verbose );
387
391
}
388
392
}
@@ -397,6 +401,7 @@ int main(int argc, char *const argv[]) {
397
401
bool isPGF90{driver.F18_FCArgs .back ().rfind (" pgf90" ) != std::string::npos};
398
402
399
403
std::list<std::string> args{argList (argc, argv)};
404
+ std::vector<std::string> objlist, liblist;
400
405
std::string prefix{args.front ()};
401
406
args.pop_front ();
402
407
prefix += " : " ;
@@ -413,32 +418,37 @@ int main(int argc, char *const argv[]) {
413
418
414
419
Fortran::common::IntrinsicTypeDefaultKinds defaultKinds;
415
420
416
- std::vector<std::string> fortranSources, otherSources, relocatables ;
421
+ std::vector<std::string> fortranSources, otherSources;
417
422
bool anyFiles{false };
418
423
419
424
while (!args.empty ()) {
420
425
std::string arg{std::move (args.front ())};
426
+ auto dot{arg.rfind (" ." )};
427
+ std::string suffix{arg.substr (dot + 1 )};
428
+ std::string prefix{arg.substr (0 , 2 )};
421
429
args.pop_front ();
422
430
if (arg.empty ()) {
423
431
} else if (arg.at (0 ) != ' -' ) {
424
432
anyFiles = true ;
425
- auto dot{arg.rfind (" ." )};
426
433
if (dot == std::string::npos) {
427
434
driver.F18_FCArgs .push_back (arg);
428
435
} else {
429
- std::string suffix{arg.substr (dot + 1 )};
430
436
if (suffix == " f" || suffix == " F" || suffix == " ff" ||
431
437
suffix == " f90" || suffix == " F90" || suffix == " ff90" ||
432
438
suffix == " f95" || suffix == " F95" || suffix == " ff95" ||
433
439
suffix == " cuf" || suffix == " CUF" || suffix == " f18" ||
434
440
suffix == " F18" || suffix == " ff18" ) {
435
441
fortranSources.push_back (arg);
436
- } else if (suffix == " o" || suffix == " a" ) {
437
- relocatables.push_back (arg);
442
+ } else if (suffix == " o" || suffix == " so" ) {
443
+ objlist.push_back (arg);
444
+ } else if (suffix == " a" ) {
445
+ liblist.push_back (arg);
438
446
} else {
439
447
otherSources.push_back (arg);
440
448
}
441
449
}
450
+ } else if (prefix == " -l" || suffix == " a" ) {
451
+ liblist.push_back (arg);
442
452
} else if (arg == " -" ) {
443
453
fortranSources.push_back (" -" );
444
454
} else if (arg == " --" ) {
@@ -682,17 +692,17 @@ int main(int argc, char *const argv[]) {
682
692
for (const auto &path : fortranSources) {
683
693
std::string relo{CompileFortran (path, options, driver, defaultKinds)};
684
694
if (!driver.compileOnly && !relo.empty ()) {
685
- relocatables .push_back (relo);
695
+ objlist .push_back (relo);
686
696
}
687
697
}
688
698
for (const auto &path : otherSources) {
689
699
std::string relo{CompileOtherLanguage (path, driver)};
690
700
if (!driver.compileOnly && !relo.empty ()) {
691
- relocatables .push_back (relo);
701
+ objlist .push_back (relo);
692
702
}
693
703
}
694
- if (!relocatables .empty ()) {
695
- Link (relocatables , driver);
704
+ if (!objlist .empty ()) {
705
+ Link (liblist, objlist , driver);
696
706
}
697
707
return exitStatus;
698
708
}
0 commit comments