| 1 |
/* |
| 2 |
Copyright (C) 2018, 2019, 2020, 2021 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
Written by: Gregory John Casamento <[email protected]> |
| 5 |
Date: 2022 |
| 6 |
|
| 7 |
This file is part of the GNUstep XCode Library |
| 8 |
|
| 9 |
This library is free software; you can redistribute it and/or |
| 10 |
modify it under the terms of the GNU Lesser General Public |
| 11 |
License as published by the Free Software Foundation; either |
| 12 |
version 2 of the License, or (at your option) any later version. |
| 13 |
|
| 14 |
This library is distributed in the hope that it will be useful, |
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 |
Lesser General Public License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU Lesser General Public |
| 20 |
License along with this library; if not, write to the Free |
| 21 |
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 22 |
Boston, MA 02110 USA. |
| 23 |
*/ |
| 24 |
|
| 25 |
#import "PBXCommon.h" |
| 26 |
#import "XCBuildConfiguration.h" |
| 27 |
#import "GSXCBuildContext.h" |
| 28 |
|
| 29 |
#import <stdlib.h> |
| 30 |
|
| 31 |
#ifdef _WIN32 |
| 32 |
#import "setenv.h" |
| 33 |
#endif |
| 34 |
|
| 35 |
@implementation XCBuildConfiguration |
| 36 |
|
| 37 |
- (instancetype) initWithName: (NSString *)theName |
| 38 |
buildSettings: (NSMutableDictionary *)settings |
| 39 |
{ |
| 40 |
self = [super init]; |
| 41 |
if (self != nil) |
| 42 |
{ |
| 43 |
[self setBuildSettings: settings]; |
| 44 |
[self setName: theName]; |
| 45 |
} |
| 46 |
return self; |
| 47 |
} |
| 48 |
|
| 49 |
- (instancetype) initWithName: (NSString *)theName |
| 50 |
{ |
| 51 |
NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithObject: @"macosx" |
| 52 |
forKey: @"SDKROOT"]; |
| 53 |
return [self initWithName: theName |
| 54 |
buildSettings: settings]; |
| 55 |
} |
| 56 |
|
| 57 |
- (instancetype) init |
| 58 |
{ |
| 59 |
self = [super init]; |
| 60 |
if (self != nil) |
| 61 |
{ |
| 62 |
// nothing now... |
| 63 |
} |
| 64 |
return self; |
| 65 |
} |
| 66 |
|
| 67 |
- (NSString *) description |
| 68 |
{ |
| 69 |
return [NSString stringWithFormat: @"%@ -- buildSettings = %@, name = %@", [super description], buildSettings, name]; |
| 70 |
} |
| 71 |
|
| 72 |
// Methods.... |
| 73 |
- (NSMutableDictionary *) buildSettings // getter |
| 74 |
{ |
| 75 |
return buildSettings; |
| 76 |
} |
| 77 |
|
| 78 |
- (void) setBuildSettings: (NSMutableDictionary *)object; // setter |
| 79 |
{ |
| 80 |
ASSIGN(buildSettings,object); |
| 81 |
} |
| 82 |
|
| 83 |
- (NSString *) name // getter |
| 84 |
{ |
| 85 |
return name; |
| 86 |
} |
| 87 |
|
| 88 |
- (void) setName: (NSString *)object; // setter |
| 89 |
{ |
| 90 |
ASSIGN(name,object); |
| 91 |
} |
| 92 |
|
| 93 |
- (void) apply |
| 94 |
{ |
| 95 |
xcputs([[NSString stringWithFormat: @"=== Applying Build Configuration %s%@%s",GREEN, name, RESET] cString]); |
| 96 |
GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext]; |
| 97 |
NSEnumerator *en = [buildSettings keyEnumerator]; |
| 98 |
NSString *key = nil; |
| 99 |
|
| 100 |
while ((key = [en nextObject]) != nil) |
| 101 |
{ |
| 102 |
id value = [buildSettings objectForKey: key]; |
| 103 |
if ([value isKindOfClass: [NSString class]]) |
| 104 |
{ |
| 105 |
setenv([key cString],[value cString],1); |
| 106 |
} |
| 107 |
else if([value isKindOfClass: [NSArray class]]) |
| 108 |
{ |
| 109 |
[context setObject: value |
| 110 |
forKey: key]; |
| 111 |
NSDebugLog(@"\tContext: %@ = %@",key,value); |
| 112 |
} |
| 113 |
else |
| 114 |
{ |
| 115 |
NSDebugLog(@"\tWARNING: Can't interpret value %@, for environment variable %@", value, key); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
if ([buildSettings objectForKey: @"TARGET_BUILD_DIR"] == nil) |
| 120 |
{ |
| 121 |
NSDebugLog(@"\tEnvironment: TARGET_BUILD_DIR = build (built-in)"); |
| 122 |
setenv("TARGET_BUILD_DIR","build",1); |
| 123 |
[context setObject: @"build" forKey: @"TARGET_BUILD_DIR"]; |
| 124 |
} |
| 125 |
|
| 126 |
if ([buildSettings objectForKey: @"BUILT_PRODUCTS_DIR"] == nil) |
| 127 |
{ |
| 128 |
NSDebugLog(@"\tEnvironment: BUILT_PRODUCTS_DIR = build (built-in)"); |
| 129 |
setenv("BUILT_PRODUCTS_DIR","build",1); |
| 130 |
[context setObject: @"build" forKey: @"BUILD_PRODUCTS_DIR"]; |
| 131 |
} |
| 132 |
|
| 133 |
xcputs([[NSString stringWithFormat: @"=== Done Applying Build Configuration for %@",name] cString]); |
| 134 |
} |
| 135 |
@end |