1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
|
/*
Copyright (C) 2018, 2019, 2020, 2021 Free Software Foundation, Inc.
Written by: Gregory John Casamento <greg.casamento@gmail.com>
Date: 2022
This file is part of the GNUstep XCode Library
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/
#import "PBXCommon.h"
#import "PBXFrameworksBuildPhase.h"
#import "PBXFileReference.h"
#import "PBXBuildFile.h"
#import "GSXCBuildContext.h"
#import "NSArray+Additions.h"
#import "NSString+PBXAdditions.h"
#import "PBXTarget.h"
#import "GSXCCommon.h"
#import <Foundation/NSPathUtilities.h>
@implementation PBXFrameworksBuildPhase
- (NSString *) _gsConfigString
{
NSString *configString = nil;
configString = @"gnustep-config";
return configString;
}
- (NSString *) linkerForBuild
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
BOOL linkWithCpp = [[context objectForKey: @"LINK_WITH_CPP"] isEqualToString: @"YES"];
NSString *compiler = [NSString stringWithFormat: @"`%@ --variable=CC`", [self _gsConfigString]];
if (linkWithCpp)
{
compiler = [NSString stringWithFormat: @"`%@ --variable=CXX`", [self _gsConfigString]];
}
return compiler;
}
- (NSString *) processOutputFilesString
{
NSString *outputFiles = [[GSXCBuildContext sharedBuildContext] objectForKey:
@"OUTPUT_FILES"];
return outputFiles;
}
- (void) generateDummyClass
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSString *executableName = [context objectForKey: @"EXECUTABLE_NAME"];
NSString *outputDir = [[context objectForKey: @"PROJECT_ROOT"]
stringByAppendingPathComponent: @"derived_src"];
NSString *fileName = [NSString stringWithFormat: @"NSFramework_%@.m",executableName];
NSString *outputPath = [outputDir stringByAppendingPathComponent: fileName];
NSString *buildDir = [context objectForKey: @"TARGET_BUILD_DIR"];
NSString *objDir = [context objectForKey: @"BUILT_PRODUCTS_DIR"];
NSString *scriptPath = [[NSBundle bundleForClass: [self class]]
pathForResource: @"create-dummy-class" ofType: @"sh"];
NSString *of = [self processOutputFilesString];
NSString *outputFiles = (of == nil)?@"":of;
NSString *files = [outputFiles stringByReplacingOccurrencesOfString: @"'" withString: @""];
objDir = (objDir == nil) ? buildDir : objDir;
BOOL f = NO;
NSString *classesCommand = [NSString stringWithFormat: @"%@ '%@' '%@'", scriptPath, files, executableName];
// NSLog(@"classesCommand = %@\n", classesCommand); // [context currentContext]);
f = xcsystem(classesCommand) == 0;
if( f )
{
NSString *compiler = nil;
NSString *buildPath = outputPath;
NSString *objPath = [objDir stringByAppendingPathComponent: [fileName stringByAppendingString: @".o"]];
if([compiler isEqualToString: @""] || compiler == nil)
{
compiler = [self linkerForBuild];
}
NSString *configString = [context objectForKey: @"CONFIG_STRING"];
NSString *buildTemplate = @"%@ %@ -c %@ -o %@";
NSString *buildCommand = [NSString stringWithFormat: buildTemplate,
compiler,
[buildPath stringByEscapingSpecialCharacters],
configString,
[objPath stringByEscapingSpecialCharacters]];
NSString *of = [self processOutputFilesString];
NSString *outputFiles = (of == nil)?@"":of;
//NSLog(@"\t%@ %@",buildCommand, outputFiles);
BOOL success = xcsystem(buildCommand) == 0;
if (success)
{
outputFiles = [outputFiles stringByAppendingString: [NSString stringWithFormat: @" %@", objPath]];
[context setObject: outputFiles forKey: @"OUTPUT_FILES"];
}
else
{
NSLog(@"** build of framework dummy class failed.");
}
}
else
{
NSLog(@"** failed to run dummy class generation script");
}
}
- (NSString *) frameworkLinkString: (NSString*)framework
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSString *path = [[NSBundle bundleForClass: [self class]]
pathForResource: @"Framework-mapping" ofType: @"plist"];
NSDictionary *propList = [[NSString stringWithContentsOfFile: path] propertyList];
NSMutableArray *ignored = [[propList objectForKey: @"Ignored"] mutableCopy];
NSMutableDictionary *mapped = [[propList objectForKey: @"Mapped"] mutableCopy];
NSDictionary *configDict = [context configForTargetName: [[self target] name]];
NSString *result = nil;
NSString *fw = [framework copy];
if ([fw hasPrefix: @"lib"])
{
fw = [fw stringByReplacingCharactersInRange: NSMakeRange(0,3)
withString: @""];
}
NSDebugLog(@"\t* config = %@", configDict);
NSDebugLog(@"\t* target = %@", [[self target] name]);
if ([configDict objectForKey: @"mapped"] != nil)
{
[mapped addEntriesFromDictionary: [configDict objectForKey: @"mapped"]];
}
if ([configDict objectForKey: @"ignored"] != nil)
{
[ignored addObjectsFromArray: [configDict objectForKey: @"ignored"]];
}
NSDebugLog(@"path = %@", path);
NSDebugLog(@"%@", fw);
if ([ignored containsObject: fw])
{
xcprintf("\t- Ignored: %s\n",[fw cString]);
return @"";
}
else
{
NSDebugLog(@"%@ not found in %@", fw, ignored);
}
result = [mapped objectForKey: fw];
if (result == nil)
{
result = [NSString stringWithFormat: @"-l%@ ", fw];
xcprintf("\t* Linking: %s\n", [result cString]);
}
else
{
result = [result stringByAppendingString: @" "];
xcprintf("\t+ Remapped: %s -> %s\n", [fw cString], [result cString]);
}
return result;
}
- (NSString *) linkString
{
NSString *cfgString = [self _gsConfigString];
NSString *systemLibDir = [NSString stringWithFormat: @"`%@ --variable=GNUSTEP_SYSTEM_LIBRARIES`", cfgString];
NSString *localLibDir = [NSString stringWithFormat: @"`%@ --variable=GNUSTEP_LOCAL_LIBRARIES`", cfgString];
NSString *userLibDir = [NSString stringWithFormat: @"`%@ --variable=GNUSTEP_USER_LIBRARIES`", cfgString];
NSString *buildDir = [NSString stringForEnvironmentVariable: @"TARGET_BUILD_DIR" defaultValue: @"build"];
NSString *uninstalledProductsDir = [buildDir stringByAppendingPathComponent: @"Products"];
NSString *linkString = [NSString stringWithFormat: @"-L/usr/local/lib -L/opt/local/lib -L%@ -L%@ -L%@ ",
userLibDir,
localLibDir,
systemLibDir];;
NSFileManager *manager = [NSFileManager defaultManager];
NSDirectoryEnumerator *dirEnumerator = [manager enumeratorAtPath:uninstalledProductsDir];
NSEnumerator *en = [_files objectEnumerator];
id file = nil;
NSString *lpath = nil;
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSDictionary *configDict = [context configForTargetName: [[self target] name]];
NSArray *linkerPaths = [configDict objectForKey: @"linkerPaths"];
NSString *wsLink = [context objectForKey: @"WORKSPACE_LINK_LINE"];
NSString *wsLibs = [context objectForKey: @"WORKSPACE_LIBS_LINE"];
// If the workspace link string exists, add it...
if (wsLink != nil)
{
linkString = [linkString stringByAppendingString: wsLink];
NSDebugLog(@"linkString = %@", linkString);
}
if (wsLibs != nil)
{
linkString = [linkString stringByAppendingString: wsLibs];
xcprintf("\t* Linking from Workspace: %s\n", [wsLibs cString]);
NSDebugLog(@"linkString = %@", linkString);
}
en = [linkerPaths objectEnumerator];
while((lpath = [en nextObject]) != nil)
{
linkString = [linkString stringByAppendingString: [NSString stringWithFormat: @"-L%@ ", lpath]];
}
en = [_files objectEnumerator];
while((file = [en nextObject]) != nil)
{
PBXFileReference *fileRef = [file fileRef];
NSString *name = [[[fileRef path] lastPathComponent] stringByDeletingPathExtension];
linkString = [linkString stringByAppendingString: [self frameworkLinkString: name]];
}
// Find any frameworks and add them to the -L directive...
while((file = [dirEnumerator nextObject]) != nil)
{
NSString *ext = [file pathExtension];
if([ext isEqualToString:@"framework"])
{
NSString *headerDir = [file stringByAppendingPathComponent:@"Headers"];
linkString = [linkString stringByAppendingString:
[NSString stringWithFormat:@"-I%@ ",
[uninstalledProductsDir stringByAppendingPathComponent:headerDir]]];
linkString = [linkString stringByAppendingString:
[NSString stringWithFormat:@"-L%@ ",
[uninstalledProductsDir stringByAppendingPathComponent:file]]];
}
}
NSArray *otherLDFlags = [context objectForKey: @"OTHER_LDFLAGS"];
NSDebugLog(@"OTHER_LDFLAGS = %@", otherLDFlags);
en = [otherLDFlags objectEnumerator];
while((file = [en nextObject]) != nil)
{
if ([file isEqualToString: @"-framework"])
{
NSString *framework = [en nextObject];
linkString = [linkString stringByAppendingString: [self frameworkLinkString: framework]];
}
}
// linkString = [linkString stringByAppendingString: @" -lpthread -lobjc -lm "];
linkString = [linkString stringByAppendingString: @" -lobjc "];
// Do substitutions and additions for buildtool.plist...
NSDictionary *substitutionList = [configDict objectForKey: @"substitutions"];
NSArray *additionalFlags = [configDict objectForKey: @"additional"];
// NSNumber *flag = [configDict objectForKey: @"translateDylibs"];
NSDebugLog(@"%@",configDict);
NSDebugLog(@"%@", additionalFlags);
if (additionalFlags != nil)
{
[context setObject: additionalFlags forKey: @"ADDITIONAL_OBJC_LIBS"];
}
// Replace anything that needs substitution... not all libraries on macos map directly...
en = [[substitutionList allKeys] objectEnumerator];
id o = nil;
while ((o = [en nextObject]) != nil)
{
NSString *r = [substitutionList objectForKey: o];
linkString = [linkString stringByReplacingOccurrencesOfString: o
withString: r];
}
// Add any additional libs...
en = [additionalFlags objectEnumerator];
o = nil;
while ((o = [en nextObject]) != nil)
{
linkString = [linkString stringByAppendingFormat: @" %@ ", o];
xcprintf("\t+ Additional: %s\n",[o cString]);
}
return linkString;
}
- (BOOL) buildTool
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSString *cfgString = [self _gsConfigString];
xcputs([[NSString stringWithFormat: @"=== Executing Frameworks / Linking Build Phase (Tool)"] cString]);
NSString *compiler = [self linkerForBuild];
NSString *outputFiles = [self processOutputFilesString];
NSString *outputDir = [context objectForKey: @"PRODUCT_OUTPUT_DIR"];
NSString *executableName = [context objectForKey: @"EXECUTABLE_NAME"];
NSString *outputPath = [outputDir stringByAppendingPathComponent: executableName];
NSString *linkString = [self linkString];
linkString = [linkString stringByAppendingString: [NSString stringWithFormat:
@" `%@ --base-libs` `%@ --variable=LDFLAGS` -lgnustep-base ",
cfgString, cfgString]];
NSProcessInfo *pi = [NSProcessInfo processInfo];
NSUInteger os = [pi operatingSystem];
NSString *command = [NSString stringWithFormat:
@"%@ -rdynamic -shared-libgcc -fgnu-runtime -o \"%@\" %@ %@",
compiler,
outputPath,
outputFiles,
linkString];
if (os == NSWindowsNTOperatingSystem || os == NSWindows95OperatingSystem)
{
outputPath = [outputPath stringByAppendingPathExtension: @"exe"];
command = [NSString stringWithFormat:
@"%@ -shared-libgcc -fgnu-runtime -o \"%@\" %@ %@",
compiler,
outputPath,
outputFiles,
linkString];
}
NSDebugLog(@"command = %@", command);
NSString *modified = [context objectForKey: @"MODIFIED_FLAG"];
int result = 0;
if([modified isEqualToString: @"YES"])
{
result = xcsystem(command);
if (result != 0)
{
NSLog(@"%sReturn Value:%s %d", RED, RESET, result);
NSLog(@"%sCommand:%s %s%@%s", RED, RESET, GREEN, command, RESET);
}
}
else
{
xcputs([[NSString stringWithFormat: @"\t** Nothing to be done for %@, no modifications.",outputPath] cString]);
}
xcputs("=== Frameworks / Linking Build Phase Completed");
return (result == 0);
}
- (BOOL) buildApp
{
xcputs("=== Executing Frameworks / Linking Build Phase (Application)");
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSString *compiler = [self linkerForBuild];
NSString *outputFiles = [self processOutputFilesString];
NSString *outputDir = [context objectForKey: @"PRODUCT_OUTPUT_DIR"];
// NSString *errorPath = [outputDir stringByAppendingPathComponent: @"linker.err"];
NSString *executableName = [context objectForKey: @"EXECUTABLE_NAME"];
NSString *outputPath = [outputDir stringByAppendingPathComponent: executableName];
NSString *linkString = [self linkString];
NSString *cfgString = [self _gsConfigString];
NSProcessInfo *pi = [NSProcessInfo processInfo];
NSUInteger os = [pi operatingSystem];
NSDebugLog(@"Output files = %@", outputFiles);
if (outputFiles == nil)
{
xcputs("\t++++ No object files found. Nothing to link ++++\n");
return YES;
}
linkString = [NSString stringWithFormat: [linkString stringByAppendingString: @" `%@ --objc-flags --objc-libs " \
@"--base-libs --gui-libs` `%@ --variable=LDFLAGS` " \
@"-lgnustep-base -lgnustep-gui "], cfgString, cfgString];
NSDebugLog(@"LINK: %@", linkString);
NSString *command = nil;
if (os == NSWindowsNTOperatingSystem || os == NSWindows95OperatingSystem)
{
outputPath = [outputPath stringByAppendingPathExtension: @"exe"];
command = [NSString stringWithFormat:
@"%@ -shared-libgcc -fgnu-runtime -o \"%@\" %@ %@",
compiler,
outputPath,
outputFiles,
linkString];
}
else
{
command = [NSString stringWithFormat:
@"%@ -rdynamic -shared-libgcc -fgnu-runtime -o \"%@\" %@ %@",
compiler,
outputPath,
outputFiles,
linkString];
}
// NSLog(@"Link command = %@", command);
// NSString *modified = [context objectForKey: @"MODIFIED_FLAG"];
int result = 0;
if(YES) // [modified isEqualToString: @"YES"])
{
xcputs([[NSString stringWithFormat: @"\t* Linking \"%@\"",outputPath] cString]);
result = xcsystem(command);
}
else
{
xcputs([[NSString stringWithFormat: @"\t** Nothing to be done for \"%@\", no modifications.",outputPath] cString]);
}
xcputs("=== Frameworks / Linking Build Phase Completed");
fflush(stdout);
return (result == 0);
}
- (NSString *) _execName
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSString *name = [context objectForKey: @"EXECUTABLE_NAME"];
if( name == nil )
{
name = [context objectForKey: @"PRODUCT_NAME"];
if ( name == nil )
{
name = [context objectForKey: @"TARGET_NAME"];
}
}
return name;
}
- (NSString *) _productOutputDir
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSString *outputDir = [context objectForKey: @"PRODUCT_OUTPUT_DIR"];
if( outputDir == nil )
{
outputDir = [@"./build" stringByAppendingPathComponent: [self _execName]];
outputDir = [outputDir stringByAppendingPathComponent: @"Products"];
}
return outputDir;
}
- (BOOL) buildStaticLib
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
// NSDictionary *config = [context config];
// NSString *ctarget = [config objectForKey: @"target"];
// NSString *libext = [ctarget isEqualToString: @"msvc"] ? @"lib" : @"a";
// NSString *libpfx = [ctarget isEqualToString: @"msvc"] ? @"" : @"lib";
NSString *outputFiles = [self processOutputFilesString];
NSString *outputDir = [self _productOutputDir];
NSString *executableName = [[[_target productReference] path] lastPathComponent];
// [[NSString stringWithFormat: @"%@%@", libpfx,[self _execName]]
// stringByReplacingPathExtensionWith: libext];
NSString *outputPath = [outputDir stringByAppendingPathComponent: executableName];
NSString *commandTemplate = @"ar rc %@ %@; ranlib %@";
NSString *command = [NSString stringWithFormat: commandTemplate,
outputPath,
outputFiles,
outputPath];
NSString *modified = [context objectForKey: @"MODIFIED_FLAG"];
int result = 0;
xcputs("=== Executing Frameworks / Archiving Build Phase (Static Library)");
if([modified isEqualToString: @"YES"])
{
xcputs([[NSString stringWithFormat: @"\t* Linking %@",outputPath] cString]);
result = xcsystem(command);
}
else
{
xcputs([[NSString stringWithFormat: @"\t** Nothing to be done for %@, no modifications.",outputPath] cString]);
}
xcputs("=== Frameworks / Linking Build Phase Completed");
return (result == 0);
}
- (BOOL) buildDynamicLib
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSDictionary *config = [context config];
NSString *ctarget = [config objectForKey: @"target"];
NSString *outputFiles = [self processOutputFilesString];
NSString *modified = [context objectForKey: @"MODIFIED_FLAG"];
NSString *outputDir = [context objectForKey: @"PRODUCT_OUTPUT_DIR"];
NSString *executableName = [context objectForKey: @"EXECUTABLE_NAME"];
NSString *executableNameStripped = [executableName stringByDeletingPathExtension];
NSString *libName = [NSString stringWithFormat: @"%@.so",executableNameStripped];
NSString *outputPath = [outputDir stringByAppendingPathComponent: libName];
NSString *libraryPath = [outputDir stringByAppendingPathComponent: libName];
NSString *cfgString = [self _gsConfigString];
NSString *systemLibDir = [NSString stringWithFormat: @"`%@ --variable=GNUSTEP_SYSTEM_LIBRARIES`", cfgString];
NSString *localLibDir = [NSString stringWithFormat: @"`%@ --variable=GNUSTEP_LOCAL_LIBRARIES`", cfgString];
NSString *userLibDir = [NSString stringWithFormat: @"`%@ --variable=GNUSTEP_USER_LIBRARIES`", cfgString];
NSProcessInfo *pi = [NSProcessInfo processInfo];
NSUInteger os = [pi operatingSystem];
NSString *compiler = [self linkerForBuild];
NSString *command = nil;
NSString *commandTemplate = nil;
NSInteger result = 0;
xcputs("=== Executing Frameworks / Linking Build Phase (Dynamic Library");
if (os == NSWindowsNTOperatingSystem || os == NSWindows95OperatingSystem)
{
if ([ctarget containsString: @"msvc"])
{
outputPath = [outputPath stringByReplacingOccurrencesOfString: @"lib" withString: @""];
NSString *msvcLibname = [outputPath stringByAppendingPathExtension: @"lib"];
NSString *dllLibname = [libraryPath stringByReplacingPathExtensionWith: @"dll"];
commandTemplate = @"%@ -g -Wl,-dll -Wl,implib:%@ -o %@ %@ `gnustep-config --base-libs` "
@"-L%@ -L%@ -L%@";
libraryPath = [outputDir stringByAppendingPathComponent: msvcLibname];
command = [NSString stringWithFormat: commandTemplate,
compiler,
libraryPath,
dllLibname,
outputFiles,
userLibDir,
localLibDir,
systemLibDir];
}
else
{
commandTemplate = @"%@ -shared -Wl,-soname,lib%@.so "
@"-shared-libgcc -o %@ %@ "
@"-L%@ -L%@ -L%@";
command = [NSString stringWithFormat: commandTemplate,
compiler,
executableName,
libraryPath,
outputFiles,
userLibDir,
localLibDir,
systemLibDir];
}
}
else
{
commandTemplate = @"%@ -shared -Wl,-soname,lib%@.so -rdynamic "
@"-shared-libgcc -o %@ %@ "
@"-L%@ -L%@ -L%@";
command = [NSString stringWithFormat: commandTemplate,
compiler,
executableName,
libraryPath,
outputFiles,
userLibDir,
localLibDir,
systemLibDir];
}
if([modified isEqualToString: @"YES"])
{
xcputs([[NSString stringWithFormat: @"\t* Linking %@",outputPath] cString]);
result = xcsystem(command);
}
else
{
xcputs([[NSString stringWithFormat: @"\t** Nothing to be done for %@, no modifications.",outputPath] cString]);
}
xcputs("=== Frameworks / Linking Build Phase Completed");
return (result == 0);
}
- (BOOL) buildFramework
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSDictionary *config = [context config];
NSString *ctarget = [config objectForKey: @"target"];
NSInteger result = 0;
xcputs("=== Executing Frameworks / Linking Build Phase (Framework)");
[self generateDummyClass];
NSString *outputFiles = [self processOutputFilesString];
NSString *modified = [context objectForKey: @"MODIFIED_FLAG"];
NSString *outputDir = [context objectForKey: @"PRODUCT_OUTPUT_DIR"];
NSString *executableName = [context objectForKey: @"EXECUTABLE_NAME"];
NSString *outputPath = [outputDir stringByAppendingPathComponent: executableName];
NSString *frameworkVersion = [NSString stringForEnvironmentVariable: "FRAMEWORK_VERSION"];
if (frameworkVersion == nil)
{
frameworkVersion = @"0";
}
NSString *libNameWithVersion = [NSString stringWithFormat: @"lib%@.so.%@",
executableName,frameworkVersion];
NSString *libName = [NSString stringWithFormat: @"lib%@.so",executableName];
NSString *libraryPath = [outputDir stringByAppendingPathComponent: libNameWithVersion];
NSString *libraryPathNoVersion = [outputDir stringByAppendingPathComponent: libName];
NSString *cfgString = [self _gsConfigString];
NSString *systemLibDir = [NSString stringWithFormat: @"`%@ --variable=GNUSTEP_SYSTEM_LIBRARIES`", cfgString];
NSString *localLibDir = [NSString stringWithFormat: @"`%@ --variable=GNUSTEP_LOCAL_LIBRARIES`", cfgString];
NSString *userLibDir = [NSString stringWithFormat: @"`%@ --variable=GNUSTEP_USER_LIBRARIES`", cfgString];
NSString *frameworkRoot = [context objectForKey: @"FRAMEWORK_DIR"];
NSString *libraryLink = [frameworkRoot stringByAppendingPathComponent: libName];
NSString *execLink = [frameworkRoot stringByAppendingPathComponent: executableName];
NSProcessInfo *pi = [NSProcessInfo processInfo];
NSUInteger os = [pi operatingSystem];
NSString *compiler = [self linkerForBuild];
NSString *command = nil;
NSString *commandTemplate = nil;
if (os == NSWindowsNTOperatingSystem || os == NSWindows95OperatingSystem)
{
if ([ctarget containsString: @"msvc"])
{
NSString *msvcLibname = [outputPath stringByAppendingPathExtension: @"lib"];
NSString *dllLibname = [libraryPathNoVersion stringByReplacingPathExtensionWith: @"dll"];
commandTemplate = @"%@ -g -Wl,-dll -Wl,implib:%@ -o %@ %@ "
@"-L%@ -L%@ -L%@ "
@"`gnustep-config --gui-libs` ";
libraryPath = msvcLibname;
command = [NSString stringWithFormat: commandTemplate,
compiler,
libraryPath,
dllLibname,
outputFiles,
userLibDir,
localLibDir,
systemLibDir];
}
else
{
commandTemplate = @"%@ -shared -Wl,-soname,lib%@.so "
@"-shared-libgcc -o %@ %@ "
@"-L%@ -L%@ -L%@ "
@"`gnustep-config --gui-libs` ";
command = [NSString stringWithFormat: commandTemplate,
compiler,
executableName,
libraryPath,
outputFiles,
userLibDir,
localLibDir,
systemLibDir];
}
}
else
{
commandTemplate = @"%@ -shared -Wl,-soname,lib%@.so.%@ -rdynamic "
@"-shared-libgcc -o %@ %@ "
@"-L%@ -L%@ -L%@";
command = [NSString stringWithFormat: commandTemplate,
compiler,
executableName,
frameworkVersion,
libraryPath,
outputFiles,
userLibDir,
localLibDir,
systemLibDir];
}
// Create link to library...
[[NSFileManager defaultManager] createSymbolicLinkAtPath: outputPath
pathContent: libName];
[[NSFileManager defaultManager] createSymbolicLinkAtPath: libraryPathNoVersion
pathContent: libNameWithVersion];
[[NSFileManager defaultManager] createSymbolicLinkAtPath: libraryLink
pathContent:
[NSString stringWithFormat: @"Versions/Current/%@",libName]];
[[NSFileManager defaultManager] createSymbolicLinkAtPath: execLink
pathContent:
[NSString stringWithFormat: @"Versions/Current/%@",executableName]];
// NSLog(@"Link command = %@", command);
if([modified isEqualToString: @"YES"])
{
xcputs([[NSString stringWithFormat: @"\t* Linking %@",outputPath] cString]);
result = xcsystem(command);
}
else
{
xcputs([[NSString stringWithFormat: @"\t** Nothing to be done for %@, no modifications.",outputPath] cString]);
}
xcputs("=== Frameworks / Linking Build Phase Completed");
return (result == 0);
}
- (BOOL) buildBundle
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
xcputs("=== Executing Frameworks / Linking Build Phase (Bundle)");
NSString *compiler = [self linkerForBuild];
NSString *outputFiles = [self processOutputFilesString];
NSString *outputDir = [NSString stringWithCString: getenv("PRODUCT_OUTPUT_DIR")];
NSString *executableName = [NSString stringWithCString: getenv("EXECUTABLE_NAME")];
NSString *outputPath = [outputDir stringByAppendingPathComponent: executableName];
NSString *linkString = [self linkString];
NSProcessInfo *pi = [NSProcessInfo processInfo];
NSUInteger os = [pi operatingSystem];
NSString *command = [NSString stringWithFormat:
@"%@ -rdynamic -shared -o \"%@\" %@ %@",
compiler,
outputPath,
outputFiles,
linkString];
if (os == NSWindowsNTOperatingSystem || os == NSWindows95OperatingSystem)
{
command = [NSString stringWithFormat:
@"%@ -shared -o \"%@\" %@ %@",
compiler,
outputPath,
outputFiles,
linkString];
}
NSString *modified = [context objectForKey: @"MODIFIED_FLAG"];
int result = 0;
if([modified isEqualToString: @"YES"])
{
xcputs([[NSString stringWithFormat: @"\t* Linking %@",outputPath] cString]);
result = xcsystem(command);
}
else
{
xcputs([[NSString stringWithFormat: @"\t** Nothing to be done for %@, no modifications.",outputPath] cString]);
}
xcputs("=== Frameworks / Linking Build Phase Completed");
return (result == 0);
}
- (BOOL) buildTest
{
xcputs("=== Build tests... currently unsupported...");
return YES;
}
- (BOOL) build
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSString *productType = [context objectForKey: @"PRODUCT_TYPE"];
if([productType isEqualToString: APPLICATION_TYPE])
{
return [self buildApp];
}
else if([productType isEqualToString: TOOL_TYPE])
{
return [self buildTool];
}
else if([productType isEqualToString: LIBRARY_TYPE])
{
return [self buildStaticLib];
}
else if([productType isEqualToString: DYNAMIC_LIBRARY_TYPE])
{
return [self buildDynamicLib];
}
else if([productType isEqualToString: FRAMEWORK_TYPE])
{
return [self buildFramework];
}
else if([productType isEqualToString: BUNDLE_TYPE])
{
return [self buildBundle];
}
else if([productType isEqualToString: TEST_TYPE])
{
return [self buildTest];
}
else
{
xcputs([[NSString stringWithFormat: @"***** ERROR: Unknown product type: %@",productType] cString]);
}
return NO;
}
- (BOOL) generate
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
NSString *productType = [context objectForKey: @"PRODUCT_TYPE"];
NSDictionary *configDict = [context configForTargetName: [[self target] name]];
NSArray *additionalFlags = [configDict objectForKey: @"additional"];
NSDebugLog(@"%@", additionalFlags);
if (additionalFlags != nil)
{
[context setObject: additionalFlags forKey: @"ADDITIONAL_OBJC_LIBS"];
}
xcprintf("\t* Adding product type entry: %s\n", [productType cStringUsingEncoding: NSUTF8StringEncoding]);
if([productType isEqualToString: APPLICATION_TYPE])
{
[context setObject: @"application"
forKey: @"PROJECT_TYPE"];
}
else if([productType isEqualToString: TOOL_TYPE])
{
[context setObject: @"tool"
forKey: @"PROJECT_TYPE"];
}
else if([productType isEqualToString: LIBRARY_TYPE])
{
[context setObject: @"library"
forKey: @"PROJECT_TYPE"];
}
else if([productType isEqualToString: DYNAMIC_LIBRARY_TYPE])
{
[context setObject: @"library"
forKey: @"PROJECT_TYPE"];
}
else if([productType isEqualToString: FRAMEWORK_TYPE])
{
[context setObject: @"framework"
forKey: @"PROJECT_TYPE"];
}
else if([productType isEqualToString: BUNDLE_TYPE])
{
[context setObject: @"bundle"
forKey: @"PROJECT_TYPE"];
}
else if([productType isEqualToString: TEST_TYPE])
{
[context setObject: @"test"
forKey: @"PROJECT_TYPE"];
}
else
{
xcputs([[NSString stringWithFormat: @"***** ERROR: Unknown product type: %@",productType] cString]);
}
return YES;
}
- (BOOL) link
{
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
[context setObject: @"YES" forKey: @"MODIFIED_FLAG"];
return [self build];
}
@end
|