2
KDevelop Autotools Support
3
Copyright (c) 2005 by Matt Rogers <mattr@kde.org>
5
***************************************************************************
7
* This program is free software; you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation; either version 2 of the License, or *
10
* (at your option) any later version. *
12
***************************************************************************
20
#include <qvaluelist.h>
24
#include <autotoolsast.h>
25
#include <autotoolsdriver.h>
27
#include "makefilehandler.h"
29
typedef QValueList<AutoTools::AST*> ASTList;
31
class MakefileHandler::Private
34
QMap<QString, AutoTools::ProjectAST*> projects;
35
QMap<QString, QString> folderToFileMap;
38
MakefileHandler::MakefileHandler()
40
d = new MakefileHandler::Private;
43
MakefileHandler::~MakefileHandler()
48
void MakefileHandler::parse( const QString& folder, bool recursive )
50
//look for either Makefile.am.in, Makefile.am, or Makefile.in, in that order
51
AutoTools::ProjectAST* ast;
53
QString filePath = folder + "/Makefile.am.in";
54
if ( QFile::exists( filePath ) )
55
ret = AutoTools::Driver::parseFile( filePath, &ast );
58
filePath = folder + "/Makefile.am";
59
if ( QFile::exists( filePath ) )
60
ret = AutoTools::Driver::parseFile( filePath, &ast );
63
filePath = folder + "/Makefile.in";
64
if ( QFile::exists( filePath ) )
65
ret = AutoTools::Driver::parseFile( filePath, &ast );
67
kdDebug(9020) << k_funcinfo << "no appropriate file to parse in "
77
kdDebug(9020) << k_funcinfo << filePath << " was parsed correctly. Adding information" << endl;
79
d->projects[filePath] = ast;
80
d->folderToFileMap[folder] = filePath;
82
if ( recursive && ast && ast->hasChildren() )
84
QValueList<AutoTools::AST*> astChildList = ast->children();
85
QValueList<AutoTools::AST*>::iterator it(astChildList.begin()), clEnd(astChildList.end());
86
for ( ; it != clEnd; ++it )
88
if ( (*it)->nodeType() == AutoTools::AST::AssignmentAST )
90
AutoTools::AssignmentAST* assignment = static_cast<AutoTools::AssignmentAST*>( (*it) );
91
if ( assignment->scopedID == "SUBDIRS" )
93
QString list = assignment->values.join( QString::null );
94
list.simplifyWhiteSpace();
95
kdDebug(9020) << k_funcinfo << "subdirs is " << list << endl;
96
QStringList subdirList = QStringList::split( " ", list );
97
QStringList::iterator vit = subdirList.begin();
98
for ( ; vit != subdirList.end(); ++vit )
100
QString realDir = ( *vit );
101
if ( realDir.startsWith( "\\" ) )
102
realDir.remove( 0, 1 );
104
realDir = realDir.stripWhiteSpace();
105
if ( realDir != "." && realDir != ".." && !realDir.isEmpty() )
107
if ( isVariable( realDir ) )
109
kdDebug(9020) << k_funcinfo << "'" << realDir << "' is a variable" << endl;
110
realDir = resolveVariable( realDir, ast );
113
kdDebug(9020) << k_funcinfo << "Beginning parsing of '" << realDir << "'" << endl;
114
parse( folder + '/' + realDir, recursive );
123
AutoTools::ProjectAST* MakefileHandler::astForFolder( const QString& folderPath )
125
if ( d->folderToFileMap.contains( folderPath ) )
127
QString filePath = d->folderToFileMap[folderPath];
128
return d->projects[filePath];
134
bool MakefileHandler::isVariable( const QString& item ) const
136
if ( item.contains( QRegExp( "(\\$\\([a-zA-Z0-9_-]*\\)|@[a-zA-Z0-9_-]*@)" ) ) )
142
QString MakefileHandler::resolveVariable( const QString& variable, AutoTools::ProjectAST* ast )
147
kdDebug(9020) << k_funcinfo << "attempting to resolve '" << variable << "'"<< endl;
148
ASTList childList = ast->children();
149
ASTList::iterator it( childList.begin() ), clEnd( childList.end() );
150
for ( ; it != clEnd; ++it )
152
if ( ( *it )->nodeType() == AutoTools::AST::AssignmentAST )
154
AutoTools::AssignmentAST* assignment = static_cast<AutoTools::AssignmentAST*>( ( *it ) );
155
if ( variable.find( assignment->scopedID ) != -1 )
157
kdDebug(9020) << k_funcinfo << "Resolving variable '" << variable << "' to '"
158
<< assignment->values.join( QString::null ).stripWhiteSpace() << "'" << endl;
159
return assignment->values.join( QString::null ).stripWhiteSpace();
166
//kate: space-indent on; indent-width 4;