wxString CompilerMINGWGenerator::SetupIncludeDirs(Compiler* compiler, ProjectBuildTarget* target)
{
    wxString result = CompilerCommandGenerator::SetupIncludeDirs(compiler, target);
    m_VerStr = compiler->GetVersionString();
    wxString pch_prepend = wxEmptyString;
    long gcc_major = 4;
    if ( !m_VerStr.IsEmpty() )
        m_VerStr.BeforeFirst('.').ToLong(&gcc_major);
    bool HasPCH = false; // We don't know yet if there are any header files to be compiled...

    // for PCH to work, the very first include dir *must* be the object output dir
    // *only* if PCH is generated in the object output dir
    if (target &&
        target->GetParentProject()->GetModeForPCH() == pchObjectDir)
    {
        wxArrayString includedDirs; // avoid adding duplicate dirs...
        wxString sep = wxFILE_SEP_PATH;
        // find all PCH in project
        for (FilesList::iterator it = target->GetParentProject()->GetFilesList().begin(); it != target->GetParentProject()->GetFilesList().end(); ++it)
        {
            ProjectFile* f = *it;
            if (FileTypeOf(f->relativeFilename) == ftHeader &&
                f->compile)
            {
                // it is a PCH; add it's object dir to includes
                wxFileName fn(f->GetObjName());
                wxString objName = (compiler->GetSwitches().UseFlatObjects) ? fn.GetFullName() : fn.GetFullPath();
                wxString dir = wxFileName(target->GetObjectOutput() + sep + objName).GetPath();
                if (includedDirs.Index(dir) == wxNOT_FOUND)
                {
                    includedDirs.Add(dir);
                    QuoteStringIfNeeded(dir);
                    if ( gcc_major < 4 )
                        pch_prepend << compiler->GetSwitches().includeDirs << dir << _T(' ');
                    else
                        pch_prepend << _T("-iquote") << dir << _T(' ');
                }
                HasPCH = true; // there is at least one header file to be compiled
            }
        }
        // for gcc-4.0+, use the following:
        // pch_prepend << _T("-iquote") << dir << _T(' ');
        // for earlier versions, -I- must be used
        if ( gcc_major < 4 )
            pch_prepend << _T("-I- ");
        int count = (int)includedDirs.GetCount();
        for (int i = 0; i < count; ++i)
        {
            QuoteStringIfNeeded(includedDirs[i]);
            pch_prepend << compiler->GetSwitches().includeDirs << includedDirs[i] << _T(' ');
        }
        pch_prepend << _T("-I. ");
    }

    // add in array
    if (HasPCH)
        result.Prepend(pch_prepend);

    return result;
}
Пример #2
0
bool cbMGMakefile::reLoadDependecies(const wxString &p_DepsFileName,ProjectBuildTarget *p_pTarget,Compiler* p_pCompiler)
{
    #ifdef USE_PRINTLOG
    printLog( _T( "cbMGMakefile::reLoadDependecies, Start" ), p_pTarget->GetTitle() );
    #endif

    m_Deps.Clear();
    if ( !wxFileExists( p_DepsFileName ) )
    {
        wxString l_Msg = _( "Dependencies file (.depend) is absent!\n"
                            "C::B MakefileGen could not complete the operation." );
        cbMessageBox( l_Msg, _( "Error" ), wxICON_ERROR | wxOK, (wxWindow *)Manager::Get()->GetAppWindow() );
        Manager::Get()->GetLogManager()->DebugLog( l_Msg );
        #ifdef USE_PRINTLOG
        printLog( _T( "cbMGMakefile::reLoadDependecies" ), _T( "End false" ) );
        #endif
        return false;
    }

    wxString l_Buf;
    wxString l_VarName;
    wxTextFile l_DepFile;
    wxString l_TargetName = p_pTarget->GetTitle();
    bool IsSkipThisFile = true;
    if (l_DepFile.Open( p_DepsFileName, wxConvFile ))
    {
        for ( unsigned long i = 0; i < l_DepFile.GetLineCount(); i++ )
        {
            l_Buf = l_DepFile[i];
            l_Buf.Trim(true);
            // Wrong! Don't uncomment it! Being deleted '\t' symbol! l_Buf.Trim(false);
            if ( l_Buf.IsEmpty() )
            {
                l_VarName.Clear();
                IsSkipThisFile = true;
                continue;
            }
            if ( _T('#') == l_Buf[0] ) continue;
            if ( _T('\t') == l_Buf[0] )
            {
                if ( !IsSkipThisFile )
                {
                    if ( _T('"') == l_Buf[1] )
                    {
                        wxString l_TmpName = l_Buf.AfterFirst( _T('\t') );
                        if (!l_TmpName.IsEmpty() && l_TmpName.GetChar(0) == _T('"') && l_TmpName.Last() == _T('"'))
                            l_TmpName = l_TmpName.Mid(1, l_TmpName.Length() - 2);
                        QuoteStringIfNeeded( l_TmpName );
                        m_Deps.AppendValue( l_VarName, l_TmpName );
                    }
                }
            }
            else
            {
                l_VarName = l_Buf.AfterFirst(_T(' '));
                bool IsSource = l_VarName.Matches( _T("source:*") );
                if ( IsSource )
                {
                    l_VarName = l_VarName.AfterFirst( _T(':') );
                }
                /*
                 * You would MUST found source file and get his filename from project
                 * !!! .depend file content lowcase filenames
                 */
                wxFileName l_DepFileName = l_VarName;

                #ifdef USE_PRINTLOG
                printLog( _T( "cbMGMakefile::reLoadDependecies, depfilename" ), l_VarName.wc_str() );
                #endif

                ProjectFile *pf = m_pProj->GetFileByFilename( l_DepFileName.GetFullPath(), l_DepFileName.IsRelative(), false );
                if ( pf )
                {
                    #ifdef USE_PRINTLOG
                    printLog( _T( "cbMGMakefile::reLoadDependecies, pf readed" ), pf->GetObjName() );
                    #endif

                    if( pf->buildTargets.Index( l_TargetName ) != wxNOT_FOUND )
                    {

                        #ifdef USE_PRINTLOG
                        printLog( _T( "cbMGMakefile::reLoadDependecies, before pfd read, target" ), l_TargetName );
                        #endif

                        const pfDetails& pfd = pf->GetFileDetails( p_pTarget );

                        #ifdef USE_PRINTLOG
                        printLog( _T( "cbMGMakefile::reLoadDependecies, pfd readed" ), pfd.dep_dir );
                        #endif

                        if ( p_pCompiler->GetSwitches().UseFullSourcePaths )
                        {
                            l_VarName = UnixFilename( pfd.source_file_absolute_native );
                        }
                        else
                        {
                            l_VarName = pfd.source_file;
                        }
                        QuoteStringIfNeeded( l_VarName );
                        IsSkipThisFile = false;
                    }
                    else
                    {
                        #ifdef USE_PRINTLOG
                        printLog( _T( "cbMGMakefile::reLoadDependecies, pf skip" ), pf->GetObjName() );
                        #endif

                        IsSkipThisFile = true;
                    }
                }
                else
                {
                    IsSkipThisFile = true;
                }
            }
        }
    }
    /* FIXME (kisoftcb#1#): Next code for debug only!
    wxTextFile l_DebFile;
    l_DebFile.Create( _T("D:/DepsFile.log") );
    m_Deps.SaveAllVars( l_DebFile );
    l_DebFile.Write();
    l_DebFile.Close(); */
    /* return was absent here! */
    #ifdef USE_PRINTLOG
    printLog( _T( "cbMGMakefile::reLoadDependecies" ), _T( "End true" ) );
    #endif
    return true;
}