Index: PBPbxNativeTarget.h
===================================================================
--- PBPbxNativeTarget.h	(revision 28752)
+++ PBPbxNativeTarget.h	(working copy)
@@ -48,6 +48,7 @@
   NSString            *productVersion;
   
   NSMutableSet        *includeDirs;
+  NSMutableSet        *libraryDirs;
   NSMutableArray      *headers;
   NSMutableSet        *headerNonGroupDirs;
   NSMutableDictionary *sources;
@@ -58,13 +59,19 @@
   NSMutableArray      *dependencyKeys;
   NSMutableDictionary *scripts;
   NSMutableSet        *targetDependencies;
+	
+	NSDictionary *defaultBuildConfiguration;
+	NSString *defaultConfigurationName ;
+	
+	NSDictionary *buildSettings;
 }
+
 /**
  * <em>Designated Initializer</em>: Initializes this Class with
  * the given target as a [NSMutableDictionary] and objects
  * in order to look up the references stored in target .
  */
-- (PBPbxNativeTarget *) initWithProject: (PBPbxProject *)project
+- (id) initWithProject: (PBPbxProject *)project
 			      andTarget: (NSDictionary *)target
 			  withTargetKey: (NSString *)targetKey;
 /**
@@ -124,7 +131,7 @@
 /**
  * getter Method
  */
-- (NSString *) infoPlist;
+- (NSDictionary *) infoPlist;
 
 /**
  * getter Method
@@ -144,6 +151,11 @@
 /**
  * getter Method: returns an Array of [NSString]
  */
+- (NSMutableSet *) libraryDirs;
+
+/**
+ * getter Method: returns an Array of [NSString]
+ */
 - (NSMutableArray *) headers;
 
 /**
@@ -192,6 +204,16 @@
  */
 - (NSString *) description;
 
+/** 
+ * getter Method: returns a dictionary of the build settings
+ */
+- (NSDictionary *) buildSettings;
+
+/**
+ * getter Method: returns the proper extension
+ */
+- (NSString *) extension;
+
 - (void) dealloc;
 @end
 
Index: main.m
===================================================================
--- main.m	(revision 28752)
+++ main.m	(working copy)
@@ -55,23 +55,24 @@
   NSFileManager              *fileManager;
   NSString                   *pbxbuildDir;
   NSString                   *pcfile;
-  BOOL                       isstatic = NO;
+//  BOOL                       isstatic = NO;
 
-  CREATE_AUTORELEASE_POOL(pool);
+//  CREATE_AUTORELEASE_POOL(pool);
+	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   fileManager = [NSFileManager defaultManager];
 
   /* let's call our cmdline parser */
   if (cmdline_parser (argc, argv, &args_info) != 0)
     {
       cmdline_parser_print_help();
-      RELEASE(pool);
-      exit(EXIT_FAILURE);
+		[pool release];
+		exit(EXIT_FAILURE);
     }
 
   if (args_info.help_given)
     {
       cmdline_parser_print_help();
-      RELEASE(pool);
+		[pool release];
       exit(EXIT_SUCCESS);
     }
 
@@ -82,11 +83,12 @@
 
   if (args_info.debug_given)
     {
+		#ifdef GNUSTEP
       NSMutableSet *debugSet;
-
       [[NSProcessInfo processInfo] setDebugLoggingEnabled: YES];
       debugSet = [[NSProcessInfo processInfo] debugSet];
       [debugSet addObject: @"dflt"];
+		#endif
     }
 
   // get the direntries of the current directory
@@ -148,16 +150,17 @@
       NSString   *makefile;
       NSString   *newTName = [[target targetName] stringByReplacingString: @" "
 						  withString: @"_"];
-      NSString   *targetDir = 
+
+		NSString   *targetDir = 
 	[pbxbuildDir stringByAppendingPathComponent:
 		       [newTName
-			 stringByAppendingPathExtension: [target targetType]]];
+			 stringByAppendingPathExtension: [target extension]]];
 
-      // static?
-      if([[target targetSubtype] isEqual: @"static"])
-	{
-	  isstatic = YES;
-	}
+//      // static?
+//      if([[target targetSubtype] isEqual: @"static"])
+//	{
+//	  isstatic = YES;
+//	}
 
       [fileManager createDirectoryAtPath: targetDir attributes: nil];
       
@@ -212,19 +215,36 @@
 		[targetDir stringByAppendingPathComponent: @"PC.project"]
 	      atomically: YES];
       // create link to Info.plist file
-
-      if ([target infoPlistFile] != nil)
-	[fileManager 
-	  copyPath: 
-	    [projectDir stringByAppendingPathComponent: [target infoPlistFile]]
-	  toPath:    
-	    [targetDir stringByAppendingPathComponent: @"Info-gnustep.plist"]
-	  handler: nil];
-      else // if not nil, the Info plist was in the pbxproj file
-	[[target infoPlist] 
-	  writeToFile: 
-	    [targetDir stringByAppendingPathComponent: @"Info-gnustep.plist"] 
-	  atomically: YES];
+		
+		NSString * infoPlistTargetPath = [targetDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@Info.plist",[target targetName]]];
+		if ([target infoPlistFile] != nil)
+	  {
+		  [fileManager 
+		   copyPath:	[projectDir stringByAppendingPathComponent: [target infoPlistFile]]
+		   toPath:		infoPlistTargetPath
+		   handler:		nil];
+		  
+		  //Fix XCode variables
+		  NSString *plistString = [NSString stringWithContentsOfFile:infoPlistTargetPath];
+	
+		  plistString = [plistString stringByReplacingString:@"${EXECUTABLE_NAME}" withString:[target targetName]];
+		  plistString = [plistString stringByReplacingString:@"${PRODUCT_NAME:identifier}" withString:[target targetName]];
+		  [plistString writeToFile:infoPlistTargetPath atomically:YES];
+	  }
+     else // if not nil, the Info plist was in the pbxproj file
+//		Another standard way of doing it
+//		NSString *error;
+//		id plistData = [NSPropertyListSerialization dataFromPropertyList:[target infoPlist] format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
+//	
+//		if (plistData) {
+//			[plistData writeToFile: infoPlistTargetPath atomically:YES];
+//		}
+//		else {
+//			NSLog(error);
+//			[error release];
+//		}
+		
+		[[target infoPlist] writeToFile:infoPlistTargetPath atomically: YES];		
     }
 
   // if user wants to generate makefile only, exit here
@@ -239,14 +259,16 @@
 
   // finally changedir to the pbxbuild directory and run make
   [fileManager changeCurrentDirectoryPath: @"pbxbuild"];
-  if(isstatic)
-    {
-      system("make shared=no");
-    }
-  else
-    {
+
+	// Can't assume everything should be static if one subproject is static.
+	//  if(isstatic)
+//    {
+//      system("make shared=no");
+//    }
+//  else
+//    {
       system("make -k");
-    }
+//    }
 
   AUTORELEASE(project);
   AUTORELEASE(pcGenerator);
Index: PBPbxGroup.m
===================================================================
--- PBPbxGroup.m	(revision 28752)
+++ PBPbxGroup.m	(working copy)
@@ -25,7 +25,7 @@
 #include "PBPbxGroup.h"
 
 @implementation PBPbxGroup
-- (PBPbxGroup *) initWithGroupKey: (NSString *)groupKey inObjects: myobjects
+- (id) initWithGroupKey: (NSString *)groupKey inObjects: myobjects
 {
   RETAIN(groupKey);
   self = [super init];
Index: PBPbxNativeTarget.m
===================================================================
--- PBPbxNativeTarget.m	(revision 28752)
+++ PBPbxNativeTarget.m	(working copy)
@@ -46,6 +46,12 @@
 - (void) addPathComponentsToIncludeDirs: (NSArray *)pathComponents;
 
 /**
+ * This adds all path components in the given array to library paths
+ * e.g. foo, bar, baz -> foo, foo/bar, foo/bar/baz
+ */
+- (void) addPathComponentsToLibraryDirs: (NSArray *)pathComponents;
+
+/**
  * get the build settings for tiger projects
  */
 - (NSDictionary *) getBuildSettingsTigerForTarget: (NSDictionary *)target;
@@ -58,6 +64,12 @@
 - (BOOL) traverseBuildPhasesOfTarget: (NSDictionary *)target;
 
 /**
+ * Cycles through all the Build configurations for various
+ * comipler settings
+ */
+//- (BOOL) traverseBuildConfigurationsOfTarget: (NSDictionary *)target;
+
+/**
  * Gets the type for the file.
  */
 - (NSString *) lookupResourceTypeOfPbxBuildFileRef: (NSString *)fileRef;
@@ -132,33 +144,62 @@
   return nil;
 }
 
-- (BOOL) traverseBuildPhasesOfTarget: (NSDictionary *)target
+- (NSDictionary *) buildConfigurationListForTarget: (NSDictionary *) target  {
+  NSString *buildConfigurationListKey = [target objectForKey:@"buildConfigurationList"];
+	if(buildConfigurationListKey == nil)
+	{
+		NSLog(@"Error: Could not find object for buildConfigurationList");
+		return nil;
+	}
+	
+	NSDictionary *buildConfigurationList = [objects objectForKey:buildConfigurationListKey];
+  return buildConfigurationList;
+}
+
+- (NSDictionary *) defaultBuildConfigurationForTarget: (NSDictionary *) aTarget
 {
-  NSDictionary *buildSettings;
-  NSString     *buildPhaseKey;
-  NSDictionary *buildPhase;
-  NSEnumerator *e;
+	NSDictionary *buildConfigurationList = [self buildConfigurationListForTarget:aTarget];
 
+	NSDictionary *defaultConfiguration = nil;
+	
+	NSEnumerator *e;
+	NSString *buildConfigurationKey;
+	
+	e = [[buildConfigurationList objectForKey:@"buildConfigurations" ]objectEnumerator];
+	while ( (buildConfigurationKey = [e nextObject]) )
+    {
+		NSDictionary *buildConfiguration = [objects objectForKey: buildConfigurationKey];
+		if( [[buildConfiguration objectForKey:@"name"] isEqualToString:defaultConfigurationName])
+		{
+			defaultConfiguration = buildConfiguration;
+			break;
+		}
+	}
+	
+	return defaultConfiguration;
+}
+
+- (void) setBuildSettingsForTarget: (NSDictionary *) target  {
   if([[project version] isEqual: PBX_VERSION_TIGER]) 
-    {
-      NSString *key = [target objectForKey: @"productType"]?
-	[target objectForKey: @"productType"]:
-	[target objectForKey: @"isa"];
+  {
+	  NSString *key = [target objectForKey: @"productType"]?
+	  [target objectForKey: @"productType"]:
+	  [target objectForKey: @"isa"];
       buildSettings = [self getBuildSettingsTigerForTarget: target];    
       ASSIGN(targetType, [self standardizeTargetType: key]);
-    }
+  }
   else if([[project version] isEqual: PBX_VERSION_PANTHER])
-    {
-      buildSettings = [target objectForKey: @"buildSettings"];
-      ASSIGN(targetType, [self standardizeTargetType: 
-				 [target objectForKey: @"productType"]]);
-    }
+  {
+	  buildSettings = [target objectForKey: @"buildSettings"];
+      ASSIGN(targetType, [self standardizeTargetType:[target objectForKey: @"productType"]]);
+  }
   else if([[project version] isEqual: PBX_VERSION_LEOPARD])
-    {
-      buildSettings = [target objectForKey: @"buildSettings"];
-      ASSIGN(targetType, [self standardizeTargetType: 
-				 [target objectForKey: @"productType"]]);
-    }
+  {
+    //  buildSettings = [target objectForKey: @"buildSettings"];
+      // Seems to have the same behavior as TIGER version, where is uses a buildConfigurationList
+	  buildSettings = [self getBuildSettingsTigerForTarget: target];
+	  ASSIGN(targetType, [self standardizeTargetType:[target objectForKey: @"productType"]]);
+  }
   else if([[project version] isEqual: PBX_VERSION_SNOWLEOPARD])
     {
       buildSettings = [target objectForKey: @"buildSettings"];
@@ -166,23 +207,49 @@
 				 [target objectForKey: @"productType"]]);
     }
   else
-    {
-      NSLog(@"Unsupported project version: '%@', quitting...",[project version]);
+  {
+	  NSLog(@"Unsupported project version: '%@', quitting...",[project version]);
       exit(EXIT_FAILURE);
-    }
+  }
 
+}
+//- (BOOL) traverseBuildConfigurationsOfTarget: (NSDictionary *)target
+//{
+//	
+//	NSDictionary *buildConfigurationList;
+//  buildConfigurationList = ;
+//
+//
+//	NSString *buildConfigurationKey;
+//	NSEnumerator *e;
+//	e = [[buildConfigurationList objectForKey:@"buildConfigurations" ]objectEnumerator];
+//	while ( (buildConfigurationKey = [e nextObject]) )
+//    {
+//		NSDictionary *buildConfiguration = [objects objectForKey: buildConfigurationKey];
+//	}
+//	
+//	return YES;
+//}
+
+- (BOOL) traverseBuildPhasesOfTarget: (NSDictionary *)target
+{
+  NSString     *buildPhaseKey;
+  NSDictionary *buildPhase;
+  NSEnumerator *e;
+	
   ASSIGN(targetName, [buildSettings objectForKey: @"PRODUCT_NAME"]);
   if(targetName == nil)
-    {
-      ASSIGN(targetName, [target objectForKey: @"name"]);
-    }
+  {
+	  ASSIGN(targetName, [target objectForKey: @"name"]);
+  }
 
+	
   if(targetType == nil)
     {
       NSString *type = ([target objectForKey: @"productType"] != nil)?
 	[target objectForKey: @"productType"]:[target objectForKey: @"isa"];
 
-      NSLog(@"Don't know how to handle target type: '%@', skipping...", type);
+      NSDebugLog(@"Don't know how to handle target type: '%@', skipping...", type);
       return NO;
     }
 
@@ -197,8 +264,21 @@
 	  [[project version] isEqual: PBX_VERSION_LEOPARD]) 
     {
       ASSIGN(infoPlistFile, [buildSettings objectForKey: @"INFOPLIST_FILE"]);
-      ASSIGN(infoPlist, [NSDictionary 
-			  dictionaryWithContentsOfFile: infoPlistFile]);
+		
+		
+		//Replace CFBundleExecutable = "${EXECUTABLE_NAME}" and CFBundleIdentifier = ${PRODUCT_NAME:identifier} 
+		//with the proper values
+		NSMutableDictionary * mutableInfo = [NSMutableDictionary dictionaryWithContentsOfFile:infoPlistFile];
+		NSString * bundleExecutable = [mutableInfo valueForKey:@"CFBundleExecutable"];
+		NSString * bundleIdentifier = [mutableInfo valueForKey:@"CFBundleIdentifier"];
+		bundleExecutable = [bundleExecutable stringByReplacingString:@"${EXECUTABLE_NAME}" withString:[self targetName]];
+		bundleIdentifier = [bundleIdentifier stringByReplacingString:@"${PRODUCT_NAME:identifier}" withString:[self targetName]];
+
+		[mutableInfo setValue:bundleExecutable forKey:@"CFBundleExecutable"];
+		[mutableInfo setValue:bundleIdentifier forKey:@"CFBundleIdentifier"];
+
+      ASSIGN(infoPlist, [mutableInfo copy]);
+		
     }
   
   ASSIGN(productVersion, [infoPlist objectForKey: @"CFBundleVersion"]);
@@ -208,7 +288,7 @@
     }
   
   // this one will be symlinked to the real Info.plist file
-  [resources addObject: @"Info-gnustep.plist"];
+//  [resources addObject: @"Info-gnustep.plist"];
 
   // get the files involved in building the target
   e = [[target objectForKey: @"buildPhases"] objectEnumerator];
@@ -253,37 +333,53 @@
 
 - (void) setUpIncludeDirsForTarget: (NSDictionary *)target
 {
-  NSArray      *buildConfigurationKeys = 
-    [[objects objectForKey: [target objectForKey: @"buildConfigurationList"]]
-      objectForKey: @"buildConfigurations"];
-  NSEnumerator *e = [buildConfigurationKeys objectEnumerator];
-  NSString     *headerSearchPaths;
-  NSString     *buildConfigurationKey;
-
+	id     headerSearchPaths;
+	id	librarySearchPaths;
+  
   if([[project version] isEqual: PBX_VERSION_PANTHER])
-    {
-      headerSearchPaths = [[target objectForKey: @"buildSettings"]
+  {
+      headerSearchPaths = [buildSettings
 			    objectForKey: @"HEADER_SEARCH_PATHS"];
+		//Don't know what panther looks like so this may not be needed/usable.
+		if(headerSearchPaths == nil)
+		  headerSearchPaths = [[project projectBuildSettings] objectForKey: @"HEADER_SEARCH_PATHS"];
+
       [self addPathComponentsToIncludeDirs: 
 	      [headerSearchPaths pathComponents]];
-    }
+  }
   else
-    while ( (buildConfigurationKey = [e nextObject]) )
-      {
-	NSDictionary *buildConfiguration = 
-	  [objects objectForKey: buildConfigurationKey];
-	
-	if (![[buildConfiguration objectForKey: @"name"] 
-	       isEqual: @"Development"])
-	  continue;
-	
-	headerSearchPaths = 
-	  [[buildConfiguration objectForKey: @"buildSettings"]
-			      objectForKey: @"HEADER_SEARCH_PATHS"];
+  {
+	  // *SearchPaths could be an Array or String depending if there are mutliple values
 
-	[self addPathComponentsToIncludeDirs: 
-		[headerSearchPaths pathComponents]];
-      }
+	  // Check target for settings first, then use project wide settings as fall back, like XCode does.
+	  headerSearchPaths = [buildSettings objectForKey: @"HEADER_SEARCH_PATHS"];
+	  if(headerSearchPaths == nil)
+		  headerSearchPaths = [[project projectBuildSettings] objectForKey: @"HEADER_SEARCH_PATHS"];
+	  
+	  if( [headerSearchPaths isKindOfClass:[NSString class]])
+		  [self addPathComponentsToIncludeDirs: [headerSearchPaths pathComponents]];
+	  else 	if( [headerSearchPaths isKindOfClass:[NSArray class]])
+	  {
+		  NSEnumerator *e              = [headerSearchPaths objectEnumerator];
+		  NSString *path;
+		  while( (path = [e nextObject] ))
+			  [self addPathComponentsToIncludeDirs: [path pathComponents]];
+	  }
+	  
+	  librarySearchPaths = [buildSettings objectForKey: @"LIBRARY_SEARCH_PATHS"];
+	  if(librarySearchPaths == nil)
+		  librarySearchPaths = [[project projectBuildSettings] objectForKey: @"LIBRARY_SEARCH_PATHS"];
+
+	  if( [librarySearchPaths isKindOfClass:[NSString class]])
+		  [self addPathComponentsToLibraryDirs: [librarySearchPaths pathComponents]];
+	  else 	if( [librarySearchPaths isKindOfClass:[NSArray class]])
+	  {
+		  NSEnumerator *e              = [librarySearchPaths objectEnumerator];
+		  NSString *path;
+		  while( (path = [e nextObject] ))
+			  [self addPathComponentsToLibraryDirs: [path pathComponents]];
+	  }
+   }
 }
 
 - (void) addPathComponentsToIncludeDirs: (NSArray *)pathComponents
@@ -296,33 +392,47 @@
       NSRange range;
       range.location = 0;
       range.length   = i+1;
-	  
-      [includeDirs addObject: 
+	  @try {
+		   [includeDirs addObject: 
 		     [NSString pathWithComponents:
 				 [pathComponents subarrayWithRange: range]
+		      ]];
+	  }
+	  @catch (NSException * e) {
+			   continue;
+	  }
+    }
+}
+
+- (void) addPathComponentsToLibraryDirs: (NSArray *)pathComponents
+{
+  int i;
+
+  // add all Directories in the path to the array
+  for (i=0; i<[pathComponents count]; i++)
+    {
+      NSRange range;
+      range.location = 0;
+      range.length   = i+1;
+		@try{
+      [libraryDirs addObject: 
+		     [NSString pathWithComponents:
+				 [pathComponents subarrayWithRange: range]
 		      ]
        ];
+		  }
+	  @catch (NSException * e) {
+			   continue;
+	  }
+
     }
 }
 
 - (NSDictionary *) getBuildSettingsTigerForTarget: (NSDictionary *)target
 {
-  NSDictionary *buildConfigurationList;
-  NSDictionary *defaultConfiguration;
   NSString     *defaultConfigurationType;
-
-  // get target name and type
-  buildConfigurationList = 
-    [objects objectForKey: [target objectForKey: 
-				     @"buildConfigurationList"]];
-  // the last object in the buildConfigurationList is the
-  // defaultConfiguration
-  defaultConfiguration = 
-    [objects objectForKey: 
-	       [[buildConfigurationList objectForKey: 
-					 @"buildConfigurations"]
-		 lastObject]];
-  defaultConfigurationType = [defaultConfiguration objectForKey: @"isa"];
+	
+  defaultConfigurationType = [defaultBuildConfiguration objectForKey: @"isa"];
   if (![@"XCBuildConfiguration" isEqual: defaultConfigurationType])
     {
       NSLog(@"FATAL: expected 'XCBuildConfiguration', but got '%@'",
@@ -330,7 +440,7 @@
       exit (EXIT_FAILURE);
     }
   
-  return [defaultConfiguration objectForKey: @"buildSettings"];
+  return [defaultBuildConfiguration objectForKey: @"buildSettings"];
 }
 
 
@@ -495,8 +605,6 @@
   NSEnumerator *e              = [files objectEnumerator];
   NSString     *pbxBuildFile;
 
-  NSDebugMLog(@"Adding files for buildPhase: %@", buildPhaseType);
-
   if ([buildPhaseType isEqual: @"PBXResourcesBuildPhase"])
     {
       while ( (pbxBuildFile = [e nextObject]) )
@@ -533,7 +641,10 @@
 	}
     }
   else
-    while ( (pbxBuildFile = [e nextObject]) )
+  {
+
+	 
+	while ( (pbxBuildFile = [e nextObject]) )
       {
 	NSString *path;
 	NSString *pbxFileReference = 
@@ -542,11 +653,13 @@
 
 	NSDebugMLog(@"Looking up file handle: %@", pbxBuildFile);
 	path = [self lookupResourcesOfPbxBuildFileRef: pbxBuildFile];
+		  NSDebugMLog(@"path: %@", path);
 	[self              addPath: path 
 	      withFileReferenceKey: pbxFileReference
 			   toArray: anArray
 			      type: buildPhaseType];
       }
+  }
 }
 
 - (void)              addPath: (NSString *)path 
@@ -554,115 +667,131 @@
                       toArray: (NSMutableArray *)anArray
 			 type: (NSString *)type
 {
- if (path != nil)
+	if (path != nil)
     {
-      NSString *sourceTree = [[objects objectForKey: fHandle] 
-			       objectForKey: @"sourceTree"];
+		NSString *sourceTree = [[objects objectForKey: fHandle] objectForKey: @"sourceTree"];
+						
+		if ([sourceTree isEqual: @"<group>"])
+		{
 
-      if ([sourceTree isEqual: @"<group>"])
-	{
-	  NSString *groupPath = 
-	    [project groupPathForFileReferenceKey: fHandle];
+			NSString *groupPath = [project groupPathForFileReferenceKey: fHandle];
 
-	  if ([type isEqual: @"PBXHeadersBuildPhase"])
-	    {
-	      NSString *dir = [path stringByDeletingLastPathComponent];
-	      if (![dir isEqual: @""])
-		[headerNonGroupDirs addObject: dir];
-	    }
+			if ([type isEqual: @"PBXHeadersBuildPhase"])
+			{
+				NSString *dir = [path stringByDeletingLastPathComponent];
+				
+				if (![dir isEqual: @""])
+					[headerNonGroupDirs addObject: dir];
+			}
 
-	  if (groupPath != nil)
-	    {
-	      // adding path components of group path to include dirs
-	      if (![type isEqual: @"PBXResourcesBuildPhase"])
-		[self addPathComponentsToIncludeDirs: 
-			[[[groupPath stringByAppendingPathComponent: path]
-			   stringByDeletingLastPathComponent]
-			  pathComponents]];
+			if (groupPath != nil)
+			{
+				// adding path components of group path to include dirs
+				if (![type isEqual: @"PBXResourcesBuildPhase"])
+					[self addPathComponentsToIncludeDirs: [[[groupPath stringByAppendingPathComponent: path] stringByDeletingLastPathComponent] pathComponents]];
 
-	      NSDebugMLog(@"Adding file with group Path '%@': %@", 
-			 groupPath,
-			 path);
-	      [anArray addObject: 
-			 [groupPath 
-			   stringByAppendingPathComponent: path]];
-	    }
-	  else 
-	    {
-	      NSDebugMLog(@"Adding file with Path '%@'", path);
-	      if([[path pathComponents] count] > 1)
-		[self addPathComponentsToIncludeDirs: 
-			[[path stringByDeletingLastPathComponent]
-			  pathComponents]];
-	      if([anArray containsObject: path] == NO)
+				NSDebugMLog(@"Adding file with group Path '%@': %@", groupPath, path);
+				
+				[anArray addObject: [groupPath stringByAppendingPathComponent: path]];
+			}
+			else 
+			{
+				NSDebugMLog(@"Adding file with Path '%@'", path);
+				if([[path pathComponents] count] > 1)
+					[self addPathComponentsToIncludeDirs: [[path stringByDeletingLastPathComponent] pathComponents]];
+	    
+				if([anArray containsObject: path] == NO)
+				{
+					[anArray addObject: path];
+				}
+			}
+		}
+		else if ([sourceTree isEqual: @"SOURCE_ROOT"]) 
+		{		
+			NSString *newPath = [@"./" stringByAppendingPathComponent: path];
+
+			[self addPathComponentsToIncludeDirs: [[path stringByDeletingLastPathComponent] pathComponents]];
+
+			NSDebugMLog(@"Adding file with SOURCE_ROOT-path: %@", newPath);
+			
+			[anArray addObject: path];
+		}
+		else if ([sourceTree isEqual: @"<absolute>"])
 		{
-		  [anArray addObject: path];
+
+			NSDebugMLog(@"Adding file with absolute path: %@", path);
+			[anArray addObject: path];
 		}
-	    }
-	}
-      else if ([sourceTree isEqual: @"SOURCE_ROOT"]) 
-	{
-	  NSString *newPath = [@"./" stringByAppendingPathComponent: path];
+		else if ([sourceTree isEqual:@"SDKROOT"])
+		{
+			// On OS X this would be something under /Develeoper, but on all *nix systems
+			// I know of, this would simply be /
+			// TODO: add a variable for SDKROOT that defaults to "/"
+			NSString *newPath = [@"/" stringByAppendingPathComponent: path];
 
-	  [self addPathComponentsToIncludeDirs: 
-		  [[path stringByDeletingLastPathComponent]
-		    pathComponents]];
+			[self addPathComponentsToIncludeDirs: [[path stringByDeletingLastPathComponent] pathComponents]];
 
-	  NSDebugMLog(@"Adding file with SOURCE_ROOT-path: %@", newPath);
-	  [anArray addObject: path];
+			NSDebugMLog(@"Adding file with SDKROOT-path: %@", newPath);
+			[anArray addObject: newPath];
+
+		}
+		else if ([sourceTree isEqual: @"BUILT_PRODUCTS_DIR"])
+		{
+			; // FIXME: No support for Products yet.
+			// put all the built products into one dir and symlink it
+			// into all the subprojects
+		}
 	}
-      else if ([sourceTree isEqual: @"<absolute>"])
-	{
-	  NSDebugMLog(@"Adding file with absolute path: %@", path);
-	  [anArray addObject: path];
-	}
-      else if ([sourceTree isEqual: @"BUILT_PRODUCTS_DIR"])
-	; // FIXME: No support for Products yet.
-          // put all the built products into one dir and symlink it
-          // into all the subprojects
-    }
 }
 
 @end
 
 @implementation PBPbxNativeTarget
-- (PBPbxNativeTarget *) initWithProject: (PBPbxProject *)aproject
+
+- (id) initWithProject: (PBPbxProject *)aproject
 			      andTarget: (NSDictionary *)atarget
 			  withTargetKey: (NSString *)atargetKey
 {
-  BOOL success = NO;
+	BOOL success = NO;
   
-  self = [super init];
-  ASSIGN(self->project, aproject);
-  ASSIGN(self->objects, [project objects]);
-  RETAIN(atarget);
-  ASSIGN(self->targetKey, atargetKey);
+	self = [super init];
+	ASSIGN(self->project, aproject);
+	ASSIGN(self->objects, [project objects]);
+	RETAIN(atarget);
+	ASSIGN(self->targetKey, atargetKey);
 
-  ASSIGN(includeDirs,        [NSMutableSet     setWithCapacity: 5 ]);
-  ASSIGN(headers,            [NSMutableArray arrayWithCapacity: 50]);
-  ASSIGN(headerNonGroupDirs, [NSMutableSet     setWithCapacity: 5]);
-  ASSIGN(sources,            [NSMutableDictionary dictionary]);
-  ASSIGN(resources,          [NSMutableArray arrayWithCapacity: 10]);
-  ASSIGN(languages,          [NSMutableSet     setWithCapacity: 5 ]);
-  ASSIGN(localizedResources, [NSMutableArray arrayWithCapacity: 5 ]);
-  ASSIGN(frameworks,         [NSMutableArray arrayWithCapacity: 5 ]);
-  ASSIGN(targetDependencies, [NSMutableArray arrayWithCapacity: 5 ]);
-  ASSIGN(scripts,            [NSMutableDictionary dictionary]);
+	ASSIGN(includeDirs,        [NSMutableSet     setWithCapacity: 5 ]);
+	ASSIGN(libraryDirs,        [NSMutableSet     setWithCapacity: 5 ]);
+	ASSIGN(headers,            [NSMutableArray arrayWithCapacity: 50]);
+	ASSIGN(headerNonGroupDirs, [NSMutableSet     setWithCapacity: 5]);
+	ASSIGN(sources,            [NSMutableDictionary dictionary]);
+	ASSIGN(resources,          [NSMutableArray arrayWithCapacity: 10]);
+	ASSIGN(languages,          [NSMutableSet     setWithCapacity: 5 ]);
+	ASSIGN(localizedResources, [NSMutableArray arrayWithCapacity: 5 ]);
+	ASSIGN(frameworks,         [NSMutableArray arrayWithCapacity: 5 ]);
+	ASSIGN(targetDependencies, [NSMutableArray arrayWithCapacity: 5 ]);
+	ASSIGN(scripts,            [NSMutableDictionary dictionary]);
+	
+	ASSIGN(defaultConfigurationName, [[self buildConfigurationListForTarget: atarget] objectForKey:@"defaultConfigurationName"]);
+	ASSIGN(defaultBuildConfiguration, [self defaultBuildConfigurationForTarget: atarget]);
 
-  // set up include dirs  
-  [self setUpIncludeDirsForTarget: atarget];
+	// Capture the buildSettings dictionary
+	[self setBuildSettingsForTarget: atarget];
 
-  // raverse the build phases
-  success = [self traverseBuildPhasesOfTarget: atarget];
+	// set up include dirs  
+	[self setUpIncludeDirsForTarget: atarget];
 
-  // store the dependency keys
-  ASSIGN(dependencyKeys, [atarget objectForKey: @"dependencies"]);
+	// Traverse the build phases
+	success = [self traverseBuildPhasesOfTarget: atarget];	
+	
+	// store the dependency keys
+	ASSIGN(dependencyKeys, [atarget objectForKey: @"dependencies"]);
 
-  RELEASE(atarget);
-  if (success == YES)
-    return self;
-  else
-    {
+	RELEASE(atarget);
+	if (success == YES)
+		return self;
+	else
+	{
       RELEASE(self);
       return nil;
     }
@@ -742,7 +871,7 @@
   return targetType;
 }
 
-- (NSString *) infoPlist
+- (NSDictionary *) infoPlist
 {
   return infoPlist;
 }
@@ -762,6 +891,11 @@
   return includeDirs;
 }
 
+- (NSMutableSet *) libraryDirs
+{
+  return libraryDirs;
+}
+
 - (NSMutableArray *) headers
 {
   return headers;
@@ -807,7 +941,19 @@
   return targetDependencies;
 }
 
+- (NSDictionary *) buildSettings
+{
+	return buildSettings;
+}
 
+- (NSString *) extension
+{
+	NSString * extension = [[self buildSettings] valueForKey:@"WRAPPER_EXTENSION"];
+	if( !extension )
+		extension = [self targetType];
+	return extension;
+}
+
 - (NSString *) description 
 {
   NSEnumerator       *e;
@@ -846,24 +992,25 @@
 
 - (void) dealloc
 {
-  DESTROY(targetDependencies);
-  DESTROY(dependencyKeys);  
-  DESTROY(frameworks);
-  DESTROY(localizedResources);
-  DESTROY(languages);
-  DESTROY(resources);
-  DESTROY(sources);
-  DESTROY(headerNonGroupDirs);
-  DESTROY(headers);
-  DESTROY(includeDirs);
-  DESTROY(infoPlist);
-  DESTROY(infoPlistFile);
-  DESTROY(productVersion);
-  DESTROY(targetType);
-  DESTROY(targetName);
-  DESTROY(targetKey);
-  DESTROY(project);
-  DESTROY(objects);
-  [super dealloc];
+	DESTROY(targetDependencies);
+	DESTROY(dependencyKeys);  
+	DESTROY(frameworks);
+	DESTROY(localizedResources);
+	DESTROY(languages);
+	DESTROY(resources);
+	DESTROY(sources);
+	DESTROY(headerNonGroupDirs);
+	DESTROY(headers);
+	DESTROY(includeDirs);
+	DESTROY(libraryDirs);
+	DESTROY(infoPlist);
+	DESTROY(infoPlistFile);
+	DESTROY(productVersion);
+	DESTROY(targetType);
+	DESTROY(targetName);
+	DESTROY(targetKey);
+	DESTROY(project);
+	DESTROY(objects);
+	[super dealloc];
 }
 @end
Index: PBProjectGenerator.h
===================================================================
--- PBProjectGenerator.h	(revision 28752)
+++ PBProjectGenerator.h	(working copy)
@@ -37,7 +37,7 @@
  * designated initializer, aProject is the project which Project 
  * is to be generated
  */
-- (PBProjectGenerator *) initWithProject: (PBPbxProject *) aProject;
+- (id) initWithProject: (PBPbxProject *) aProject;
 
 - (void) dealloc;
 
Index: PBPbxProject.h
===================================================================
--- PBPbxProject.h	(revision 28752)
+++ PBPbxProject.h	(working copy)
@@ -25,6 +25,62 @@
 #ifndef _PBPBXPROJECT_H_
 #define _PBPBXPROJECT_H_
 
+
+/***** XCode for OS X Compatability
+ * These macros are undefined in a standard OS X enviroment.
+ * PBXBuild can actually be built from within XCode (and then create its
+ * own GNUmakefule ;)
+ */
+
+#ifndef AUTORELEASE
+#define AUTORELEASE(x) [x autorelease]
+#endif
+
+#ifndef RELEASE
+#define RELEASE(x)		[x release]
+#endif
+
+#ifndef RETAIN
+#define RETAIN(x)		[x retain]
+#endif
+
+#ifndef ASSIGN
+#define ASSIGN(x, y)	(x = y)
+#endif
+
+#define DLog(format, ...) NSLog(@"%s(%i) %@", __FUNCTION__, __LINE__, [NSString stringWithFormat:format, ## __VA_ARGS__])
+
+#ifndef NSDebugMLog
+#ifdef GNUSTEP
+#define NSDebugMLog(format, args...) \
+  do { if (GSDebugSet(@"dflt") == YES) { \
+    NSString *s = GSDebugFunctionMsg( \
+      __PRETTY_FUNCTION__, __FILE__, __LINE__, \
+      [NSString stringWithFormat: format, ##args]); \
+    NSLog(@"%@", s); }} while (0)
+#else
+#define NSDebugMLog(format, args...) DLog(format, ## args)
+#endif
+#endif
+
+#ifndef NSDebugLog
+#ifdef GNUSTEP
+#define NSDebugLog(format, args...) \
+  do { if (GSDebugSet(@"dflt") == YES) \
+    NSLog(format , ## args); } while (0)
+#else
+#define NSDebugLog(format, args...) DLog(format, ## args)
+#endif
+#endif
+
+#ifndef DESTROY
+#define DESTROY(x)		(x = nil)
+#endif
+
+#ifdef TARGET_OS_MAC
+#define stringByReplacingString stringByReplacingOccurrencesOfString
+#endif
+
 #include <Foundation/Foundation.h>
 #include "PBPbxNativeTarget.h"
 
@@ -41,6 +97,11 @@
 
   // used to resolve the group path of files
   NSMutableArray      *groups;
+
+	// Default configuration to use
+	NSMutableString * defaultConfigurationName;
+	
+	NSDictionary * projectBuildSettings;
 }
 
 /**
@@ -49,7 +110,7 @@
  * file into the object and returns a fully initialized instance
  * that can be used to query information about the project 
  */
-- (PBPbxProject *) initWithFile: (NSString *)fileName;
+- (id) initWithFile: (NSString *)fileName;
 
 - (void) dealloc;
 
@@ -79,6 +140,13 @@
  * getter for version
  */
 - (NSString *) version;
+
+/**
+ * getter for project wide build settings
+  * I want properties in gcc or clang to be finished :(
+ */
+- (NSDictionary *)projectBuildSettings;
+
 @end
 
 #endif // _PBPBXPROJECT_H_
Index: PBProjectGenerator.m
===================================================================
--- PBProjectGenerator.m	(revision 28752)
+++ PBProjectGenerator.m	(working copy)
@@ -203,7 +203,7 @@
 
 
 @implementation PBProjectGenerator
-- (PBProjectGenerator *) initWithProject: (PBPbxProject *) aProject;
+- (id) initWithProject: (PBPbxProject *) aProject;
 {  
   self = [super init];
   if(self != nil)
@@ -226,9 +226,9 @@
 }
 
 - (NSString *) getSubprojectNameForTarget: (PBPbxNativeTarget *)target
-{
+{	
   return [[target targetNameReplacingSpaces] 
-	   stringByAppendingPathExtension: [target targetType]];
+	   stringByAppendingPathExtension: [target extension]];
 }
 
 - (NSString *) generateProjectFile
Index: PBMakefileGenerator.h
===================================================================
--- PBMakefileGenerator.h	(revision 28752)
+++ PBMakefileGenerator.h	(working copy)
@@ -37,7 +37,7 @@
  * designated initializer, aProject is the project which Makefile 
  * is to be generated
  */
-- (PBMakefileGenerator *) initWithProject: (PBPbxProject *) aProject;
+- (id) initWithProject: (PBPbxProject *) aProject;
 
 - (void) dealloc;
 
Index: cmdline.c
===================================================================
--- cmdline.c	(revision 28752)
+++ cmdline.c	(working copy)
@@ -187,7 +187,7 @@
 }
 
 int
-cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
+cmdline_parser (int argc, char const *argv[], struct gengetopt_args_info *args_info)
 {
   return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
 }
Index: PBPbxProject.m
===================================================================
--- PBPbxProject.m	(revision 28752)
+++ PBPbxProject.m	(working copy)
@@ -117,7 +117,7 @@
 
 
 @implementation PBPbxProject
-- (PBPbxProject *) initWithFile: (NSString *)fileName
+- (id) initWithFile: (NSString *)fileName
 {
   NSDictionary      *dict;
   NSMutableArray    *myTargets;
@@ -172,7 +172,7 @@
 	{
 	  AUTORELEASE(newTarget);
 	  [targets addObject: newTarget];
-	  NSLog(@"Found Target %@", [target objectForKey: @"name"]);
+	  NSDebugLog(@"Found Target %@", [target objectForKey: @"name"]);
 	}
     }
 
@@ -187,9 +187,27 @@
     }
 
   // and sort the targets according to dependency order
-  ASSIGN(targets, 
-	 [targets sortedArrayUsingSelector: @selector(compareDepends:)]);
-
+  targets = [[targets sortedArrayUsingSelector: @selector(compareDepends:)] mutableCopy];
+	
+	/* Read for project build settings */
+	//PBXProjext (buildConfigurationList) -> XCConfigurationList (defaultConfigurationName=, buildConfigurations{}) -> XCBuildConfiguration (name=, buildSettings={...}) 
+	NSString *defaultBuildConfigurationName;
+	NSDictionary *projectConfigurationList = [objects objectForKey:[rootObject objectForKey:@"buildConfigurationList"]];
+	defaultBuildConfigurationName = [projectConfigurationList objectForKey:@"defaultConfigurationName"];
+	e = [[projectConfigurationList objectForKey:@"buildConfigurations"] objectEnumerator];
+	
+	NSString *buildConfigurationKey;
+	while( (buildConfigurationKey = [e nextObject]) )
+	{
+		NSDictionary *buildConfiguration = [objects objectForKey: buildConfigurationKey];
+		if( [[buildConfiguration objectForKey:@"name"] isEqualToString:defaultBuildConfigurationName])
+		{
+			projectBuildSettings = [buildConfiguration objectForKey:@"buildSettings"];
+			NSDebugLog(@"Project build settings: %@", projectBuildSettings);
+			break;
+		}
+	}
+	
   return self;
 }
 
@@ -245,4 +263,9 @@
   return AUTORELEASE(RETAIN(version));
 }
 
+- (NSDictionary *) projectBuildSettings
+{
+	return projectBuildSettings;
+}
+
 @end
Index: PBDevelopmentHelper.m
===================================================================
--- PBDevelopmentHelper.m	(revision 28752)
+++ PBDevelopmentHelper.m	(working copy)
@@ -23,6 +23,7 @@
 */
 
 #include "PBDevelopmentHelper.h"
+#include "PBPbxProject.h"
 
 @implementation PBDevelopmentHelper
 // Developing, Logging and Debugging
Index: PBMakefileGenerator.m
===================================================================
--- PBMakefileGenerator.m	(revision 28752)
+++ PBMakefileGenerator.m	(working copy)
@@ -40,6 +40,12 @@
 			      inMakefile: (NSMutableString *)makefile;
 
 /**
+ * insert the CFLAGS entry for the compiler
+ */
+- (void) insertCFlagsForTarget: (PBPbxNativeTarget *)target
+					inMakefile: (NSMutableString *)makefile;
+
+/**
  * insert the shell scripts into before-all::
  */
 - (void) createShellScriptEntriesForTarget: (PBPbxNativeTarget *)target
@@ -68,6 +74,34 @@
 @end
 
 @implementation PBMakefileGenerator (Private)
+
+- (void) insertCFlagsForTarget: (PBPbxNativeTarget *)target
+			 inMakefile: (NSMutableString *)makefile
+{
+	NSString * targetcflags = [[target buildSettings] objectForKey:@"OTHER_CFLAGS"];
+	
+	NSString * cflags = [NSString stringWithFormat:@"\n\nADDITIONAL_CPPFLAGS+= -DGNUSTEP %@\n", targetcflags == nil ? @"" : targetcflags];
+	
+	/* C Dialect START */
+	NSString * gccCLanguageStandard = [[target buildSettings] objectForKey:@"GCC_C_LANGUAGE_STANDARD"];
+	if(gccCLanguageStandard)
+	{
+		cflags = [cflags stringByAppendingFormat:@" -std=%@",gccCLanguageStandard];
+	}
+	/* C Dialect END */
+	
+	/* Optimization Level START */
+	NSString * gccOptimizationLevel = [[target buildSettings] objectForKey:@"GCC_OPTIMIZATION_LEVEL"];
+	if(gccOptimizationLevel)
+	{
+		cflags = [cflags stringByAppendingFormat:@" -O%@", gccOptimizationLevel];
+	}
+	/* Optimization Level END */
+
+	
+	[makefile appendString:cflags];
+}
+
 - (void) insertIncludeDirsForTarget: (PBPbxNativeTarget *)target
 			 inMakefile: (NSMutableString *)makefile
 {
@@ -77,11 +111,38 @@
   if ([[target includeDirs] count] == 0)
     return;
 
-  [makefile appendFormat: @"\n\n%@_INCLUDE_DIRS=", [target targetNameReplacingSpaces]];
+	NSString     *tName = [target targetNameReplacingSpaces];      
+	NSString     *type  = [target targetType]; 
+	if([type isEqual: @"tool"])
+  	{
+    	tName = [tName stringByAppendingString: @"_tool"];
+  	}
+
+  [makefile appendFormat: @"\n\n%@_INCLUDE_DIRS=", tName];
   while ( (includeDir = [e nextObject]) )
+  {
+	  NSString *root = [includeDir isAbsolutePath] ? @"/" : @".";
+	  
     [makefile appendFormat: @"\\\n\t-I%@", 
+	      [root stringByAppendingPathComponent: includeDir]];
+  }
+	NSArray *frameworkSubprojects = [self includeDirectoriesForDepencies:target];
+	e = [frameworkSubprojects objectEnumerator];
+	while( (includeDir = [e nextObject]) )
+		[makefile appendFormat: @"\\\n\t-I%@", 
 	      [@"." stringByAppendingPathComponent: includeDir]];
 
+
+	
+	/* Library paths */
+	e = [[target libraryDirs] objectEnumerator];
+	[makefile appendFormat: @"\n\n%@_LIB_DIRS=", tName];
+	while ( (includeDir = [e nextObject]) )
+    {
+	  NSString *root = [includeDir isAbsolutePath] ? @"/" : @".";
+		[makefile appendFormat: @"\\\n\t-L%@", [root stringByAppendingPathComponent: includeDir]];
+	}
+	
   //generate necessary dirs in obj
   [makefile appendString: @"\n\nbefore-all::"];
   e = [[target includeDirs] objectEnumerator];
@@ -100,14 +161,21 @@
   // if the target is a framework, make the header directories
   if ([[target targetType] isEqual: @"framework"])
     {
+		
       NSString *nonGroupDir = nil;
 
       [makefile appendString: @"\n\nbefore-build-headers::"];
-      e = [[target includeDirs] objectEnumerator];
-      while ( (includeDir = [e nextObject]) )
-	[makefile appendFormat: 
-	  @"\n\tmkdir -p $(FRAMEWORK_NAME).framework/Versions/%@/Headers/%@", 
-		  [target productVersion], includeDir];  
+	
+		//Make the symlink for other projects to be able to include
+		[makefile appendFormat: @"\n\tmkdir -p $(FRAMEWORK_NAME).framework/Versions/%@/Headers/",[target productVersion]];  
+		[makefile appendFormat: @"\n\tif [[ -h $(FRAMEWORK_NAME) ]]; then rm $(FRAMEWORK_NAME); fi", [target productVersion]];  
+		[makefile appendFormat: @"\n\tln -s $(FRAMEWORK_NAME).framework/Versions/%@/Headers $(FRAMEWORK_NAME)", [target productVersion]];  
+
+   //   e = [[target includeDirs] objectEnumerator];
+//      while ( (includeDir = [e nextObject]) )
+//	[makefile appendFormat: 
+//	  @"\n\tmkdir -p $(FRAMEWORK_NAME).framework/Versions/%@/Headers/%@", 
+//		  [target productVersion], includeDir];  
       
       [makefile appendString: @"\n\nafter-build-headers::"];
       e = [[target headerNonGroupDirs] objectEnumerator];
@@ -127,38 +195,37 @@
 - (void) insertFrameworkEntriesForTarget: (PBPbxNativeTarget *)target
 			      inMakefile: (NSMutableString *)makefile
 {
-  NSEnumerator *e = [[target frameworks] objectEnumerator];
-  NSString     *frameworkFullName = nil;
-    
-  if ([[target frameworks] count] == 0)
-    return;
-  
-  [makefile appendString: @"\n\n"]; 
-  while ( (frameworkFullName = [e nextObject]) )
+	NSEnumerator *e = [[target frameworks] objectEnumerator];
+	NSString     *frameworkFullName = nil;
+
+	if ([[target frameworks] count] == 0)
+		return;
+  	
+	[makefile appendString: @"\n\n"]; 
+	while ( (frameworkFullName = [e nextObject]) )
     {
       NSString *framework = [frameworkFullName lastPathComponent];
       NSString *name = nil;
       NSString *nativeLib = nil;
       NSString *ext = [framework pathExtension];
-      
+    		
       if(framework == nil)
-	continue;
+		  continue;
 
       if([ext isEqual: @"framework"])
-	{
-	  name = [framework stringByDeletingPathExtension];
-	}
-      else if([ext isEqual: @"a"])
-	{
-	  name = [[framework stringByDeletingPathExtension] 
-		   stringByReplacingString: @"lib" withString: @""];
-	}
-
+	  {
+		  name = [framework stringByDeletingPathExtension];
+	  }
+      else if([ext isEqual: @"a"] || [ext isEqual: @"dylib"])
+	  {
+		  name = [[framework stringByDeletingPathExtension] stringByReplacingString: @"lib" withString: @""];
+	  }
+		
       // Check for well known things that we already link or can't link...
       if(name == nil)
-	{
-	  continue;
-	}      
+	  {
+		  continue;
+	  }      
       else if([name isEqual: @"Cocoa"] || // covered by gnustep-gui and gnustep-base
 	      [name isEqual: @"Carbon"] || // not available...
 	      [name isEqual: @"IOKit"] || // not available...
@@ -167,16 +234,21 @@
 	      [name isEqual: @"QuickTime"] || // not available...
 	      [name isEqual: @"SystemConfiguration"] ||
 	      [name isEqual: @"ApplicationServices"])
-	{
-	  // we already are linking parts of GNUstep equivalent to what's 
-	  // needed for the tooltype.  Also skip any other Apple specific
-	  // frameworks.
-	  continue; 
+	  {
+		  // we already are linking parts of GNUstep equivalent to what's 
+		  // needed for the tooltype.  Also skip any other Apple specific
+		  // frameworks.
+		  continue; 
+	  }
+	  else if([name isEqual: @"JavaVM"]) // Apple's framwork which is essentially libjvm
+	  {
+		  name = @"jvm";
+	  }
+
+   
+		nativeLib = [NSString stringWithFormat: @"ADDITIONAL_NATIVE_LIBS+= %@\n",name];
+		[makefile appendString: nativeLib]; 
 	}
-
-      nativeLib = [NSString stringWithFormat: @"ADDITIONAL_NATIVE_LIBS+= %@\n",name];
-      [makefile appendString: nativeLib]; 
-    }
 }
 
 - (void) createShellScriptEntriesForTarget: (PBPbxNativeTarget *)target 
@@ -280,10 +352,41 @@
   // Header files...
   if ([type isEqual: @"bundle"] || [type isEqual: @"framework"] || [type isEqual: @"library"])
     {
-      [self enumerate: [[target headers] sortedArrayUsingSelector:@selector(compare:)] 
+		// Get list of header files
+		NSArray * headerFilePaths = [[target headers] sortedArrayUsingSelector:@selector(compare:)];
+		// Remove directory paths from them
+		NSEnumerator * e = [headerFilePaths objectEnumerator];
+		NSMutableArray * headerFiles = [[NSMutableArray alloc] initWithCapacity:[headerFilePaths count]];
+		NSMutableSet	*directories = [[NSMutableSet alloc] initWithCapacity:[headerFilePaths count]]; //Set so we don't get duplicates
+		NSString * path;
+		while( (path = [e nextObject]) )
+		{
+			//Remove path components 
+			//TODO: Make this cross platform by using path compnent stuff
+			NSArray * components = [path componentsSeparatedByString:@"/"];
+			
+			[headerFiles addObject:[components lastObject]];
+			components = [components subarrayWithRange:NSMakeRange(0, [components count]-1)];
+			NSString * directory = [components componentsJoinedByString:@"/"];
+			// FIXME: Temporary, see todo a few lines below
+			if( [directories count] == 0)
+				[directories addObject: directory];
+		}
+	
+		// XCode puts ALL public headers into the Headers directory flat, in my experiences
+      [self enumerate:  headerFiles
 	    InMakefile: makefile
 	    withTargetName: tName
 	    andPrefix: @"HEADER_FILES"];
+		[headerFiles release];
+		
+		// So it knows where to find these headers
+		//TODO: Can only specify on dir, so need to make a temp dir and copy/link them all to that
+		[self enumerate:  directories
+	    InMakefile: makefile
+	    withTargetName: tName
+	    andPrefix: @"HEADER_FILES_DIR"];
+		[headerFiles release];
     }
   
   // Resource files...
@@ -321,54 +424,87 @@
     }
 }
 
+-(NSArray*)includeDirectoriesForDepencies: (PBPbxNativeTarget *)target 
+{
+	if ([[target targetDependencies] count] == 0)
+		return nil;
+	
+	NSEnumerator		*e                 = [[target targetDependencies] objectEnumerator];	
+	PBPbxNativeTarget	*dependency;
+	NSMutableArray		*nativeLibs = [NSMutableArray arrayWithCapacity:[[target targetDependencies] count]];
+  
+	while ( (dependency = [e nextObject]) )
+    {
+		if ([[dependency targetType] isEqual: @"framework"])
+		{
+			NSString *libDir;
+			libDir = [@".." stringByAppendingPathComponent:[self getSubprojectNameForTarget: dependency]];
+			  
+			[nativeLibs addObject:libDir];
+		}
+    }
+	return nativeLibs;
+}
+
 - (void) linkDependenciesForTarget: (PBPbxNativeTarget *)target 
 		      inMakefile: (NSMutableString *)makefile
 {
-  NSEnumerator      *e                 = [[target targetDependencies] 
-					   objectEnumerator];
-  PBPbxNativeTarget *dependency;
-  NSMutableString   *additionalLibDirs = [NSMutableString string];
-  NSString          *objcLibs          = [NSString string];
+	if ([[target targetDependencies] count] == 0)
+		return;
+	
+	NSEnumerator      *e                 = [[target targetDependencies] objectEnumerator];
+	
+	PBPbxNativeTarget *dependency;
+	NSMutableString   *additionalLibDirs = [NSMutableString string];
 
-  if ([[target targetDependencies] count] == 0)
-    return;
+	NSMutableString *nativeLibs = [NSMutableString string];
+	NSString          *objcLibs          = [NSString string];
 
-  objcLibs = [objcLibs stringByAppendingFormat: @"%@_OBJC_LIBS+=",
-		       [target targetNameReplacingSpaces]];
-
-  [additionalLibDirs appendString: @"\nADDITIONAL_LIB_DIRS="];
-
-  while ( (dependency = [e nextObject]) )
+	objcLibs = [objcLibs stringByAppendingFormat: @"\n%@_OBJC_LIBS+=", [target targetNameReplacingSpaces]];
+	[additionalLibDirs appendString: @"\nADDITIONAL_LIB_DIRS="];
+	
+	[nativeLibs appendString:@"\nADDITIONAL_NATIVE_LIBS +="];
+  
+	while ( (dependency = [e nextObject]) )
     {
-      if ([[dependency targetType] isEqual: @"framework"])
-	{
-	  NSString *libDir;
-	  // linking the lib
-	  objcLibs = [objcLibs stringByAppendingFormat: @" -l%@", 
-			       [dependency targetNameReplacingSpaces]];
-	  
-	  // adding the library dir
-	  // The path to the subproject
-	  libDir = [@".." stringByAppendingPathComponent:
-				[self getSubprojectNameForTarget: dependency]];
-	  // The path of the build product (The framework wrapper)
-	  libDir = [libDir stringByAppendingPathComponent: 
-			     [self getSubprojectNameForTarget: dependency]];
-	  libDir = [libDir stringByAppendingPathComponent: @"Versions"];
-	  libDir = [libDir stringByAppendingPathComponent: @"Current"];
-
-	  [additionalLibDirs appendFormat: @" -L%@", libDir];
-	}
+		if ([[dependency targetType] isEqual: @"framework"])
+		{
+			NSString *libDir;
+			// linking the lib
+			[nativeLibs appendFormat: @" %@", 
+						[dependency targetNameReplacingSpaces]];
+			
+			// adding the library dir
+			// The path to the subproject
+			libDir = [@".." stringByAppendingPathComponent:[self getSubprojectNameForTarget: dependency]];
+		
+			// The path of the build product (The framework wrapper)
+			libDir = [libDir stringByAppendingPathComponent: [self getSubprojectNameForTarget: dependency]];
+			libDir = [libDir stringByAppendingPathComponent: @"Versions"];
+			libDir = [libDir stringByAppendingPathComponent: @"Current"];
+			[additionalLibDirs appendFormat: @" -L%@", libDir];
+		  }
+		  else if([[dependency targetType] isEqual: @"library"])
+		  {
+			  NSString *libDir;
+			  libDir = [@".." stringByAppendingPathComponent:[self getSubprojectNameForTarget: dependency]];
+			  libDir = [libDir stringByAppendingPathComponent: @"obj"];
+			  [additionalLibDirs appendFormat: @" -L%@", libDir];
+			  
+			  [nativeLibs appendFormat: @" %@", [dependency targetNameReplacingSpaces]];	  
+			}
     }
 
-  [makefile appendString: objcLibs];
-  [makefile appendString: additionalLibDirs];
+	[makefile appendString: objcLibs];
+	[makefile appendString: additionalLibDirs];
+	
+	[makefile appendString: nativeLibs];
 }
 @end
 
 
 @implementation PBMakefileGenerator
-- (PBMakefileGenerator *) initWithProject: (PBPbxProject *) aProject;
+- (id) initWithProject: (PBPbxProject *) aProject;
 {  
   self = [super init];
   [self setProject: aProject];
@@ -390,7 +526,7 @@
 - (NSString *) getSubprojectNameForTarget: (PBPbxNativeTarget *)target
 {
   return [[target targetNameReplacingSpaces] 
-	   stringByAppendingPathExtension: [target targetType]];
+	   stringByAppendingPathExtension: [target extension]];
 }
 
 - (NSString *) generateProjectMakefile
@@ -430,19 +566,19 @@
 
   [makefile appendString: @"#\n# This file generated by pbxbuild \n#\n\n"];
 
+	if([[target targetSubtype] isEqualToString:@"static"])
+	  [makefile appendString: @"# Static Library\nshared=no\n\n"];
+
   [makefile appendString: @"include $(GNUSTEP_MAKEFILES)/common.make\n\n"];
 
   [self generateStandardSectionsForTarget: target
 	inMakefile: makefile];      
 
-  [self insertIncludeDirsForTarget: target inMakefile: makefile];
-
-  [self insertFrameworkEntriesForTarget: target inMakefile: makefile];
-
-  [makefile appendString: @"\n\nADDITIONAL_CPPFLAGS+= -DGNUSTEP\n"];
-
-  [self linkDependenciesForTarget: target inMakefile: makefile];
-
+	[self insertIncludeDirsForTarget: target inMakefile: makefile];
+	[self insertFrameworkEntriesForTarget: target inMakefile: makefile];	
+	[self linkDependenciesForTarget: target inMakefile: makefile];
+	[self insertCFlagsForTarget:target inMakefile:makefile];
+	
   if ([@"app" isEqual: targetType])
     {
       [makefile
@@ -455,6 +591,12 @@
     }
   else if ([@"bundle" isEqual: targetType])
     {
+		NSString * wrapperExtension =  [[target buildSettings] objectForKey:@"WRAPPER_EXTENSION"];
+		if( wrapperExtension )
+		{
+			[makefile appendFormat:@"\nBUNDLE_EXTENSION = .%@\n",wrapperExtension];
+		}
+		
       [makefile 
 	appendString: @"\ninclude $(GNUSTEP_MAKEFILES)/bundle.make\n"];
     }
Index: cmdline.h
===================================================================
--- cmdline.h	(revision 28752)
+++ cmdline.h	(working copy)
@@ -46,7 +46,7 @@
 extern const char *gengetopt_args_info_usage;
 extern const char *gengetopt_args_info_help[];
 
-int cmdline_parser (int argc, char * const *argv,
+int cmdline_parser (int argc, char const *argv[],
   struct gengetopt_args_info *args_info);
 int cmdline_parser2 (int argc, char * const *argv,
   struct gengetopt_args_info *args_info,
Index: PBPbxGroup.h
===================================================================
--- PBPbxGroup.h	(revision 28752)
+++ PBPbxGroup.h	(working copy)
@@ -26,6 +26,7 @@
 #define _PBPBXGROUP_H_
 
 #include <Foundation/Foundation.h>
+#include "PBPbxProject.h"
 
 @interface PBPbxGroup : NSObject
 {
@@ -39,7 +40,7 @@
  * Designated Initializer: groupKey is the key of a group in the 
  * NSDictionary objects
  */
-- (PBPbxGroup *) initWithGroupKey: (NSString *)groupKey inObjects: objects;
+- (id) initWithGroupKey: (NSString *)groupKey inObjects: objects;
 
 - (void) dealloc;
 
