diff --git a/Tools/pc2xc/main.m b/Tools/pc2xc/main.m index e5bd56b..19e8da7 100644 --- a/Tools/pc2xc/main.m +++ b/Tools/pc2xc/main.m @@ -11,6 +11,93 @@ #import #import +NSMutableArray *buildFileReferences(NSArray *allFiles, + NSString *ext) +{ + NSMutableArray *result = [NSMutableArray array]; + NSEnumerator *en = [allFiles objectEnumerator]; + NSString *filename = nil; + + while ((filename = [en nextObject]) != nil) + { + if (ext != nil) + { + filename = [filename stringByAppendingPathExtension: ext]; + } + + PBXFileReference *fileRef = AUTORELEASE([[PBXFileReference alloc] initWithPath: filename]); + [result addObject: fileRef]; + } + + return result; +} + +NSString *typeForProjectType(NSString *projectType) +{ + NSString *result = @""; + + if ([projectType isEqualToString: @"Application"]) + { + result = @"com.apple.product-type.application"; + } + else if ([projectType isEqualToString: @"Tool"]) + { + result = @"com.apple.product-type.tool"; + } + else if ([projectType isEqualToString: @"Library"]) + { + result = @"com.apple.product-type.library"; + } + else if ([projectType isEqualToString: @"Framework"]) + { + result = @"com.apple.product-type.framework"; + } + + return result; +} + +PBXGroup *productReferenceGroup(NSString *projectName, + NSString *projectType) +{ + PBXGroup *group = AUTORELEASE([[PBXGroup alloc] init]); + NSString *type = typeForProjectType(projectType); + NSString *ext = [PBXFileReference extForFileType: type]; + NSString *path = [projectName stringByAppendingPathExtension: ext]; + PBXFileReference *productFileRef = AUTORELEASE([[PBXFileReference alloc] initWithPath: path]); + NSMutableArray *children = [NSMutableArray arrayWithObject: productFileRef]; + + [group setChildren: children]; + [group setName: @"Products"]; + + return group; +} + +PBXGroup *mainGroupBuild(NSArray *files, PBXGroup *productReferenceGroup) +{ + PBXGroup *mainGroup = AUTORELEASE([[PBXGroup alloc] init]); + NSMutableArray *buildGroupFiles = buildFileReferences(files, nil); + PBXGroup *buildFileGroup = AUTORELEASE([[PBXGroup alloc] init]); + [buildFileGroup setChildren: buildGroupFiles]; + + NSMutableArray *mainGroupChildren = [NSMutableArray arrayWithObjects: buildFileGroup, + productReferenceGroup, nil]; + [mainGroup setChildren: mainGroupChildren]; + + return mainGroup; +} + +NSMutableArray *buildTargets(NSString *projectName, + NSString *projectType, + NSArray *files, + NSArray *headers, + NSArray *resources, + NSArray *frameworks) +{ + NSMutableArray *result = [NSMutableArray array]; + return result; +} + + PBXContainer *buildContainer(NSString *projectName, NSString *projectType, NSArray *files, @@ -19,8 +106,29 @@ NSArray *other, NSArray *frameworks) { - PBXContainer *container = [[PBXContainer alloc] init]; + NSMutableArray *allFiles = [NSMutableArray arrayWithArray: files]; + PBXProject *project = AUTORELEASE([[PBXProject alloc] init]); + PBXContainer *container = AUTORELEASE([[PBXContainer alloc] initWithRootObject: project]); + XCBuildConfiguration *buildConfigDebug = AUTORELEASE([[XCBuildConfiguration alloc] init]); + XCBuildConfiguration *buildConfigRelease = AUTORELEASE([[XCBuildConfiguration alloc] initWithName: @"Release"]); + NSMutableArray *configArray = [NSMutableArray arrayWithObjects: buildConfigDebug, buildConfigRelease, nil]; + XCConfigurationList *configList = AUTORELEASE([[XCConfigurationList alloc] initWithConfigurations: configArray]); + [allFiles addObject: other]; + + // Set up groups... + PBXGroup *productRefGroup = productReferenceGroup(projectName, projectType); // AUTORELEASE([[PBXGroup alloc] init]); + PBXGroup *mainGroup = mainGroupBuild(allFiles, productRefGroup); // AUTORELEASE([[PBXGroup alloc] init]); + NSMutableArray *targets = buildTargets(projectName, projectType, allFiles, headers, resources, frameworks); + + [project setMainGroup: mainGroup]; + [project setProductRefGroup: productRefGroup]; + [project setBuildConfigurationList: configList]; + [project setContainer: container]; + [project setTargets: targets]; + NSLog(@"files = %@", files); + NSLog(@"container = %@", container); + return container; } diff --git a/XCode/PBXBuildPhase.h b/XCode/PBXBuildPhase.h index 2347517..08b8ceb 100644 --- a/XCode/PBXBuildPhase.h +++ b/XCode/PBXBuildPhase.h @@ -22,6 +22,9 @@ Boston, MA 02110 USA. */ +#ifndef __PBXBuildPhase_h_GNUSTEP_INCLUDE +#define __PBXBuildPhase_h_GNUSTEP_INCLUDE + #import // Local includes @@ -38,6 +41,12 @@ NSString *_name; } +- (instancetype) initWithFiles: (NSMutableArray *)files + buildActionMask: (NSString *)buildActionMask + runOnlyForDeployment: (NSString *)runOnlyForDeployment + target: (PBXNativeTarget *)target + name: (NSString *)name; + // Methods.... - (NSMutableArray *) files; // getter - (void) setFiles: (NSMutableArray *)object; // setter @@ -63,3 +72,5 @@ - (BOOL) link; @end + +#endif diff --git a/XCode/PBXBuildPhase.m b/XCode/PBXBuildPhase.m index b834be2..307d53f 100644 --- a/XCode/PBXBuildPhase.m +++ b/XCode/PBXBuildPhase.m @@ -27,6 +27,24 @@ @implementation PBXBuildPhase +- (instancetype) initWithFiles: (NSMutableArray *)files + buildActionMask: (NSString *)buildActionMask + runOnlyForDeployment: (NSString *)runOnlyForDeployment + target: (PBXNativeTarget *)target + name: (NSString *)name +{ + self = [super init]; + if (self != nil) + { + [self setFiles: files]; + [self setBuildActionMask: buildActionMask]; + [self setRunOnlyForDeploymentPostprocessing: runOnlyForDeployment]; + [self setTarget: target]; + [self setName: name]; + } + return self; +} + - (void) dealloc { RELEASE(_files); diff --git a/XCode/PBXContainer.h b/XCode/PBXContainer.h index 224c750..9148eee 100644 --- a/XCode/PBXContainer.h +++ b/XCode/PBXContainer.h @@ -43,6 +43,8 @@ NSString *_workspaceIncludes; } +- (instancetype) initWithRootObject: (id)object; + - (void) setWorkspaceIncludes: (NSString *)i; - (NSString *) workspaceIncludes; diff --git a/XCode/PBXContainer.m b/XCode/PBXContainer.m index ce2349d..802a507 100644 --- a/XCode/PBXContainer.m +++ b/XCode/PBXContainer.m @@ -50,6 +50,16 @@ - (instancetype) init return self; } +- (instancetype) initWithRootObject: (id)object +{ + self = [self init]; + if (self != nil) + { + [self setRootObject: object]; + } + return self; +} + - (void) dealloc { RELEASE(_archiveVersion); diff --git a/XCode/PBXFileReference.h b/XCode/PBXFileReference.h index 7c08bc0..4f6c436 100644 --- a/XCode/PBXFileReference.h +++ b/XCode/PBXFileReference.h @@ -22,6 +22,9 @@ Boston, MA 02110 USA. */ +#ifndef __PBXFileReference_h_GNUSTEP_INCLUDE +#define __PBXFileReference_h_GNUSTEP_INCLUDE + #import // Local includes @@ -52,6 +55,10 @@ NSUInteger _currentFile; } ++ (NSString *) fileTypeFromPath: (NSString *)path; ++ (NSString *) extForFileType: (NSString *)type; +- (instancetype) initWithPath: (NSString *)path; + - (void) setTotalFiles: (NSUInteger)t; - (void) setCurrentFile: (NSUInteger)n; @@ -84,3 +91,5 @@ - (BOOL) generate; @end + +#endif diff --git a/XCode/PBXFileReference.m b/XCode/PBXFileReference.m index aac8f19..d45bf8c 100644 --- a/XCode/PBXFileReference.m +++ b/XCode/PBXFileReference.m @@ -45,6 +45,108 @@ + (void) initialize lock = [[NSLock alloc] init]; } ++ (NSString *) fileTypeFromPath: (NSString *)path +{ + NSString *result = @"compiled.mach-o.executable"; + NSString *ext = [path pathExtension]; + + if ([ext isEqualToString: @"m"]) + { + result = @"sourcecode.c.objc"; + } + else if ([ext isEqualToString: @"c"]) + { + result = @"sourcecode.c.c"; + } + else if ([ext isEqualToString: @"cc"] + || [ext isEqualToString: @"cpp"] + || [ext isEqualToString: @"C"] + || [ext isEqualToString: @"cxx"]) + { + result = @"sourcecode.cpp.cpp"; + } + else if ([ext isEqualToString: @"mm"]) + { + result = @"sourcecode.cpp.objcpp"; + } + else if ([ext isEqualToString: @"lex.yy"]) + { + result = @"sourcecode.lex"; + } + else if ([ext isEqualToString: @"yy.tab"]) + { + result = @"sourcecode.yacc"; + } + else if ([ext isEqualToString: @"app"]) + { + result = @"wrapper.application"; + } + + return result; +} + ++ (NSString *) extForFileType: (NSString *)type +{ + NSString *result = @""; + + if ([type isEqualToString: @"sourcecode.c.objc"]) + { + result = @"m"; + } + else if ([type isEqualToString: @"sourcecode.c.c"]) + { + result = @"c"; + } + else if ([type isEqualToString: @"sourcecode.cpp.cpp"]) + { + result = @"cc"; + } + else if ([type isEqualToString: @"sourcecode.cpp.objcpp"]) + { + result = @"mm"; + } + else if ([type isEqualToString: @"sourcecode.lex"]) + { + result = @"lex.yy"; + } + else if ([type isEqualToString: @"sourcecode.yacc"]) + { + result = @"yy.tab"; + } + else if ([type isEqualToString: @"wrapper.application"]) + { + result = @"app"; + } + + return result; +} + +- (instancetype) initWithPath: (NSString *)path +{ + self = [super init]; + if (self != nil) + { + NSString *fileType = [PBXFileReference fileTypeFromPath: path]; + + if ([fileType isEqualToString: @"compiled.mach-o.executable"]) + { + [self setIncludeInIndex: @"0"]; + } + + if ([fileType isEqualToString: @"wrapper.application"]) + { + [self setExplicitFileType: fileType]; + } + else + { + [self setLastKnownFileType: fileType]; + } + + [self setSourceTree: @""]; + } + return self; +} + - (void) dealloc { RELEASE(_sourceTree); diff --git a/XCode/PBXProject.h b/XCode/PBXProject.h index 4939484..b06f8f5 100644 --- a/XCode/PBXProject.h +++ b/XCode/PBXProject.h @@ -22,6 +22,9 @@ Boston, MA 02110 USA. */ +#ifndef __PBXProject_h_GNUSTEP_INCLUDE +#define __PBXProject_h_GNUSTEP_INCLUDE + #import // Local includes @@ -56,30 +59,43 @@ // Methods.... - (NSString *) developmentRegion; // getter - (void) setDevelopmentRegion: (NSString *)object; // setter + - (NSMutableArray *) knownRegions; // getter - (void) setKnownRegions: (NSMutableArray *)object; // setter + - (NSString *) compatibilityVersion; // getter - (void) setCompatibilityVersion: (NSString *)object; // setter + - (NSMutableArray *) projectReferences; // getter - (void) setProjectReferences: (NSMutableArray *)object; // setter + - (NSMutableArray *) targets; // getter - (void) setTargets: (NSMutableArray *)object; // setter + - (NSString *) projectDirPath; // getter - (void) setProjectDirPath: (NSString *)object; // setter + - (NSString *) projectRoot; // getter - (void) setProjectRoot: (NSString *)object; // setter + - (XCConfigurationList *) buildConfigurationList; // getter - (void) setBuildConfigurationList: (XCConfigurationList *)object; // setter + - (PBXGroup *) mainGroup; // getter - (void) setMainGroup: (PBXGroup *)object; // setter + - (NSString *) hasScannedForEncodings; // getter - (void) setHasScannedForEncodings: (NSString *)object; // setter + - (PBXGroup *) productRefGroup; // getter - (void) setProductRefGroup: (PBXGroup *)object; // setter + - (PBXContainer *) container; - (void) setContainer: (PBXContainer *)container; + - (void) setContext: (NSDictionary *)ctx; - (NSDictionary *) context; + - (void) setFilename: (NSString *)fn; - (NSString *) filename; @@ -93,3 +109,5 @@ - (BOOL) generate; - (BOOL) save; @end + +#endif diff --git a/XCode/PBXProject.m b/XCode/PBXProject.m index b8594a9..a37d830 100644 --- a/XCode/PBXProject.m +++ b/XCode/PBXProject.m @@ -153,6 +153,14 @@ - (instancetype) init if (self != nil) { + // Set up defaults... + [self setCompatibilityVersion: @"Xcode 14.0"]; + [self setDevelopmentRegion: @"en"]; + [self setKnownRegions: [NSMutableArray arrayWithObjects: @"en", @"Base", nil]]; + [self setProjectDirPath: @""]; + [self setProjectRoot: @""]; + [self setHasScannedForEncodings: @"0"]; + [self setTargets: [NSMutableArray array]]; } return self; diff --git a/XCode/XCBuildConfiguration.h b/XCode/XCBuildConfiguration.h index 20f191f..6fae707 100644 --- a/XCode/XCBuildConfiguration.h +++ b/XCode/XCBuildConfiguration.h @@ -22,6 +22,9 @@ Boston, MA 02110 USA. */ +#ifndef __XCBuildConfiguration_h_GNUSTEP_INCLUDE +#define __XCBuildConfiguration_h_GNUSTEP_INCLUDE + #import // Local includes @@ -35,6 +38,11 @@ PBXFileReference *baseConfigurationReference; } +// Initialization... +- (instancetype) initWithName: (NSString *)theName + buildSettings: (NSMutableDictionary *)settings; +- (instancetype) initWithName: (NSString *)theName; + // Methods.... - (NSMutableDictionary *) buildSettings; // getter - (void) setBuildSettings: (NSMutableDictionary *)object; // setter @@ -43,3 +51,5 @@ - (void) apply; @end + +#endif diff --git a/XCode/XCBuildConfiguration.m b/XCode/XCBuildConfiguration.m index b834e83..041123d 100644 --- a/XCode/XCBuildConfiguration.m +++ b/XCode/XCBuildConfiguration.m @@ -34,6 +34,35 @@ @implementation XCBuildConfiguration +- (instancetype) initWithName: (NSString *)theName + buildSettings: (NSMutableDictionary *)settings +{ + self = [super init]; + if (self != nil) + { + [self setBuildSettings: settings]; + [self setName: theName]; + } + return self; +} + +- (instancetype) initWithName: (NSString *)theName +{ + NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithObject: @"macosx" + forKey: @"SDKROOT"]; + return [self initWithName: theName + buildSettings: settings]; +} + +- (instancetype) init +{ + NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithObject: @"macosx" + forKey: @"SDKROOT"]; + return [self initWithName: @"Debug" + buildSettings: settings]; + +} + - (NSString *) description { return [NSString stringWithFormat: @"%@ -- buildSettings = %@, name = %@", [super description], buildSettings, name]; diff --git a/XCode/XCConfigurationList.h b/XCode/XCConfigurationList.h index 83db8ec..407c6df 100644 --- a/XCode/XCConfigurationList.h +++ b/XCode/XCConfigurationList.h @@ -20,7 +20,12 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 USA. -*/ #import +*/ + +#ifndef __XCConfigurationList_h_GNUSTEP_INCLUDE +#define __XCConfigurationList_h_GNUSTEP_INCLUDE + +#import #import "PBXCoder.h" @class XCBuildConfiguration; @@ -32,6 +37,8 @@ NSString *defaultConfigurationName; } +- (instancetype) initWithConfigurations: (NSMutableArray *)configs; + // Methods.... - (NSString *) defaultConfigurationIsVisible; // getter - (void) setDefaultConfigurationIsVisible: (NSString *)object; // setter @@ -43,3 +50,5 @@ - (void) applyDefaultConfiguration; @end + +#endif diff --git a/XCode/XCConfigurationList.m b/XCode/XCConfigurationList.m index 718827b..bedc160 100644 --- a/XCode/XCConfigurationList.m +++ b/XCode/XCConfigurationList.m @@ -20,12 +20,29 @@ 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 "PBXCommon.h" #import "XCConfigurationList.h" #import "XCBuildConfiguration.h" @implementation XCConfigurationList +- (instancetype) initWithConfigurations: (NSMutableArray *)configs +{ + self = [super init]; + if (self != nil) + { + [self setBuildConfigurations: configs]; + } + return self; +} + +- (instancetype) init +{ + return [self initWithConfigurations: [NSMutableArray array]]; +} + // Methods.... - (NSString *) defaultConfigurationIsVisible // getter { @@ -85,12 +102,6 @@ - (void) applyDefaultConfiguration [[self defaultConfiguration] apply]; } -- (instancetype) init -{ - self = [super init]; - return self; -} - - (NSString *) description { return [NSString stringWithFormat: @"%@ -- %@", [super description],