[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
---|
| 5 | **
|
---|
| 6 | ** This file is part of the qmake application of the Qt Toolkit.
|
---|
| 7 | **
|
---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 9 | ** Commercial Usage
|
---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 13 | ** a written agreement between you and Nokia.
|
---|
| 14 | **
|
---|
| 15 | ** GNU Lesser General Public License Usage
|
---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 19 | ** packaging of this file. Please review the following information to
|
---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 22 | **
|
---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
| 26 | ** 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 are unsure which license is appropriate for your use, please
|
---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
---|
| 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "project.h"
|
---|
| 43 | #include "property.h"
|
---|
| 44 | #include "option.h"
|
---|
| 45 | #include "cachekeys.h"
|
---|
| 46 | #include "metamakefile.h"
|
---|
| 47 | #include <qnamespace.h>
|
---|
| 48 | #include <qdebug.h>
|
---|
| 49 | #include <qregexp.h>
|
---|
| 50 | #include <qdir.h>
|
---|
| 51 | #include <stdio.h>
|
---|
| 52 | #include <stdlib.h>
|
---|
| 53 | #include <ctype.h>
|
---|
| 54 | #include <fcntl.h>
|
---|
| 55 | #include <sys/types.h>
|
---|
| 56 | #include <sys/stat.h>
|
---|
| 57 |
|
---|
| 58 | QT_BEGIN_NAMESPACE
|
---|
| 59 |
|
---|
| 60 | // for Borland, main is defined to qMain which breaks qmake
|
---|
| 61 | #undef main
|
---|
| 62 | #ifdef Q_OS_MAC
|
---|
| 63 | #endif
|
---|
| 64 |
|
---|
| 65 | /* This is to work around lame implementation on Darwin. It has been noted that the getpwd(3) function
|
---|
| 66 | is much too slow, and called much too often inside of Qt (every fileFixify). With this we use a locally
|
---|
| 67 | cached copy because I can control all the times it is set (because Qt never sets the pwd under me).
|
---|
| 68 | */
|
---|
| 69 | static QString pwd;
|
---|
| 70 | QString qmake_getpwd()
|
---|
| 71 | {
|
---|
| 72 | if(pwd.isNull())
|
---|
| 73 | pwd = QDir::currentPath();
|
---|
| 74 | return pwd;
|
---|
| 75 | }
|
---|
| 76 | bool qmake_setpwd(const QString &p)
|
---|
| 77 | {
|
---|
| 78 | if(QDir::setCurrent(p)) {
|
---|
| 79 | pwd = QDir::currentPath();
|
---|
| 80 | return true;
|
---|
| 81 | }
|
---|
| 82 | return false;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | int runQMake(int argc, char **argv)
|
---|
| 86 | {
|
---|
| 87 | // parse command line
|
---|
| 88 | int ret = Option::init(argc, argv);
|
---|
| 89 | if(ret != Option::QMAKE_CMDLINE_SUCCESS) {
|
---|
| 90 | if ((ret & Option::QMAKE_CMDLINE_ERROR) != 0)
|
---|
| 91 | return 1;
|
---|
| 92 | return 0;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | // report Qt usage for commercial customers with a "metered license" (currently experimental)
|
---|
| 96 | #if QT_EDITION != QT_EDITION_OPENSOURCE
|
---|
| 97 | QString reporterPath = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator()
|
---|
| 98 | + "qtusagereporter";
|
---|
[29] | 99 | #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
|
---|
[2] | 100 | reporterPath += ".exe";
|
---|
| 101 | #endif
|
---|
| 102 | if (QFile::exists(reporterPath))
|
---|
| 103 | system(qPrintable(reporterPath + " qmake"));
|
---|
| 104 | #endif
|
---|
| 105 |
|
---|
| 106 | QString oldpwd = qmake_getpwd();
|
---|
[29] | 107 | #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
|
---|
[2] | 108 | if(!(oldpwd.length() == 3 && oldpwd[0].isLetter() && oldpwd.endsWith(":/")))
|
---|
| 109 | #endif
|
---|
| 110 | {
|
---|
| 111 | if(oldpwd.right(1) != QString(QChar(QDir::separator())))
|
---|
| 112 | oldpwd += QDir::separator();
|
---|
| 113 | }
|
---|
| 114 | Option::output_dir = oldpwd; //for now this is the output dir
|
---|
| 115 |
|
---|
| 116 | if(Option::output.fileName() != "-") {
|
---|
| 117 | QFileInfo fi(Option::output);
|
---|
| 118 | QString dir;
|
---|
| 119 | if(fi.isDir()) {
|
---|
| 120 | dir = fi.filePath();
|
---|
| 121 | } else {
|
---|
| 122 | QString tmp_dir = fi.path();
|
---|
| 123 | if(!tmp_dir.isEmpty() && QFile::exists(tmp_dir))
|
---|
| 124 | dir = tmp_dir;
|
---|
| 125 | }
|
---|
| 126 | if(!dir.isNull() && dir != ".")
|
---|
| 127 | Option::output_dir = dir;
|
---|
| 128 | if(QDir::isRelativePath(Option::output_dir))
|
---|
[363] | 129 | Option::output_dir.prepend(oldpwd);
|
---|
[2] | 130 | Option::output_dir = QDir::cleanPath(Option::output_dir);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | QMakeProperty prop;
|
---|
| 134 | if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY || Option::qmake_mode == Option::QMAKE_SET_PROPERTY)
|
---|
| 135 | return prop.exec() ? 0 : 101;
|
---|
| 136 |
|
---|
| 137 | QMakeProject project(&prop);
|
---|
| 138 | int exit_val = 0;
|
---|
| 139 | QStringList files;
|
---|
| 140 | if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
|
---|
| 141 | files << "(*hack*)"; //we don't even use files, but we do the for() body once
|
---|
| 142 | else
|
---|
| 143 | files = Option::mkfile::project_files;
|
---|
| 144 | for(QStringList::Iterator pfile = files.begin(); pfile != files.end(); pfile++) {
|
---|
| 145 | if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
|
---|
| 146 | Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
|
---|
| 147 | QString fn = Option::fixPathToLocalOS((*pfile));
|
---|
| 148 | if(!QFile::exists(fn)) {
|
---|
| 149 | fprintf(stderr, "Cannot find file: %s.\n", fn.toLatin1().constData());
|
---|
| 150 | exit_val = 2;
|
---|
| 151 | continue;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | //setup pwd properly
|
---|
| 155 | debug_msg(1, "Resetting dir to: %s", oldpwd.toLatin1().constData());
|
---|
| 156 | qmake_setpwd(oldpwd); //reset the old pwd
|
---|
| 157 | int di = fn.lastIndexOf(Option::dir_sep);
|
---|
| 158 | if(di != -1) {
|
---|
| 159 | debug_msg(1, "Changing dir to: %s", fn.left(di).toLatin1().constData());
|
---|
| 160 | if(!qmake_setpwd(fn.left(di)))
|
---|
| 161 | fprintf(stderr, "Cannot find directory: %s\n", fn.left(di).toLatin1().constData());
|
---|
| 162 | fn = fn.right(fn.length() - di - 1);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | // read project..
|
---|
| 166 | if(!project.read(fn)) {
|
---|
| 167 | fprintf(stderr, "Error processing project file: %s\n",
|
---|
| 168 | fn == "-" ? "(stdin)" : (*pfile).toLatin1().constData());
|
---|
| 169 | exit_val = 3;
|
---|
| 170 | continue;
|
---|
| 171 | }
|
---|
| 172 | if(Option::mkfile::do_preprocess) //no need to create makefile
|
---|
| 173 | continue;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | MetaMakefileGenerator *mkfile = MetaMakefileGenerator::createMetaGenerator(&project, QString(), false);
|
---|
| 177 | if(mkfile && !mkfile->write(oldpwd)) {
|
---|
| 178 | if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
|
---|
| 179 | fprintf(stderr, "Unable to generate project file.\n");
|
---|
| 180 | else
|
---|
| 181 | fprintf(stderr, "Unable to generate makefile for: %s\n", (*pfile).toLatin1().constData());
|
---|
| 182 | exit_val = 5;
|
---|
| 183 | }
|
---|
| 184 | delete mkfile;
|
---|
| 185 | mkfile = NULL;
|
---|
| 186 | }
|
---|
| 187 | qmakeClearCaches();
|
---|
| 188 | return exit_val;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | QT_END_NAMESPACE
|
---|
| 192 |
|
---|
| 193 | int main(int argc, char **argv)
|
---|
| 194 | {
|
---|
| 195 | return QT_PREPEND_NAMESPACE(runQMake)(argc, argv);
|
---|
| 196 | }
|
---|