1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the qmake application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
32
#include "metamakefile.h"
33
#include <qnamespace.h>
40
#include <sys/types.h>
43
// for Borland, main is defined to qMain which breaks qmake
48
/* This is to work around lame implementation on Darwin. It has been noted that the getpwd(3) function
49
is much too slow, and called much too often inside of Qt (every fileFixify). With this we use a locally
50
cached copy because I can control all the times it is set (because Qt never sets the pwd under me).
53
QString qmake_getpwd()
56
pwd = QDir::currentPath();
59
bool qmake_setpwd(const QString &p)
61
if(QDir::setCurrent(p)) {
62
pwd = QDir::currentPath();
68
int main(int argc, char **argv)
71
int ret = Option::init(argc, argv);
72
if(ret != Option::QMAKE_CMDLINE_SUCCESS) {
73
if ((ret & Option::QMAKE_CMDLINE_ERROR) != 0)
78
QString oldpwd = qmake_getpwd();
80
if(!(oldpwd.length() == 3 && oldpwd[0].isLetter() && oldpwd.endsWith(":/")))
83
if(oldpwd.right(1) != QString(QChar(QDir::separator())))
84
oldpwd += QDir::separator();
86
Option::output_dir = oldpwd; //for now this is the output dir
88
if(Option::output.fileName() != "-") {
89
QFileInfo fi(Option::output);
94
QString tmp_dir = fi.path();
95
if(!tmp_dir.isEmpty() && QFile::exists(tmp_dir))
98
if(!dir.isNull() && dir != ".")
99
Option::output_dir = dir;
100
if(QDir::isRelativePath(Option::output_dir))
101
Option::output_dir.prepend(oldpwd);
102
Option::output_dir = QDir::cleanPath(Option::output_dir);
106
if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY || Option::qmake_mode == Option::QMAKE_SET_PROPERTY)
107
return prop.exec() ? 0 : 101;
109
QMakeProject proj(&prop);
112
if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
113
files << "(*hack*)"; //we don't even use files, but we do the for() body once
115
files = Option::mkfile::project_files;
116
for(QStringList::Iterator pfile = files.begin(); pfile != files.end(); pfile++) {
117
if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
118
Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
119
QString fn = Option::fixPathToLocalOS((*pfile));
120
if(!QFile::exists(fn)) {
121
fprintf(stderr, "Cannot find file: %s.\n", fn.toLatin1().constData());
127
debug_msg(1, "Resetting dir to: %s", oldpwd.toLatin1().constData());
128
qmake_setpwd(oldpwd); //reset the old pwd
129
int di = fn.lastIndexOf(Option::dir_sep);
131
debug_msg(1, "Changing dir to: %s", fn.left(di).toLatin1().constData());
132
if(!qmake_setpwd(fn.left(di)))
133
fprintf(stderr, "Cannot find directory: %s\n", fn.left(di).toLatin1().constData());
134
fn = fn.right(fn.length() - di - 1);
139
fprintf(stderr, "Error processing project file: %s\n",
140
fn == "-" ? "(stdin)" : (*pfile).toLatin1().constData());
144
if(Option::mkfile::do_preprocess) //no need to create makefile
148
MetaMakefileGenerator *mkfile = MetaMakefileGenerator::createMetaGenerator(&proj);
149
if(mkfile && !mkfile->write(oldpwd)) {
150
if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
151
fprintf(stderr, "Unable to generate project file.\n");
153
fprintf(stderr, "Unable to generate makefile for: %s\n", (*pfile).toLatin1().constData());