-
-
Save sooop/d18412abb6bf80b203a4 to your computer and use it in GitHub Desktop.
Compile and link easily Objective files in current directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
void compile(NSString *filepath) | |
{ | |
NSString *cmd = [NSString stringWithFormat:@"c:/clang/bin/clang.exe -c %@ -ObjC -I c:/GNUstep/GNUstep/System/Library/Headers -I c:/GNUstep/include", filepath]; | |
system([cmd UTF8String]); | |
} | |
void linkFiles(NSArray *objects, NSString *output) | |
{ | |
NSString *files = @""; | |
for (id i in objects) | |
{ | |
files = (NSString*)[files stringByAppendingFormat:@" %@", i]; | |
} | |
NSString *cmd = [NSString stringWithFormat:@"c:/clang/bin/clang %@ -o %@ -Objc -L C:/GNUstep/GNUstep/System/Library/Libraries -lobjc -lgnustep-base", files, output]; | |
system([cmd UTF8String]); | |
} | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSMutableArray *objectFiles = [NSMutableArray array]; | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
NSString *curdir = [fileManager currentDirectoryPath]; | |
NSError *error = nil; | |
NSArray *arr = [fileManager contentsOfDirectoryAtPath:curdir error:&error]; | |
// complie m files | |
for (id i in arr) | |
{ | |
if([[(NSString*)i pathExtension] isEqualToString:@"m"]) { | |
NSLog(@"Compile : %@", i); | |
NSString *fullpath = [curdir stringByAppendingPathComponent:i]; | |
compile(fullpath); | |
} | |
} | |
// find All object files | |
arr = [fileManager contentsOfDirectoryAtPath:curdir error:&error]; | |
for (id i in arr) | |
{ | |
if( [[(NSString*)i pathExtension] isEqualToString:@"o"]) { | |
[objectFiles addObject:i]; | |
} | |
} | |
NSString *oName = (argc > 1) ? [NSString stringWithUTF8String:argv[1]] : @"run" ; | |
if([objectFiles count]) linkFiles(objectFiles, oName); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment