2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-01-02 11:13:29 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-09-19 12:28:29 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the qmake application of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 09:34:08 +00:00
|
|
|
** GNU General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2012-01-24 06:17:24 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "project.h"
|
|
|
|
#include "property.h"
|
|
|
|
#include "option.h"
|
|
|
|
#include "cachekeys.h"
|
|
|
|
#include "metamakefile.h"
|
|
|
|
#include <qnamespace.h>
|
|
|
|
#include <qdebug.h>
|
|
|
|
#include <qregexp.h>
|
|
|
|
#include <qdir.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
/* This is to work around lame implementation on Darwin. It has been noted that the getpwd(3) function
|
|
|
|
is much too slow, and called much too often inside of Qt (every fileFixify). With this we use a locally
|
|
|
|
cached copy because I can control all the times it is set (because Qt never sets the pwd under me).
|
|
|
|
*/
|
|
|
|
static QString pwd;
|
|
|
|
QString qmake_getpwd()
|
|
|
|
{
|
|
|
|
if(pwd.isNull())
|
|
|
|
pwd = QDir::currentPath();
|
|
|
|
return pwd;
|
|
|
|
}
|
|
|
|
bool qmake_setpwd(const QString &p)
|
|
|
|
{
|
|
|
|
if(QDir::setCurrent(p)) {
|
|
|
|
pwd = QDir::currentPath();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int runQMake(int argc, char **argv)
|
|
|
|
{
|
|
|
|
// stderr is unbuffered by default, but stdout buffering depends on whether
|
|
|
|
// there is a terminal attached. Buffering can make output from stderr and stdout
|
|
|
|
// appear out of sync, so force stdout to be unbuffered as well.
|
|
|
|
// This is particularly important for things like QtCreator and scripted builds.
|
|
|
|
setvbuf(stdout, (char *)NULL, _IONBF, 0);
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QMakeGlobals globals;
|
|
|
|
Option::globals = &globals;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// parse command line
|
|
|
|
int ret = Option::init(argc, argv);
|
|
|
|
if(ret != Option::QMAKE_CMDLINE_SUCCESS) {
|
|
|
|
if ((ret & Option::QMAKE_CMDLINE_ERROR) != 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString oldpwd = qmake_getpwd();
|
2011-10-21 07:35:57 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!(oldpwd.length() == 3 && oldpwd[0].isLetter() && oldpwd.endsWith(":/")))
|
|
|
|
#endif
|
|
|
|
{
|
2011-11-15 08:34:38 +00:00
|
|
|
if(!oldpwd.endsWith(QLatin1Char('/')))
|
|
|
|
oldpwd += QLatin1Char('/');
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
Option::output_dir = oldpwd; //for now this is the output dir
|
|
|
|
|
|
|
|
if(Option::output.fileName() != "-") {
|
|
|
|
QFileInfo fi(Option::output);
|
|
|
|
QString dir;
|
|
|
|
if(fi.isDir()) {
|
|
|
|
dir = fi.filePath();
|
|
|
|
} else {
|
|
|
|
QString tmp_dir = fi.path();
|
|
|
|
if(!tmp_dir.isEmpty() && QFile::exists(tmp_dir))
|
|
|
|
dir = tmp_dir;
|
|
|
|
}
|
|
|
|
if(!dir.isNull() && dir != ".")
|
|
|
|
Option::output_dir = dir;
|
|
|
|
if(QDir::isRelativePath(Option::output_dir))
|
|
|
|
Option::output_dir.prepend(oldpwd);
|
|
|
|
Option::output_dir = QDir::cleanPath(Option::output_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
QMakeProperty prop;
|
|
|
|
if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY ||
|
|
|
|
Option::qmake_mode == Option::QMAKE_SET_PROPERTY ||
|
|
|
|
Option::qmake_mode == Option::QMAKE_UNSET_PROPERTY)
|
|
|
|
return prop.exec() ? 0 : 101;
|
2012-09-05 16:29:19 +00:00
|
|
|
globals.setQMakeProperty(&prop);
|
|
|
|
|
|
|
|
ProFileCache proFileCache;
|
|
|
|
Option::proFileCache = &proFileCache;
|
|
|
|
QMakeParser parser(&proFileCache, &Option::evalHandler);
|
|
|
|
Option::parser = &parser;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QMakeProject project;
|
2011-04-27 10:05:43 +00:00
|
|
|
int exit_val = 0;
|
|
|
|
QStringList files;
|
|
|
|
if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
|
|
|
|
files << "(*hack*)"; //we don't even use files, but we do the for() body once
|
|
|
|
else
|
|
|
|
files = Option::mkfile::project_files;
|
|
|
|
for(QStringList::Iterator pfile = files.begin(); pfile != files.end(); pfile++) {
|
|
|
|
if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
|
|
|
|
Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
|
2011-11-15 08:34:38 +00:00
|
|
|
QString fn = Option::normalizePath(*pfile);
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!QFile::exists(fn)) {
|
2011-11-15 08:34:38 +00:00
|
|
|
fprintf(stderr, "Cannot find file: %s.\n",
|
|
|
|
QDir::toNativeSeparators(fn).toLatin1().constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
exit_val = 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup pwd properly
|
2011-11-15 08:34:38 +00:00
|
|
|
debug_msg(1, "Resetting dir to: %s",
|
|
|
|
QDir::toNativeSeparators(oldpwd).toLatin1().constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
qmake_setpwd(oldpwd); //reset the old pwd
|
2011-11-15 08:34:38 +00:00
|
|
|
int di = fn.lastIndexOf(QLatin1Char('/'));
|
2011-04-27 10:05:43 +00:00
|
|
|
if(di != -1) {
|
2011-11-15 08:34:38 +00:00
|
|
|
debug_msg(1, "Changing dir to: %s",
|
|
|
|
QDir::toNativeSeparators(fn.left(di)).toLatin1().constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!qmake_setpwd(fn.left(di)))
|
2011-11-15 08:34:38 +00:00
|
|
|
fprintf(stderr, "Cannot find directory: %s\n",
|
|
|
|
QDir::toNativeSeparators(fn.left(di)).toLatin1().constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
fn = fn.right(fn.length() - di - 1);
|
|
|
|
}
|
|
|
|
|
2012-05-09 13:29:25 +00:00
|
|
|
Option::prepareProject(fn);
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// read project..
|
|
|
|
if(!project.read(fn)) {
|
|
|
|
fprintf(stderr, "Error processing project file: %s\n",
|
2012-08-28 08:12:36 +00:00
|
|
|
QDir::toNativeSeparators(*pfile).toLatin1().constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
exit_val = 3;
|
|
|
|
continue;
|
|
|
|
}
|
2012-04-23 17:27:43 +00:00
|
|
|
if (Option::mkfile::do_preprocess) {
|
|
|
|
project.dump();
|
|
|
|
continue; //no need to create makefile
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool success = true;
|
|
|
|
MetaMakefileGenerator *mkfile = MetaMakefileGenerator::createMetaGenerator(&project, QString(), false, &success);
|
|
|
|
if (!success)
|
|
|
|
exit_val = 3;
|
|
|
|
|
|
|
|
if(mkfile && !mkfile->write(oldpwd)) {
|
|
|
|
if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
|
|
|
|
fprintf(stderr, "Unable to generate project file.\n");
|
|
|
|
else
|
2011-11-15 08:34:38 +00:00
|
|
|
fprintf(stderr, "Unable to generate makefile for: %s\n",
|
|
|
|
QDir::toNativeSeparators(*pfile).toLatin1().constData());
|
2011-04-27 10:05:43 +00:00
|
|
|
exit_val = 5;
|
|
|
|
}
|
|
|
|
delete mkfile;
|
|
|
|
mkfile = NULL;
|
|
|
|
}
|
|
|
|
qmakeClearCaches();
|
|
|
|
return exit_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
return QT_PREPEND_NAMESPACE(runQMake)(argc, argv);
|
|
|
|
}
|