Skip to content

Instantly share code, notes, and snippets.

@sooop

sooop/scc.m Secret

Created April 10, 2013 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sooop/d18412abb6bf80b203a4 to your computer and use it in GitHub Desktop.
Save sooop/d18412abb6bf80b203a4 to your computer and use it in GitHub Desktop.
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