コード例 #1
0
ファイル: Project.cpp プロジェクト: passick/Paladin
void
Project::Link(void)
{
	BString linkString;
	
	if (TargetType() == TARGET_STATIC_LIB)
	{
		linkString = "ar rcs '";
		linkString << GetPath().GetFolder() << "/" << GetTargetName() << "' ";
		for (int32 i = 0; i < CountGroups(); i++)
		{
			SourceGroup *group = GroupAt(i);
			
			for (int32 j = 0; j < group->filelist.CountItems(); j++)
			{
				SourceFile *file = group->filelist.ItemAt(j);
				if (file->GetObjectPath(fBuildInfo).GetFullPath())
					linkString << "'" << file->GetObjectPath(fBuildInfo).GetFullPath() << "' ";
			}
		}
	
	}
	else
	{
		linkString = "gcc -o '";
		linkString << GetPath().GetFolder() << "/" << GetTargetName() << "' ";
			
		for (int32 i = 0; i < CountGroups(); i++)
		{
			SourceGroup *group = GroupAt(i);
			
			for (int32 j = 0; j < group->filelist.CountItems(); j++)
			{
				SourceFile *file = group->filelist.ItemAt(j);
				if (file->GetObjectPath(fBuildInfo).GetFullPath())
					linkString << "'" << file->GetObjectPath(fBuildInfo).GetFullPath() << "' ";
			}
		}
	
		for (int32 i = 0; i < CountGroups(); i++)
		{
			SourceGroup *group = GroupAt(i);
			
			for (int32 j = 0; j < group->filelist.CountItems(); j++)
			{
				SourceFile *file = group->filelist.ItemAt(j);
				if (file->GetLibraryPath(fBuildInfo).GetFullPath())
					linkString << "'" << file->GetLibraryPath(fBuildInfo).GetFullPath() << "' ";
			}
		}
	
		for (int32 i = 0; i < CountLibraries(); i++)
		{
			SourceFile *file = LibraryAt(i);
			if (!file)
				continue;
			
			BString filenamebase;
			filenamebase = file->GetPath().GetBaseName();
			if (filenamebase.FindFirst("lib") == 0)
				filenamebase.RemoveFirst("lib");
			
			linkString << "-l" << filenamebase << " ";
		}
		
		if (TargetType() == TARGET_DRIVER)
			linkString << "/boot/develop/lib/x86/_KERNEL_ ";
		
		linkString << "-L/boot/home/config/lib ";
		
		switch (TargetType())
		{
			case TARGET_DRIVER:
			{
				linkString << "-Xlinker -nostdlib ";
				break;
			}
			case TARGET_SHARED_LIB:
			{
				linkString << "-nostart -Xlinker -soname=" << GetTargetName() << " ";
				break;
			}
			default:
			{
				// Application
				linkString << "-Xlinker -soname=_APP_ ";
				break;
			}
		}
	}
	
	linkString << " 2>&1";
	
	BString errmsg;
	PipeCommand(linkString.String(),errmsg);

	STRACE(1,("Linking %s:\n%s\nErrors:\n%s\n",GetName(),linkString.String(),errmsg.String()));
	
	if (errmsg.CountChars() > 0)
		ParseLDErrors(errmsg.String(),fBuildInfo.errorList);
}