summaryrefslogtreecommitdiffstats
path: root/buildtools/qmake/qmakedefaultopts.cpp
blob: e0e7fa6324dc7d86eaca7c25d2248031be0fd853 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/***************************************************************************
*   Copyright (C) 2006 by Andreas Pakulat                                 *
*   apaku@gmx.de                                                          *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/

#include "qmakedefaultopts.h"

#include <kdebug.h>
#include <ktempfile.h>
#include <tqregexp.h>
#include <kprocess.h>

#include <blockingkprocess.h>

TQMakeDefaultOpts::TQMakeDefaultOpts()
{

}

void TQMakeDefaultOpts::readVariables( const TQString& qmake, const TQString& projdir )
{
    KTempFile makefile (projdir+"/", ".mf");
    KTempFile qmakefile(projdir+"/", ".pro");
    if ( makefile.status() == 0 && qmakefile.status() == 0 )
    {
        makefile.close();
        qmakefile.close();

        BlockingTDEProcess proc;
        kdDebug(9024) << "KProc Working dir:" << projdir << endl;
        proc.setWorkingDirectory( projdir );
        proc << qmake;
        proc << "-d";
        proc << "-o";
        proc << makefile.name();
        proc << qmakefile.name();
        kdDebug(9024) << "Executing:" << proc.args() << endl;
        proc.start( TDEProcess::NotifyOnExit, TDEProcess::Stderr );
        if( !proc.isRunning() && !proc.normalExit() )
        {
            kdDebug(9024) << "Couldn't execute qmake: " << proc.args() << endl;
            makefile.unlink();
            qmakefile.unlink();
            m_variables.clear();
            m_keys.clear();
        }else
        {
            makefile.unlink();
            qmakefile.unlink();
            TQStringList lines = TQStringList::split( "\n", proc.stdErr() );
            kdDebug(9024) << "Got " << lines.count() << " lines" << endl;
            for ( TQStringList::const_iterator it = lines.begin(); it != lines.end(); ++it)
            {
                TQString line = *it;
                TQRegExp re( "DEBUG 1: ([^ =:]+) === (.*)" );
                if ( re.exactMatch( line ) )
                {
                    TQString var = re.cap( 1 );
                    TQStringList values = TQStringList::split( " :: ", re.cap( 2 ) );
                    m_variables[var] = values;
                    m_keys.append( var );
                }
            }
        }
    }
}

TQMakeDefaultOpts::~TQMakeDefaultOpts()
{
}

const TQStringList TQMakeDefaultOpts::variableValues( const TQString& var ) const
{
//     TQStringList result;
    if ( m_variables.contains(var) )
        return m_variables[var];
    return TQStringList();
}

const TQStringList& TQMakeDefaultOpts::variables() const
{
    return m_keys;
}

// kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on