Skip to content

Instantly share code, notes, and snippets.

@sooop

sooop/scc.m Secret

Created Apr 10, 2013
Embed
What would you like to do?
Compile and link easily Objective files in current directory
#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