diff --git a/ChangeLog b/ChangeLog index c99c617..78439db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-09-15 Richard frith-Macdonald + + * Framework/PCMakefileFactory.m: generate makefiles with standard + preamble to determine GNUSTEP_MAKEFILES if possible, and warn if + not found. + 2009-09-15 Riccardo Mottola * Headers/ProjectCenter/PCProject.h diff --git a/Framework/PCMakefileFactory.m b/Framework/PCMakefileFactory.m index ed5ddc9..84633cd 100644 --- a/Framework/PCMakefileFactory.m +++ b/Framework/PCMakefileFactory.m @@ -51,7 +51,7 @@ static PCMakefileFactory *_factory = nil; { static BOOL isInitialised = NO; - if( isInitialised == NO ) + if (isInitialised == NO) { _factory = [[PCMakefileFactory alloc] init]; @@ -61,12 +61,12 @@ static PCMakefileFactory *_factory = nil; return _factory; } -- (void)createMakefileForProject:(PCProject *)project +- (void) createMakefileForProject: (PCProject *)project { id prefs = [[project projectManager] prefController]; NSString *buildDir = [prefs stringForKey:RootBuildDirectory]; NSString *prName = [project projectName]; - NSString *buildName = [prName stringByAppendingPathExtension:@"build"]; + NSString *buildName = [prName stringByAppendingPathExtension: @"build"]; NSString *instDir = [[project projectDict] objectForKey:PCInstallDir]; NSAssert(prName, @"No project name given!"); @@ -77,32 +77,41 @@ static PCMakefileFactory *_factory = nil; AUTORELEASE(pnme); pnme = [prName copy]; - [mfile appendString:@"#\n"]; - [mfile appendString:@"# GNUmakefile - Generated by ProjectCenter\n"]; - [mfile appendString:@"#\n"]; + [mfile appendString: @"#\n"]; + [mfile appendString: @"# GNUmakefile - Generated by ProjectCenter\n"]; + [mfile appendString: @"#\n"]; - if ([instDir isEqualToString:@"LOCAL"] || - [instDir isEqualToString:@"SYSTEM"] || - [instDir isEqualToString:@"USER"] || - [instDir isEqualToString:@"NETWORK"]) + [mfile appendString: @"ifeq ($(GNUSTEP_MAKEFILES),)\n"]; + [mfile appendString: @" GNUSTEP_MAKEFILES := $(shell gnustep-config "]; + [mfile appendString: @"--variable=GNUSTEP_MAKEFILES 2>/dev/null)\n"]; + [mfile appendString: @"endif\n"]; + [mfile appendString: @"ifeq ($(GNUSTEP_MAKEFILES),)\n"]; + [mfile appendString: @" $(error You need to set GNUSTEP_MAKEFILES"]; + [mfile appendString: @" before compiling!)\n"]; + [mfile appendString: @"endif\n"]; + + if ([instDir isEqualToString: @"LOCAL"] + || [instDir isEqualToString: @"SYSTEM"] + || [instDir isEqualToString: @"USER"] + || [instDir isEqualToString: @"NETWORK"]) { [mfile appendString: - [NSString stringWithFormat:@"\nGNUSTEP_INSTALLATION_DOMAIN = %@\n", + [NSString stringWithFormat: @"\nGNUSTEP_INSTALLATION_DOMAIN = %@\n", instDir]]; } - else if ([instDir isEqualToString:@""]) + else if ([instDir isEqualToString: @""]) { [mfile appendString: - [NSString stringWithFormat:@"\nGNUSTEP_INSTALLATION_DOMAIN = LOCAL\n", + [NSString stringWithFormat: @"\nGNUSTEP_INSTALLATION_DOMAIN = LOCAL\n", instDir]]; } - [mfile appendString:@"\ninclude $(GNUSTEP_MAKEFILES)/common.make\n"]; + [mfile appendString: @"\ninclude $(GNUSTEP_MAKEFILES)/common.make\n"]; - if (![buildDir isEqualToString:@""]) + if (![buildDir isEqualToString: @""]) { [mfile appendString: - [NSString stringWithFormat:@"\nGNUSTEP_BUILD_DIR = %@\n", + [NSString stringWithFormat: @"\nGNUSTEP_BUILD_DIR = %@\n", [buildDir stringByAppendingPathComponent:buildName]]]; } } @@ -117,39 +126,39 @@ static PCMakefileFactory *_factory = nil; NSString *projectType = [project projectTypeName]; // Create the new file - [mfp appendString:@"#\n"]; - [mfp appendString:@"# GNUmakefile.preamble - Generated by ProjectCenter\n"]; - [mfp appendString:@"#\n\n"]; + [mfp appendString: @"#\n"]; + [mfp appendString: @"# GNUmakefile.preamble - Generated by ProjectCenter\n"]; + [mfp appendString: @"#\n\n"]; // Preprocessor flags - [mfp appendString:@"# Additional flags to pass to the preprocessor\n"]; + [mfp appendString: @"# Additional flags to pass to the preprocessor\n"]; [mfp appendString: - [NSString stringWithFormat:@"ADDITIONAL_CPPFLAGS += %@\n\n", + [NSString stringWithFormat: @"ADDITIONAL_CPPFLAGS += %@\n\n", [projectDict objectForKey:PCPreprocessorOptions]]]; // Objective C compiler flags - [mfp appendString:@"# Additional flags to pass to Objective C compiler\n"]; + [mfp appendString: @"# Additional flags to pass to Objective C compiler\n"]; [mfp appendString: - [NSString stringWithFormat:@"ADDITIONAL_OBJCFLAGS += %@\n\n", + [NSString stringWithFormat: @"ADDITIONAL_OBJCFLAGS += %@\n\n", [projectDict objectForKey:PCObjCCompilerOptions]]]; // C compiler flags - [mfp appendString:@"# Additional flags to pass to C compiler\n"]; + [mfp appendString: @"# Additional flags to pass to C compiler\n"]; [mfp appendString: - [NSString stringWithFormat:@"ADDITIONAL_CFLAGS += %@\n\n", + [NSString stringWithFormat: @"ADDITIONAL_CFLAGS += %@\n\n", [projectDict objectForKey:PCCompilerOptions]]]; // Linker flags - [mfp appendString:@"# Additional flags to pass to the linker\n"]; + [mfp appendString: @"# Additional flags to pass to the linker\n"]; [mfp appendString: - [NSString stringWithFormat:@"ADDITIONAL_LDFLAGS += %@ ", + [NSString stringWithFormat: @"ADDITIONAL_LDFLAGS += %@ ", [projectDict objectForKey:PCLinkerOptions]]]; - [mfp appendString:@"\n\n"]; + [mfp appendString: @"\n\n"]; // Directories where to search headers [mfp appendString: @"# Additional include directories the compiler should search\n"]; - [mfp appendString:@"ADDITIONAL_INCLUDE_DIRS += "]; + [mfp appendString: @"ADDITIONAL_INCLUDE_DIRS += "]; array = [projectDict objectForKey:PCSearchHeaders]; if (array && [array count]) { @@ -158,15 +167,15 @@ static PCMakefileFactory *_factory = nil; while ((tmp = [enumerator nextObject])) { - [mfp appendString:[NSString stringWithFormat:@"-I%@ ",tmp]]; + [mfp appendString: [NSString stringWithFormat: @"-I%@ ",tmp]]; } } - [mfp appendString:@"\n\n"]; + [mfp appendString: @"\n\n"]; // Directories where to search libraries [mfp appendString: @"# Additional library directories the linker should search\n"]; - [mfp appendString:@"ADDITIONAL_LIB_DIRS += "]; + [mfp appendString: @"ADDITIONAL_LIB_DIRS += "]; array = [projectDict objectForKey:PCSearchLibs]; if (array && [array count]) { @@ -175,17 +184,17 @@ static PCMakefileFactory *_factory = nil; while ((tmp = [enumerator nextObject])) { - [mfp appendString:[NSString stringWithFormat:@"-L%@ ",tmp]]; + [mfp appendString: [NSString stringWithFormat: @"-L%@ ",tmp]]; } } - [mfp appendString:@"\n\n"]; + [mfp appendString: @"\n\n"]; - // [mfp appendString:[projectDict objectForKey:PCLibraries]]; + // [mfp appendString: [projectDict objectForKey:PCLibraries]]; - if([projectType isEqualToString: @"Tool"]) + if ([projectType isEqualToString: @"Tool"]) { // Additional TOOL libraries - [mfp appendString:@"# Additional TOOL libraries to link\n"]; + [mfp appendString: @"# Additional TOOL libraries to link\n"]; [mfp appendString: @"ADDITIONAL_TOOL_LIBS += "]; array = [projectDict objectForKey:PCLibraries]; if (array && [array count]) @@ -195,9 +204,9 @@ static PCMakefileFactory *_factory = nil; while ((tmp = [enumerator nextObject])) { - if (![tmp isEqualToString:@"gnustep-base"]) + if (![tmp isEqualToString: @"gnustep-base"]) { - [mfp appendString:[NSString stringWithFormat:@"-l%@ ",tmp]]; + [mfp appendString: [NSString stringWithFormat: @"-l%@ ",tmp]]; } } } @@ -207,7 +216,7 @@ static PCMakefileFactory *_factory = nil; // Additional GUI libraries // TODO: Let the user select objc, base, gui libraries/frameworks // on the gui - the following works well for GUI stuff only. - [mfp appendString:@"# Additional GUI libraries to link\n"]; + [mfp appendString: @"# Additional GUI libraries to link\n"]; [mfp appendString: @"ADDITIONAL_GUI_LIBS += "]; array = [projectDict objectForKey:PCLibraries]; if (array && [array count]) @@ -217,19 +226,19 @@ static PCMakefileFactory *_factory = nil; while ((tmp = [enumerator nextObject])) { - if (![tmp isEqualToString:@"gnustep-base"] && - ![tmp isEqualToString:@"gnustep-gui"]) + if (![tmp isEqualToString: @"gnustep-base"] && + ![tmp isEqualToString: @"gnustep-gui"]) { - [mfp appendString:[NSString stringWithFormat:@"-l%@ ",tmp]]; + [mfp appendString: [NSString stringWithFormat: @"-l%@ ",tmp]]; } } } } - [mfp appendString:@"\n\n"]; + [mfp appendString: @"\n\n"]; // Write the new file to disc! - mfl = [projectPath stringByAppendingPathComponent:@"GNUmakefile.preamble"]; + mfl = [projectPath stringByAppendingPathComponent: @"GNUmakefile.preamble"]; if (![mfp writeToFile:mfl atomically:YES]) { NSRunAlertPanel(@"Create Makefile", @@ -248,10 +257,10 @@ static PCMakefileFactory *_factory = nil; NSString *postamble = nil; NSFileManager *fm = [NSFileManager defaultManager]; - bundle = [NSBundle bundleForClass:[self class]]; - template = [bundle pathForResource:@"postamble" ofType:@"template"]; + bundle = [NSBundle bundleForClass: [self class]]; + template = [bundle pathForResource: @"postamble" ofType: @"template"]; postamble = [[project projectPath] - stringByAppendingPathComponent:@"GNUmakefile.postamble"]; + stringByAppendingPathComponent: @"GNUmakefile.postamble"]; if (![fm copyPath:template toPath:postamble handler:nil]) { @@ -278,22 +287,22 @@ static PCMakefileFactory *_factory = nil; NSString *lib = nil; NSEnumerator *enumerator = nil; - [libs removeObject:@"gnustep-base"]; - [libs removeObject:@"gnustep-gui"]; + [libs removeObject: @"gnustep-base"]; + [libs removeObject: @"gnustep-gui"]; if (libs == nil || [libs count] == 0) { return; } - [self appendString:@"\n\n#\n# Libraries\n#\n"]; + [self appendString: @"\n\n#\n# Libraries\n#\n"]; [self appendString: - [NSString stringWithFormat:@"%@_LIBRARIES_DEPEND_UPON += ",pnme]]; + [NSString stringWithFormat: @"%@_LIBRARIES_DEPEND_UPON += ",pnme]]; enumerator = [libs objectEnumerator]; while ((lib = [enumerator nextObject])) { - [self appendString:[NSString stringWithFormat:@"-l%@ ",lib]]; + [self appendString: [NSString stringWithFormat: @"-l%@ ",lib]]; } } @@ -312,9 +321,9 @@ static PCMakefileFactory *_factory = nil; [self appendString:COMMENT_HEADERS]; [self appendString: - [NSString stringWithFormat:@"%@_HEADER_FILES = \\\n", target]]; + [NSString stringWithFormat: @"%@_HEADER_FILES = \\\n", target]]; - [self appendString:[array componentsJoinedByString:@" \\\n"]]; + [self appendString: [array componentsJoinedByString: @" \\\n"]]; } - (void)appendClasses:(NSArray *)array @@ -336,9 +345,9 @@ static PCMakefileFactory *_factory = nil; [self appendString:COMMENT_CLASSES]; [self appendString: - [NSString stringWithFormat:@"%@_OBJC_FILES = \\\n",target]]; + [NSString stringWithFormat: @"%@_OBJC_FILES = \\\n",target]]; - [self appendString:[array componentsJoinedByString:@" \\\n"]]; + [self appendString: [array componentsJoinedByString: @" \\\n"]]; } - (void)appendOtherSources:(NSArray *)array @@ -392,11 +401,11 @@ static PCMakefileFactory *_factory = nil; { oenum = [oarray objectEnumerator]; - [self appendString:[NSString stringWithFormat:@"%@_C_FILES = ", target]]; + [self appendString: [NSString stringWithFormat: @"%@_C_FILES = ", target]]; while ((file = [oenum nextObject])) { - [self appendString:[NSString stringWithFormat:@"\\\n%@ ",file]]; + [self appendString: [NSString stringWithFormat: @"\\\n%@ ",file]]; } [self appendString: @"\n\n"]; } @@ -406,11 +415,11 @@ static PCMakefileFactory *_factory = nil; { oenum = [marray objectEnumerator]; - [self appendString:[NSString stringWithFormat:@"%@_OBJC_FILES += ",pnme]]; + [self appendString: [NSString stringWithFormat: @"%@_OBJC_FILES += ",pnme]]; while ((file = [oenum nextObject])) { - [self appendString:[NSString stringWithFormat:@"\\\n%@ ", file]]; + [self appendString: [NSString stringWithFormat: @"\\\n%@ ", file]]; } } } @@ -421,7 +430,7 @@ static PCMakefileFactory *_factory = nil; int count = [array count]; NSString *string = nil; NSString *item = nil; - NSString *eol = [NSString stringWithString:@"\\\n"]; + NSString *eol = [NSString stringWithString: @"\\\n"]; if (array == nil || count <= 0) { @@ -431,17 +440,17 @@ static PCMakefileFactory *_factory = nil; // Header [self appendString:COMMENT_RESOURCES]; [self appendString: - [NSString stringWithFormat:@"%@_RESOURCE_FILES = \\\n",pnme]]; + [NSString stringWithFormat: @"%@_RESOURCE_FILES = \\\n",pnme]]; // Items for (i = 0; i < count; i++) { item = [array objectAtIndex:i]; - string = [NSString stringWithFormat:@"%@/%@ %@", dir, item, eol]; + string = [NSString stringWithFormat: @"%@/%@ %@", dir, item, eol]; [self appendString:string]; if (i == (count-2)) { - eol = [NSString stringWithString:@"\n"]; + eol = [NSString stringWithString: @"\n"]; } } } @@ -453,17 +462,17 @@ static PCMakefileFactory *_factory = nil; return; } - [self appendString:@"\\\n"]; - [self appendString:[array componentsJoinedByString:@" \\\n"]]; + [self appendString: @"\\\n"]; + [self appendString: [array componentsJoinedByString: @" \\\n"]]; } - (void)appendLocalizedResources:(NSArray *)resources forLanguages:(NSArray *)languages { - NSString *langs = [languages componentsJoinedByString:@" "]; + NSString *langs = [languages componentsJoinedByString: @" "]; NSString *string = nil; NSString *item = nil; - NSString *eol = [NSString stringWithString:@"\\\n"]; + NSString *eol = [NSString stringWithString: @"\\\n"]; int i = 0; int count = [resources count]; @@ -476,20 +485,20 @@ static PCMakefileFactory *_factory = nil; [self appendString:COMMENT_LOCALIZATION]; // Languages - string = [NSString stringWithFormat:@"%@_LANGUAGES = %@\n", pnme, langs]; + string = [NSString stringWithFormat: @"%@_LANGUAGES = %@\n", pnme, langs]; [self appendString:string]; // Items [self appendString: - [NSString stringWithFormat:@"%@_LOCALIZED_RESOURCE_FILES = \\\n",pnme]]; + [NSString stringWithFormat: @"%@_LOCALIZED_RESOURCE_FILES = \\\n",pnme]]; for (i = 0; i < count; i++) { if (i == (count-1)) { - eol = [NSString stringWithString:@"\n"]; + eol = [NSString stringWithString: @"\n"]; } item = [resources objectAtIndex:i]; - string = [NSString stringWithFormat:@"%@ %@", item, eol]; + string = [NSString stringWithFormat: @"%@ %@", item, eol]; [self appendString:string]; } } @@ -505,21 +514,21 @@ static PCMakefileFactory *_factory = nil; } [self appendString:COMMENT_SUBPROJECTS]; - [self appendString:@"SUBPROJECTS = "]; + [self appendString: @"SUBPROJECTS = "]; enumerator = [array objectEnumerator]; while ((tmp = [enumerator nextObject])) { - tmp = [tmp stringByAppendingPathExtension:@"subproj"]; - [self appendString:[NSString stringWithFormat:@"\\\n%@ ",tmp]]; + tmp = [tmp stringByAppendingPathExtension: @"subproj"]; + [self appendString: [NSString stringWithFormat: @"\\\n%@ ",tmp]]; } } - (NSData *)encodedMakefile { - NSAssert( mfile, @"No valid makefile available!"); + NSAssert(mfile, @"No valid makefile available!"); - return [mfile dataUsingEncoding:[NSString defaultCStringEncoding]]; + return [mfile dataUsingEncoding: [NSString defaultCStringEncoding]]; } @end