summaryrefslogtreecommitdiff
path: root/qmake/project.cpp
Side-by-side diff
Diffstat (limited to 'qmake/project.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/project.cpp407
1 files changed, 245 insertions, 162 deletions
diff --git a/qmake/project.cpp b/qmake/project.cpp
index 44eb503..834823d 100644
--- a/qmake/project.cpp
+++ b/qmake/project.cpp
@@ -68,5 +68,10 @@ static QString varMap(const QString &x)
QString ret(x);
- ret.replace(QRegExp("^TMAKE"), "QMAKE");
+ if(ret.startsWith("TMAKE")) //tmake no more!
+ ret = "QMAKE" + ret.mid(5);
if(ret == "INTERFACES")
ret = "FORMS";
+ if(ret == "QMAKE_POST_BUILD")
+ ret = "QMAKE_POST_LINK";
+ if(ret == "TARGETDEPS")
+ ret = "POST_TARGETDEPS";
return ret;
@@ -108,3 +113,3 @@ static QStringList split_value_list(const QString &vals, bool do_semicolon=FALSE
quote.push(vals[x]);
- } else if(quote.isEmpty() &&
+ } else if(quote.isEmpty() &&
((do_semicolon && vals[x] == ';') || vals[x] == ' ')) {
@@ -124,6 +129,8 @@ QMakeProject::QMakeProject()
bool
-QMakeProject::parse(QString t, QMap<QString, QStringList> &place)
+QMakeProject::parse(const QString &t, QMap<QString, QStringList> &place)
{
QString s = t.simplifyWhiteSpace();
- s.replace(QRegExp("#.*$"), ""); /* bye comments */
+ int hash_mark = s.find('#');
+ if(hash_mark != -1) //good bye comments
+ s = s.left(hash_mark);
if(s.isEmpty()) /* blank_line */
@@ -156,13 +163,17 @@ QMakeProject::parse(QString t, QMap<QString, QStringList> &place)
int parens = 0, scope_count=0;
- while(*d && *d != '=') {
- if((*d == '+' || *d == '-' || *d == '*' || *d == '~')) {
- if(*(d+1) == '=') {
+ while(*d) {
+ if(!parens) {
+ if(*d == '=')
break;
- } else if(*(d+1) == ' ') {
- const char *k = d + 1;
- SKIP_WS(k);
- if(*k == '=') {
- QString msg;
- qmake_error_msg(*d + "must be followed immediatly by =");
- return FALSE;
+ if(*d == '+' || *d == '-' || *d == '*' || *d == '~') {
+ if(*(d+1) == '=') {
+ break;
+ } else if(*(d+1) == ' ') {
+ const char *k = d + 1;
+ SKIP_WS(k);
+ if(*k == '=') {
+ QString msg;
+ qmake_error_msg(*d + "must be followed immediately by =");
+ return FALSE;
+ }
}
@@ -219,3 +230,3 @@ QMakeProject::parse(QString t, QMap<QString, QStringList> &place)
} else {
- test = isActiveConfig(comp_scope.stripWhiteSpace());
+ test = isActiveConfig(comp_scope.stripWhiteSpace(), TRUE);
}
@@ -289,3 +300,3 @@ QMakeProject::parse(QString t, QMap<QString, QStringList> &place)
/* vallist is the broken up list of values */
- QStringList vallist = split_value_list(vals, (var == "DEPENDPATH" || var == "INCLUDEPATH"));
+ QStringList vallist = split_value_list(vals, (var == "DEPENDPATH" || var == "INCLUDEPATH"));
if(!vallist.grep("=").isEmpty())
@@ -357,3 +368,3 @@ QMakeProject::parse(QString t, QMap<QString, QStringList> &place)
bool
-QMakeProject::read(QString file, QMap<QString, QStringList> &place)
+QMakeProject::read(const QString &file, QMap<QString, QStringList> &place)
{
@@ -365,7 +376,7 @@ QMakeProject::read(QString file, QMap<QString, QStringList> &place)
- file = Option::fixPathToLocalOS(file);
- doVariableReplace(file, place);
+ QString filename = Option::fixPathToLocalOS(file);
+ doVariableReplace(filename, place);
bool ret = FALSE, using_stdin = FALSE;
QFile qfile;
- if(!strcmp(file, "-")) {
+ if(!strcmp(filename, "-")) {
qfile.setName("");
@@ -374,3 +385,3 @@ QMakeProject::read(QString file, QMap<QString, QStringList> &place)
} else {
- qfile.setName(file);
+ qfile.setName(filename);
ret = qfile.open(IO_ReadOnly);
@@ -380,3 +391,3 @@ QMakeProject::read(QString file, QMap<QString, QStringList> &place)
QString s, line;
- parser.file = file;
+ parser.file = filename;
parser.line_no = 0;
@@ -386,3 +397,7 @@ QMakeProject::read(QString file, QMap<QString, QStringList> &place)
int prelen = line.length();
- line.replace(QRegExp("#.*$"), ""); // bye comments
+ {
+ int hash_mark = line.find('#');
+ if(hash_mark != -1) //bye comments
+ line = line.left(hash_mark);
+ }
if(!line.isEmpty() && line.right(1) == "\\") {
@@ -410,4 +425,11 @@ QMakeProject::read(QString file, QMap<QString, QStringList> &place)
bool
-QMakeProject::read(QString project, QString)
+QMakeProject::read(const QString &project, const QString &, bool just_project)
{
+ if(just_project) { //nothing more, nothing less
+ pfile = project;
+ if(pfile != "-" && !QFile::exists(pfile) && pfile.right(4) != ".pro")
+ pfile += ".pro";
+ return read(pfile, vars);
+ }
+
if(cfile.isEmpty()) {
@@ -416,2 +438,4 @@ QMakeProject::read(QString project, QString)
base_vars["QMAKE_EXT_H"] = Option::h_ext;
+ if(!Option::user_template_prefix.isEmpty())
+ base_vars["TEMPLATE_PREFIX"] = Option::user_template_prefix;
@@ -443,16 +467,5 @@ QMakeProject::read(QString project, QString)
/* prefer $QTDIR if it is set */
- /* prefer QMAKESPECSDIR -cl */
-
- if (getenv("QTDIR")) {
+ if (getenv("QTDIR"))
mkspec_roots << getenv("QTDIR");
- }
mkspec_roots << qInstallPathData();
-
- if (Option::mkfile::qmakespec.isEmpty() && getenv("QMAKESPECSDIR")){
- QString mkspec = QString(getenv("QMAKESPECSDIR")) + QDir::separator() +
- QDir::separator() + "default";
- if(QFile::exists(mkspec))
- Option::mkfile::qmakespec = mkspec;
- }
-
if(Option::mkfile::qmakespec.isEmpty()) {
@@ -466,7 +479,6 @@ QMakeProject::read(QString project, QString)
}
- }
-
- if(Option::mkfile::qmakespec.isEmpty()) {
- fprintf(stderr, "QMAKESPEC has not been set, so configuration cannot be deduced.\n");
- return FALSE;
+ if(Option::mkfile::qmakespec.isEmpty()) {
+ fprintf(stderr, "QMAKESPEC has not been set, so configuration cannot be deduced.\n");
+ return FALSE;
+ }
}
@@ -546,8 +558,10 @@ QMakeProject::read(QString project, QString)
- if(vars["TEMPLATE"].isEmpty())
- vars["TEMPLATE"].append(QString("app"));
- else
- vars["TEMPLATE"].first().replace(QRegExp("\\.t$"), "");
- if(!Option::user_template_prefix.isEmpty())
- vars["TEMPLATE"].first().prepend(Option::user_template_prefix);
+ QStringList &templ = vars["TEMPLATE"];
+ if(templ.isEmpty())
+ templ.append(QString("app"));
+ else if(vars["TEMPLATE"].first().endsWith(".t"))
+ templ = QStringList(templ.first().left(templ.first().length() - 2));
+ if ( !Option::user_template_prefix.isEmpty() ) {
+ templ.first().prepend(Option::user_template_prefix);
+ }
@@ -581,3 +595,3 @@ QMakeProject::read(QString project, QString)
bool
-QMakeProject::isActiveConfig(const QString &x)
+QMakeProject::isActiveConfig(const QString &x, bool regex)
{
@@ -586,5 +600,4 @@ QMakeProject::isActiveConfig(const QString &x)
- QRegExp re(x, FALSE, TRUE);
- if((Option::target_mode == Option::TARG_MACX_MODE || Option::target_mode == Option::TARG_QNX6_MODE || Option::target_mode == Option::TARG_UNIX_MODE) &&
- x == "unix")
+ if((Option::target_mode == Option::TARG_MACX_MODE || Option::target_mode == Option::TARG_QNX6_MODE ||
+ Option::target_mode == Option::TARG_UNIX_MODE) && x == "unix")
return TRUE;
@@ -603,5 +616,6 @@ QMakeProject::isActiveConfig(const QString &x)
+ QRegExp re(x, FALSE, TRUE);
QString spec = Option::mkfile::qmakespec.right(Option::mkfile::qmakespec.length() -
(Option::mkfile::qmakespec.findRev(QDir::separator())+1));
- if(re.exactMatch(spec))
+ if((regex && re.exactMatch(spec)) || (!regex && spec == x))
return TRUE;
@@ -618,3 +632,3 @@ QMakeProject::isActiveConfig(const QString &x)
r = r.mid(r.findRev('/') + 1);
- if(re.exactMatch(r))
+ if((regex && re.exactMatch(r)) || (!regex && r == x))
return TRUE;
@@ -627,2 +641,3 @@ QMakeProject::isActiveConfig(const QString &x)
for(QStringList::Iterator it = configs.begin(); it != configs.end(); ++it) {
+ if((regex && re.exactMatch((*it))) || (!regex && (*it) == x))
if(re.exactMatch((*it)))
@@ -634,3 +649,3 @@ QMakeProject::isActiveConfig(const QString &x)
bool
-QMakeProject::doProjectTest(QString func, const QString &params, QMap<QString, QStringList> &place)
+QMakeProject::doProjectTest(const QString& func, const QString &params, QMap<QString, QStringList> &place)
{
@@ -646,3 +661,3 @@ QMakeProject::doProjectTest(QString func, const QString &params, QMap<QString, Q
bool
-QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStringList> &place)
+QMakeProject::doProjectTest(const QString& func, QStringList args, QMap<QString, QStringList> &place)
{
@@ -656,2 +671,12 @@ QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStrin
return doProjectCheckReqs(args, place);
+ } else if(func == "equals") {
+ if(args.count() != 2) {
+ fprintf(stderr, "%s:%d: equals(variable, value) requires two arguments.\n", parser.file.latin1(),
+ parser.line_no);
+ return FALSE;
+ }
+ QString value = args[1];
+ if((value.left(1) == "\"" || value.left(1) == "'") && value.right(1) == value.left(1))
+ value = value.mid(1, value.length()-2);
+ return vars[args[0]].join(" ") == value;
} else if(func == "exists") {
@@ -693,3 +718,3 @@ QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStrin
for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
- if(regx.exactMatch((*it)))
+ if(regx.exactMatch((*it)))
return TRUE;
@@ -807,4 +832,7 @@ QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStrin
bool r = read(file.latin1(), place);
- if(r)
+ if(r)
vars["QMAKE_INTERNAL_INCLUDED_FILES"].append(file);
+ else
+ warn_msg(WarnParser, "%s:%d: Failure to include file %s.",
+ pi.file.latin1(), pi.line_no, file.latin1());
parser = pi;
@@ -821,2 +849,7 @@ QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStrin
QString msg = args.first();
+ if((msg.startsWith("\"") || msg.startsWith("'")) && msg.endsWith(msg.left(1)))
+ msg = msg.mid(1, msg.length()-2);
+ msg.replace(QString("${QMAKE_FILE}"), parser.file.latin1());
+ msg.replace(QString("${QMAKE_LINE_NUMBER}"), QString::number(parser.line_no));
+ msg.replace(QString("${QMAKE_DATE}"), QDateTime::currentDateTime().toString());
doVariableReplace(msg, place);
@@ -859,3 +892,3 @@ QMakeProject::doProjectCheckReqs(const QStringList &deps, QMap<QString, QStringL
} else {
- test = isActiveConfig(chk);
+ test = isActiveConfig(chk, TRUE);
}
@@ -879,114 +912,164 @@ QMakeProject::doVariableReplace(QString &str, const QMap<QString, QStringList> &
{
- for(int x = 0, rep; x < 5; x++) {
- QRegExp reg_var;
- reg_var.setMinimal(TRUE);
- if( x == 0 ) //function blocked out by {}'s
- reg_var = QRegExp("\\$\\$\\{([a-zA-Z0-9_]*)\\((\\(.|(.*)\\)*)\\)\\}");
- else if( x == 1 ) //variables blocked out by {}'s
- reg_var = QRegExp("\\$\\$\\{([a-zA-Z0-9_\\.-]*)\\}");
- else if(x == 2) //environment
- reg_var = QRegExp("\\$\\$\\(([a-zA-Z0-9_\\.-]*)\\)");
- else if(x == 3) //function
- reg_var = QRegExp("\\$\\$([a-zA-Z0-9_]*)\\((\\(.|(.*)\\)*)\\)");
- else if(x == 4) //normal variable
- reg_var = QRegExp("\\$\\$([a-zA-Z0-9_\\.-]*)");
- while((rep = reg_var.search(str)) != -1) {
- QString replacement;
- if(x == 2) {//environment
- replacement = getenv(reg_var.cap(1));
- } else if(x == 0 || x == 3) { //function
- QStringList args = split_arg_list(reg_var.cap(2));
- for(QStringList::Iterator arit = args.begin(); arit != args.end(); ++arit) {
- (*arit) = (*arit).stripWhiteSpace(); // blah, get rid of space
- doVariableReplace((*arit), place);
- }
- debug_msg(1, "Running function: %s( %s )", reg_var.cap(1).latin1(), args.join("::").latin1());
- if(reg_var.cap(1).lower() == "member") {
- if(args.count() < 1 || args.count() > 2) {
- fprintf(stderr, "%s:%d: member(var, place) requires two arguments.\n",
- parser.file.latin1(), parser.line_no);
- } else {
- uint pos = 0;
- if(args.count() == 2)
- pos = args[1].toInt();
- const QStringList &var = place[varMap(args.first())];
- if(var.count() >= pos)
- replacement = var[pos];
- }
- } else if(reg_var.cap(1).lower() == "list") {
- if(args.count() != 1) {
- fprintf(stderr, "%s:%d: list(vals) requires one"
- "argument.\n", parser.file.latin1(), parser.line_no);
- } else {
- static int x = 0;
- replacement.sprintf(".QMAKE_INTERNAL_TMP_VAR_%d", x++);
- (*((QMap<QString, QStringList>*)&place))[replacement] = split_value_list(args.first());
- }
- } else if(reg_var.cap(1).lower() == "join") {
- if(args.count() < 1 || args.count() > 4) {
- fprintf(stderr, "%s:%d: join(var, glue, before, after) requires four"
- "arguments.\n", parser.file.latin1(), parser.line_no);
- } else {
- QString glue, before, after;
- if(args.count() >= 2)
- glue = args[1].replace("\"", "" );
- if(args.count() >= 3)
- before = args[2].replace("\"", "" );
- if(args.count() == 4)
- after = args[3].replace("\"", "" );
- const QStringList &var = place[varMap(args.first())];
- if(!var.isEmpty())
- replacement = before + var.join(glue) + after;
+ for(int var_begin, var_last=0; (var_begin = str.find("$$", var_last)) != -1; var_last = var_begin) {
+ if(var_begin >= int( str.length() + 2 ) ) {
+ break;
+ } else if(var_begin != 0 && str[var_begin-1] == '\\') {
+ str.replace(var_begin-1, 1, "");
+ var_begin += 1;
+ continue;
+ }
+
+ int var_incr = var_begin + 2;
+ bool in_braces = FALSE, as_env = FALSE;
+ if(str[var_incr] == '{') {
+ in_braces = TRUE;
+ var_incr++;
+ while(var_incr < int( str.length() ) &&
+ (str[var_incr] == ' ' || str[var_incr] == '\t' || str[var_incr] == '\n'))
+ var_incr++;
+ }
+ if(str[var_incr] == '(') {
+ as_env = TRUE;
+ var_incr++;
+ }
+ QString val, args;
+ while(var_incr < int( str.length() ) &&
+ (str[var_incr].isLetter() || str[var_incr].isNumber() || str[var_incr] == '.' || str[var_incr] == '_'))
+ val += str[var_incr++];
+ if(as_env) {
+ if(str[var_incr] != ')') {
+ var_incr++;
+ warn_msg(WarnParser, "%s:%d: Unterminated env-variable replacement '%s' (%s)",
+ parser.file.latin1(), parser.line_no,
+ str.mid(var_begin, QMAX(var_incr - var_begin, int(str.length()))).latin1(), str.latin1());
+ var_begin += var_incr;
+ continue;
+ }
+ var_incr++;
+ } else if(str[var_incr] == '(') { //args
+ for(int parens = 0; var_incr < int( str.length() ); var_incr++) {
+ if(str[var_incr] == '(') {
+ parens++;
+ if(parens == 1)
+ continue;
+ } else if(str[var_incr] == ')') {
+ parens--;
+ if(!parens) {
+ var_incr++;
+ break;
}
- } else if(reg_var.cap(1).lower() == "find") {
- if(args.count() != 2) {
- fprintf(stderr, "%s:%d find(var, str) requires two arguments\n",
- parser.file.latin1(), parser.line_no);
- } else {
- QRegExp regx(args[1]);
- const QStringList &var = place[varMap(args.first())];
- for(QStringList::ConstIterator vit = var.begin();
- vit != var.end(); ++vit) {
- if(regx.search(*vit) != -1) {
- if(!replacement.isEmpty())
- replacement += " ";
- replacement += (*vit);
- }
+ }
+ args += str[var_incr];
+ }
+ }
+ if(var_incr > int( str.length() ) || (in_braces && str[var_incr] != '}')) {
+ var_incr++;
+ warn_msg(WarnParser, "%s:%d: Unterminated variable replacement '%s' (%s)",
+ parser.file.latin1(), parser.line_no,
+ str.mid(var_begin, QMAX(var_incr - var_begin, int( str.length() ))).latin1(), str.latin1());
+ var_begin += var_incr;
+ continue;
+ } else if(in_braces) {
+ var_incr++;
+ }
+
+ QString replacement;
+ if(as_env) {
+ replacement = getenv(val);
+ } else if(args.isEmpty()) {
+ if(val.left(1) == ".")
+ replacement = "";
+ else if(val == "LITERAL_WHITESPACE")
+ replacement = "\t";
+ else
+ replacement = place[varMap(val)].join(" ");
+ } else {
+ QStringList arg_list = split_arg_list(args);
+ for(QStringList::Iterator arit = arg_list.begin(); arit != arg_list.end(); ++arit) {
+ (*arit) = (*arit).stripWhiteSpace(); // blah, get rid of space
+ doVariableReplace((*arit), place);
+ }
+ debug_msg(1, "Running function: %s( %s )", val.latin1(), arg_list.join("::").latin1());
+ if(val.lower() == "member") {
+ if(arg_list.count() < 1 || arg_list.count() > 2) {
+ fprintf(stderr, "%s:%d: member(var, place) requires two arguments.\n",
+ parser.file.latin1(), parser.line_no);
+ } else {
+ uint pos = 0;
+ if(arg_list.count() == 2)
+ pos = arg_list[1].toInt();
+ const QStringList &var = place[varMap(arg_list.first())];
+ if(var.count() >= pos)
+ replacement = var[pos];
+ }
+ } else if(val.lower() == "list") {
+ static int x = 0;
+ replacement.sprintf(".QMAKE_INTERNAL_TMP_VAR_%d", x++);
+ QStringList &lst = (*((QMap<QString, QStringList>*)&place))[replacement];
+ lst.clear();
+ for(QStringList::ConstIterator arg_it = arg_list.begin();
+ arg_it != arg_list.end(); ++arg_it)
+ lst += split_value_list((*arg_it));
+ } else if(val.lower() == "join") {
+ if(arg_list.count() < 1 || arg_list.count() > 4) {
+ fprintf(stderr, "%s:%d: join(var, glue, before, after) requires four"
+ "arguments.\n", parser.file.latin1(), parser.line_no);
+ } else {
+ QString glue, before, after;
+ if(arg_list.count() >= 2)
+ glue = arg_list[1].replace("\"", "" );
+ if(arg_list.count() >= 3)
+ before = arg_list[2].replace("\"", "" );
+ if(arg_list.count() == 4)
+ after = arg_list[3].replace("\"", "" );
+ const QStringList &var = place[varMap(arg_list.first())];
+ if(!var.isEmpty())
+ replacement = before + var.join(glue) + after;
+ }
+ } else if(val.lower() == "find") {
+ if(arg_list.count() != 2) {
+ fprintf(stderr, "%s:%d find(var, str) requires two arguments\n",
+ parser.file.latin1(), parser.line_no);
+ } else {
+ QRegExp regx(arg_list[1]);
+ const QStringList &var = place[varMap(arg_list.first())];
+ for(QStringList::ConstIterator vit = var.begin();
+ vit != var.end(); ++vit) {
+ if(regx.search(*vit) != -1) {
+ if(!replacement.isEmpty())
+ replacement += " ";
+ replacement += (*vit);
}
}
- } else if(reg_var.cap(1).lower() == "system") {
- if(args.count() != 1) {
- fprintf(stderr, "%s:%d system(execut) requires one argument\n",
- parser.file.latin1(), parser.line_no);
- } else {
- char buff[256];
- FILE *proc = QT_POPEN(args.join(" ").latin1(), "r");
- while(proc && !feof(proc)) {
- int read_in = fread(buff, 1, 255, proc);
- if(!read_in)
- break;
- for(int i = 0; i < read_in; i++) {
- if(buff[i] == '\n' || buff[i] == '\t')
- buff[i] = ' ';
- }
- buff[read_in] = '\0';
- replacement += buff;
+ }
+ } else if(val.lower() == "system") {
+ if(arg_list.count() != 1) {
+ fprintf(stderr, "%s:%d system(execut) requires one argument\n",
+ parser.file.latin1(), parser.line_no);
+ } else {
+ char buff[256];
+ FILE *proc = QT_POPEN(arg_list.join(" ").latin1(), "r");
+ while(proc && !feof(proc)) {
+ int read_in = fread(buff, 1, 255, proc);
+ if(!read_in)
+ break;
+ for(int i = 0; i < read_in; i++) {
+ if(buff[i] == '\n' || buff[i] == '\t')
+ buff[i] = ' ';
}
+ buff[read_in] = '\0';
+ replacement += buff;
}
- } else {
- fprintf(stderr, "%s:%d: Unknown replace function: %s\n",
- parser.file.latin1(), parser.line_no, reg_var.cap(1).latin1());
}
- } else { //variable
- if(reg_var.cap(1).left(1) == ".")
- replacement = "";
- else if(reg_var.cap(1) == "LITERAL_WHITESPACE")
- replacement = "\t";
- else
- replacement = place[varMap(reg_var.cap(1))].join(" ");
+ } else {
+ fprintf(stderr, "%s:%d: Unknown replace function: %s\n",
+ parser.file.latin1(), parser.line_no, val.latin1());
}
- debug_msg(2, "Project parser: %d (%s) :: %s -> %s", x, str.latin1(),
- reg_var.capturedTexts().join("::").latin1(), replacement.latin1());
- str.replace(rep, reg_var.matchedLength(), replacement);
}
+ //actually do replacement now..
+ int mlen = var_incr - var_begin;
+ debug_msg(2, "Project Parser [var replace]: '%s' :: %s -> %s", str.latin1(),
+ str.mid(var_begin, mlen).latin1(), replacement.latin1());
+ str.replace(var_begin, mlen, replacement);
+ var_begin += replacement.length();
}