2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 Openismus GmbH.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-11-29 14:19:28 +01:00
|
|
|
|
2016-02-03 17:21:12 +01:00
|
|
|
#pragma once
|
2011-11-29 14:19:28 +01:00
|
|
|
|
2017-02-07 15:00:38 +01:00
|
|
|
#include <projectexplorer/projectmacro.h>
|
|
|
|
|
|
2024-07-15 13:28:18 +02:00
|
|
|
#include <QFuture>
|
|
|
|
|
#include <QObject>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QTextStream>
|
2021-02-18 18:17:08 +01:00
|
|
|
|
2023-08-17 00:20:09 +02:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QDir;
|
|
|
|
|
QT_END_NAMESPACE
|
2011-11-29 14:19:28 +01:00
|
|
|
|
2022-09-29 17:11:01 +02:00
|
|
|
namespace AutotoolsProjectManager::Internal {
|
2011-11-29 14:19:28 +01:00
|
|
|
|
2024-07-15 11:27:43 +02:00
|
|
|
class MakefileParserOutputData final
|
|
|
|
|
{
|
|
|
|
|
public:
|
2024-07-15 12:15:35 +02:00
|
|
|
// File name of the executable.
|
2024-07-15 11:27:43 +02:00
|
|
|
QString m_executable;
|
2024-07-15 12:15:35 +02:00
|
|
|
// List of sources that are set for the _SOURCES target.
|
|
|
|
|
// Sources in sub directorties contain the sub directory as prefix.
|
2024-07-15 11:27:43 +02:00
|
|
|
QStringList m_sources;
|
2024-07-15 12:15:35 +02:00
|
|
|
// List of Makefile.am files from the current directory and all sub directories.
|
|
|
|
|
// The values for sub directories contain the sub directory as prefix.
|
2024-07-15 11:27:43 +02:00
|
|
|
QStringList m_makefiles;
|
2024-07-15 12:15:35 +02:00
|
|
|
// List of include paths. Should be invoked, after the signal finished() has been emitted.
|
2024-07-15 11:27:43 +02:00
|
|
|
QStringList m_includePaths;
|
2024-07-15 12:15:35 +02:00
|
|
|
// Concatenated normalized defines, just like in code:
|
|
|
|
|
// #define X12_DEPRECATED __attribute__((deprecated))
|
|
|
|
|
// #define X12_HAS_DEPRECATED
|
2024-07-15 11:27:43 +02:00
|
|
|
ProjectExplorer::Macros m_macros;
|
2024-07-15 12:15:35 +02:00
|
|
|
// List of compiler flags for C.
|
2024-07-15 11:27:43 +02:00
|
|
|
QStringList m_cflags;
|
2024-07-15 12:15:35 +02:00
|
|
|
// List of compiler flags for C++.
|
2024-07-15 11:27:43 +02:00
|
|
|
QStringList m_cxxflags;
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-29 14:19:28 +01:00
|
|
|
/**
|
|
|
|
|
* @brief Parses the autotools makefile Makefile.am.
|
|
|
|
|
*
|
|
|
|
|
* The parser returns the sources, makefiles and executable.
|
|
|
|
|
* Variables like $(test) are not evaluated. If such a variable
|
|
|
|
|
* is part of a SOURCES target, a fallback will be done and all
|
|
|
|
|
* sub directories get parsed for C- and C++ files.
|
|
|
|
|
*/
|
|
|
|
|
class MakefileParser : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
2017-02-07 15:00:38 +01:00
|
|
|
using Macros = ProjectExplorer::Macros;
|
|
|
|
|
|
2011-11-29 14:19:28 +01:00
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* @param makefile Filename including path of the autotools
|
|
|
|
|
* makefile that should be parsed.
|
|
|
|
|
*/
|
|
|
|
|
MakefileParser(const QString &makefile);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parses the makefile. Must be invoked at least once, otherwise
|
2013-10-07 13:34:40 +02:00
|
|
|
* the getter functions of MakefileParser will return empty values.
|
2011-11-29 14:19:28 +01:00
|
|
|
* @return True, if the parsing was successful. If false is returned,
|
|
|
|
|
* the makefile could not be opened.
|
|
|
|
|
*/
|
|
|
|
|
bool parse();
|
2024-07-15 13:28:18 +02:00
|
|
|
bool parse(const QFuture<void> &future);
|
2011-11-29 14:19:28 +01:00
|
|
|
|
2024-07-15 11:27:43 +02:00
|
|
|
MakefileParserOutputData outputData() const { return m_outputData; }
|
|
|
|
|
|
2011-11-29 14:19:28 +01:00
|
|
|
signals:
|
|
|
|
|
/**
|
|
|
|
|
* Is emitted periodically during parsing the Makefile.am files
|
|
|
|
|
* and the sub directories. \p status provides a translated
|
|
|
|
|
* string, that can be shown to indicate the current state
|
|
|
|
|
* of the parsing.
|
|
|
|
|
*/
|
|
|
|
|
void status(const QString &status);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
enum TopTarget {
|
|
|
|
|
Undefined,
|
|
|
|
|
AmDefaultSourceExt,
|
|
|
|
|
BinPrograms,
|
|
|
|
|
BuiltSources,
|
|
|
|
|
Sources,
|
|
|
|
|
SubDirs
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TopTarget topTarget() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parses the bin_PROGRAM target and stores it in m_executable.
|
|
|
|
|
*/
|
2024-07-15 14:02:03 +02:00
|
|
|
void parseBinPrograms(QTextStream *textStream);
|
2011-11-29 14:19:28 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parses all values from a _SOURCE target and appends them to
|
|
|
|
|
* the m_sources list.
|
|
|
|
|
*/
|
2024-07-15 14:02:03 +02:00
|
|
|
void parseSources(QTextStream *textStream);
|
2011-11-29 14:19:28 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parses all sub directories for files having the extension
|
|
|
|
|
* specified by 'AM_DEFAULT_SOURCE_EXT ='. The result will be
|
|
|
|
|
* append to the m_sources list. Corresponding header files
|
|
|
|
|
* will automatically be attached too.
|
|
|
|
|
*/
|
2024-07-15 14:02:03 +02:00
|
|
|
void parseDefaultSourceExtensions(QTextStream *textStream);
|
2011-11-29 14:19:28 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parses all sub directories specified by the SUBDIRS target and
|
|
|
|
|
* adds the found sources to the m_sources list. The found makefiles
|
|
|
|
|
* get added to the m_makefiles list.
|
|
|
|
|
*/
|
2024-07-15 14:02:03 +02:00
|
|
|
void parseSubDirs(QTextStream *textStream);
|
2011-11-29 14:19:28 +01:00
|
|
|
|
|
|
|
|
/**
|
2013-10-07 13:34:40 +02:00
|
|
|
* Helper function for parseDefaultExtensions(). Returns recursively all sources
|
2011-11-29 14:19:28 +01:00
|
|
|
* inside the directory \p directory that match with the extension \p extension.
|
|
|
|
|
*/
|
|
|
|
|
QStringList directorySources(const QString &directory,
|
|
|
|
|
const QStringList &extensions);
|
|
|
|
|
|
|
|
|
|
/**
|
2013-10-07 13:34:40 +02:00
|
|
|
* Helper function for all parse-functions. Returns each value of a target as string in
|
2011-11-29 14:19:28 +01:00
|
|
|
* the stringlist. The current line m_line is used as starting point and increased
|
|
|
|
|
* if the current line ends with a \.
|
|
|
|
|
*
|
|
|
|
|
* Example: For the text
|
|
|
|
|
* \code
|
|
|
|
|
* my_SOURCES = a.cpp\
|
|
|
|
|
* b.cpp c.cpp\
|
|
|
|
|
* d.cpp
|
|
|
|
|
* \endcode
|
|
|
|
|
* the string list contains all 4 *.cpp files. m_line is positioned to d.cpp afterwards.
|
|
|
|
|
* Variables like $(test) are skipped and not part of the return value.
|
|
|
|
|
*
|
|
|
|
|
* @param hasVariables Optional output parameter. Is set to true, if the target values
|
|
|
|
|
* contained a variable like $(test). Note that all variables are not
|
|
|
|
|
* part of the return value, as they cannot get interpreted currently.
|
|
|
|
|
*/
|
2024-07-15 14:02:03 +02:00
|
|
|
QStringList targetValues(QTextStream *textStream, bool *hasVariables = nullptr);
|
2011-11-29 14:19:28 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds recursively all sources of the current folder to m_sources and removes
|
|
|
|
|
* all duplicates. The Makefile.am is not parsed, only the folders and files are
|
2013-10-07 13:34:40 +02:00
|
|
|
* handled. This function should only be called, if the sources parsing in the Makefile.am
|
2011-11-29 14:19:28 +01:00
|
|
|
* failed because variables (e.g. $(test)) have been used.
|
|
|
|
|
*/
|
|
|
|
|
void addAllSources();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds all include paths to m_includePaths. TODO: Currently this is done
|
|
|
|
|
* by parsing the generated Makefile. It might be more efficient and reliable
|
|
|
|
|
* to parse the Makefile.am instead.
|
|
|
|
|
*/
|
|
|
|
|
void parseIncludePaths();
|
|
|
|
|
|
|
|
|
|
/**
|
2013-10-07 13:34:40 +02:00
|
|
|
* Helper function for MakefileParser::directorySources(). Appends the name of the headerfile
|
2011-11-29 14:19:28 +01:00
|
|
|
* to \p list, if the header could be found in the directory specified by \p dir.
|
|
|
|
|
* The headerfile base name is defined by \p fileName.
|
|
|
|
|
*/
|
|
|
|
|
static void appendHeader(QStringList &list, const QDir &dir, const QString &fileName);
|
|
|
|
|
|
2013-02-03 20:47:45 +04:00
|
|
|
/**
|
|
|
|
|
* If line starts with identifier and = goes next, return identifier.
|
|
|
|
|
* Identifier is valid target name and it matches regexp [a-zA-Z1-9_]+
|
|
|
|
|
*/
|
|
|
|
|
static QString parseIdentifierBeforeAssign(const QString &line);
|
|
|
|
|
|
2013-04-29 02:31:43 +04:00
|
|
|
/**
|
|
|
|
|
* Parses list of space-separated terms after "="
|
|
|
|
|
*/
|
|
|
|
|
static QStringList parseTermsAfterAssign(const QString &line);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If term is compiler flag -D<macro>, adds macro to defines and returns true.
|
|
|
|
|
*/
|
|
|
|
|
bool maybeParseDefine(const QString &term);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If term is compiler flag -I<path>, adds path to includes and returns true.
|
|
|
|
|
* @param term Term itself
|
|
|
|
|
* @param dirName Directory where Makefile placed
|
|
|
|
|
*/
|
|
|
|
|
bool maybeParseInclude(const QString &term, const QString &dirName);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If term is compiler flag -<flag>, adds it to cflags and returns true.
|
|
|
|
|
*/
|
|
|
|
|
bool maybeParseCFlag(const QString &term);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If term is compiler flag -<flag>, adds it to cxxflags and returns true.
|
|
|
|
|
*/
|
|
|
|
|
bool maybeParseCXXFlag(const QString &term);
|
|
|
|
|
|
2015-07-09 13:27:27 +02:00
|
|
|
/**
|
|
|
|
|
* If term is compiler flag -<flag>, adds it to cppflags and returns true.
|
|
|
|
|
*/
|
|
|
|
|
bool maybeParseCPPFlag(const QString &term);
|
|
|
|
|
|
2016-02-03 17:21:12 +01:00
|
|
|
bool m_success = false; ///< Return value for MakefileParser::parse().
|
2021-12-16 10:42:33 +01:00
|
|
|
bool m_subDirsEmpty = false;///< States if last subdirs var was empty
|
2011-11-29 14:19:28 +01:00
|
|
|
|
2024-07-15 13:28:18 +02:00
|
|
|
QFuture<void> m_future; ///< For periodic checking of cancelled state.
|
2011-11-29 14:19:28 +01:00
|
|
|
|
|
|
|
|
QString m_makefile; ///< Filename of the makefile
|
2024-07-15 11:27:43 +02:00
|
|
|
MakefileParserOutputData m_outputData;
|
2015-07-09 13:27:27 +02:00
|
|
|
QStringList m_cppflags; ///< The cpp flags, which will be part of both cflags and cxxflags
|
2011-11-29 14:19:28 +01:00
|
|
|
|
|
|
|
|
QString m_line; ///< Current line of the makefile
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-29 17:11:01 +02:00
|
|
|
} // AutotoolsProjectManager::Internal
|