Skip to content

Commit

Permalink
Update headers, fix main
Browse files Browse the repository at this point in the history
  • Loading branch information
gcasa committed Sep 15, 2024
1 parent e6a6672 commit 612745e
Show file tree
Hide file tree
Showing 13 changed files with 354 additions and 9 deletions.
110 changes: 109 additions & 1 deletion Tools/pc2xc/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,93 @@
#import <XCode/XCode.h>
#import <XCode/xcsystem.h>

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,
Expand All @@ -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;
}

Expand Down
11 changes: 11 additions & 0 deletions XCode/PBXBuildPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
Boston, MA 02110 USA.
*/

#ifndef __PBXBuildPhase_h_GNUSTEP_INCLUDE
#define __PBXBuildPhase_h_GNUSTEP_INCLUDE

#import <Foundation/Foundation.h>

// Local includes
Expand All @@ -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
Expand All @@ -63,3 +72,5 @@
- (BOOL) link;

@end

#endif
18 changes: 18 additions & 0 deletions XCode/PBXBuildPhase.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions XCode/PBXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
NSString *_workspaceIncludes;
}

- (instancetype) initWithRootObject: (id)object;

- (void) setWorkspaceIncludes: (NSString *)i;
- (NSString *) workspaceIncludes;

Expand Down
10 changes: 10 additions & 0 deletions XCode/PBXContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions XCode/PBXFileReference.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
Boston, MA 02110 USA.
*/

#ifndef __PBXFileReference_h_GNUSTEP_INCLUDE
#define __PBXFileReference_h_GNUSTEP_INCLUDE

#import <Foundation/Foundation.h>

// Local includes
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -84,3 +91,5 @@
- (BOOL) generate;

@end

#endif
102 changes: 102 additions & 0 deletions XCode/PBXFileReference.m
Original file line number Diff line number Diff line change
Expand Up @@ -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: @"<group>"];
}
return self;
}

- (void) dealloc
{
RELEASE(_sourceTree);
Expand Down
Loading

0 comments on commit 612745e

Please sign in to comment.