| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the qmake application of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "projectgenerator.h"
|
|---|
| 43 | #include "option.h"
|
|---|
| 44 | #include <qdatetime.h>
|
|---|
| 45 | #include <qdir.h>
|
|---|
| 46 | #include <qfile.h>
|
|---|
| 47 | #include <qfileinfo.h>
|
|---|
| 48 | #include <qregexp.h>
|
|---|
| 49 |
|
|---|
| 50 | QT_BEGIN_NAMESPACE
|
|---|
| 51 |
|
|---|
| 52 | QString project_builtin_regx() //calculate the builtin regular expression..
|
|---|
| 53 | {
|
|---|
| 54 | QString ret;
|
|---|
| 55 | QStringList builtin_exts;
|
|---|
| 56 | builtin_exts << Option::c_ext << Option::ui_ext << Option::yacc_ext << Option::lex_ext << ".ts" << ".xlf" << ".qrc";
|
|---|
| 57 | builtin_exts += Option::h_ext + Option::cpp_ext;
|
|---|
| 58 | for(int i = 0; i < builtin_exts.size(); ++i) {
|
|---|
| 59 | if(!ret.isEmpty())
|
|---|
| 60 | ret += "; ";
|
|---|
| 61 | ret += QString("*") + builtin_exts[i];
|
|---|
| 62 | }
|
|---|
| 63 | return ret;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | ProjectGenerator::ProjectGenerator() : MakefileGenerator(), init_flag(false)
|
|---|
| 67 | {
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | void
|
|---|
| 71 | ProjectGenerator::init()
|
|---|
| 72 | {
|
|---|
| 73 | if(init_flag)
|
|---|
| 74 | return;
|
|---|
| 75 | int file_count = 0;
|
|---|
| 76 | init_flag = true;
|
|---|
| 77 | verifyCompilers();
|
|---|
| 78 |
|
|---|
| 79 | project->read(QMakeProject::ReadFeatures);
|
|---|
| 80 | project->variables()["CONFIG"].clear();
|
|---|
| 81 |
|
|---|
| 82 | QMap<QString, QStringList> &v = project->variables();
|
|---|
| 83 | QString templ = Option::user_template.isEmpty() ? QString("app") : Option::user_template;
|
|---|
| 84 | if(!Option::user_template_prefix.isEmpty())
|
|---|
| 85 | templ.prepend(Option::user_template_prefix);
|
|---|
| 86 | v["TEMPLATE_ASSIGN"] += templ;
|
|---|
| 87 |
|
|---|
| 88 | //figure out target
|
|---|
| 89 | if(Option::output.fileName() == "-")
|
|---|
| 90 | v["TARGET_ASSIGN"] = QStringList("unknown");
|
|---|
| 91 | else
|
|---|
| 92 | v["TARGET_ASSIGN"] = QStringList(QFileInfo(Option::output).baseName());
|
|---|
| 93 |
|
|---|
| 94 | //the scary stuff
|
|---|
| 95 | if(project->first("TEMPLATE_ASSIGN") != "subdirs") {
|
|---|
| 96 | QString builtin_regex = project_builtin_regx();
|
|---|
| 97 | QStringList dirs = Option::projfile::project_dirs;
|
|---|
| 98 | if(Option::projfile::do_pwd) {
|
|---|
| 99 | if(!v["INCLUDEPATH"].contains("."))
|
|---|
| 100 | v["INCLUDEPATH"] += ".";
|
|---|
| 101 | dirs.prepend(qmake_getpwd());
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | for(int i = 0; i < dirs.count(); ++i) {
|
|---|
| 105 | QString dir, regex, pd = dirs.at(i);
|
|---|
| 106 | bool add_depend = false;
|
|---|
| 107 | if(exists(pd)) {
|
|---|
| 108 | QFileInfo fi(fileInfo(pd));
|
|---|
| 109 | if(fi.isDir()) {
|
|---|
| 110 | dir = pd;
|
|---|
| 111 | add_depend = true;
|
|---|
| 112 | if(dir.right(1) != Option::dir_sep)
|
|---|
| 113 | dir += Option::dir_sep;
|
|---|
| 114 | if(Option::recursive == Option::QMAKE_RECURSIVE_YES) {
|
|---|
| 115 | QStringList files = QDir(dir).entryList(QDir::Files);
|
|---|
| 116 | for(int i = 0; i < (int)files.count(); i++) {
|
|---|
| 117 | if(files[i] != "." && files[i] != "..")
|
|---|
| 118 | dirs.append(dir + files[i] + QDir::separator() + builtin_regex);
|
|---|
| 119 | }
|
|---|
| 120 | }
|
|---|
| 121 | regex = builtin_regex;
|
|---|
| 122 | } else {
|
|---|
| 123 | QString file = pd;
|
|---|
| 124 | int s = file.lastIndexOf(Option::dir_sep);
|
|---|
| 125 | if(s != -1)
|
|---|
| 126 | dir = file.left(s+1);
|
|---|
| 127 | if(addFile(file)) {
|
|---|
| 128 | add_depend = true;
|
|---|
| 129 | file_count++;
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 | } else { //regexp
|
|---|
| 133 | regex = pd;
|
|---|
| 134 | }
|
|---|
| 135 | if(!regex.isEmpty()) {
|
|---|
| 136 | int s = regex.lastIndexOf(Option::dir_sep);
|
|---|
| 137 | if(s != -1) {
|
|---|
| 138 | dir = regex.left(s+1);
|
|---|
| 139 | regex = regex.right(regex.length() - (s+1));
|
|---|
| 140 | }
|
|---|
| 141 | if(Option::recursive == Option::QMAKE_RECURSIVE_YES) {
|
|---|
| 142 | QStringList entries = QDir(dir).entryList(QDir::Dirs);
|
|---|
| 143 | for(int i = 0; i < (int)entries.count(); i++) {
|
|---|
| 144 | if(entries[i] != "." && entries[i] != "..") {
|
|---|
| 145 | dirs.append(dir + entries[i] + QDir::separator() + regex);
|
|---|
| 146 | }
|
|---|
| 147 | }
|
|---|
| 148 | }
|
|---|
| 149 | QStringList files = QDir(dir).entryList(QDir::nameFiltersFromString(regex));
|
|---|
| 150 | for(int i = 0; i < (int)files.count(); i++) {
|
|---|
| 151 | QString file = dir + files[i];
|
|---|
| 152 | if (addFile(file)) {
|
|---|
| 153 | add_depend = true;
|
|---|
| 154 | file_count++;
|
|---|
| 155 | }
|
|---|
| 156 | }
|
|---|
| 157 | }
|
|---|
| 158 | if(add_depend && !dir.isEmpty() && !v["DEPENDPATH"].contains(dir, Qt::CaseInsensitive)) {
|
|---|
| 159 | QFileInfo fi(fileInfo(dir));
|
|---|
| 160 | if(fi.absoluteFilePath() != qmake_getpwd())
|
|---|
| 161 | v["DEPENDPATH"] += fileFixify(dir);
|
|---|
| 162 | }
|
|---|
| 163 | }
|
|---|
| 164 | }
|
|---|
| 165 | if(!file_count) { //shall we try a subdir?
|
|---|
| 166 | QStringList knownDirs = Option::projfile::project_dirs;
|
|---|
| 167 | if(Option::projfile::do_pwd)
|
|---|
| 168 | knownDirs.prepend(".");
|
|---|
| 169 | const QString out_file = fileFixify(Option::output.fileName());
|
|---|
| 170 | for(int i = 0; i < knownDirs.count(); ++i) {
|
|---|
| 171 | QString pd = knownDirs.at(i);
|
|---|
| 172 | if(exists(pd)) {
|
|---|
| 173 | QString newdir = pd;
|
|---|
| 174 | QFileInfo fi(fileInfo(newdir));
|
|---|
| 175 | if(fi.isDir()) {
|
|---|
| 176 | newdir = fileFixify(newdir);
|
|---|
| 177 | QStringList &subdirs = v["SUBDIRS"];
|
|---|
| 178 | if(exists(fi.filePath() + QDir::separator() + fi.fileName() + Option::pro_ext) &&
|
|---|
| 179 | !subdirs.contains(newdir, Qt::CaseInsensitive)) {
|
|---|
| 180 | subdirs.append(newdir);
|
|---|
| 181 | } else {
|
|---|
| 182 | QStringList profiles = QDir(newdir).entryList(QStringList("*" + Option::pro_ext), QDir::Files);
|
|---|
| 183 | for(int i = 0; i < (int)profiles.count(); i++) {
|
|---|
| 184 | QString nd = newdir;
|
|---|
|
|---|