~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to qmake/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the qmake application of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "project.h"
 
30
#include "property.h"
 
31
#include "option.h"
 
32
#include "metamakefile.h"
 
33
#include <qnamespace.h>
 
34
#include <qregexp.h>
 
35
#include <qdir.h>
 
36
#include <stdio.h>
 
37
#include <stdlib.h>
 
38
#include <ctype.h>
 
39
#include <fcntl.h>
 
40
#include <sys/types.h>
 
41
#include <sys/stat.h>
 
42
 
 
43
// for Borland, main is defined to qMain which breaks qmake
 
44
#undef main
 
45
#ifdef Q_OS_MAC
 
46
#endif
 
47
 
 
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).
 
51
*/
 
52
static QString pwd;
 
53
QString qmake_getpwd()
 
54
{
 
55
    if(pwd.isNull())
 
56
        pwd = QDir::currentPath();
 
57
    return pwd;
 
58
}
 
59
bool qmake_setpwd(const QString &p)
 
60
{
 
61
    if(QDir::setCurrent(p)) {
 
62
        pwd = QDir::currentPath();
 
63
        return true;
 
64
    }
 
65
    return false;
 
66
}
 
67
 
 
68
int main(int argc, char **argv)
 
69
{
 
70
    // parse command line
 
71
    int ret = Option::init(argc, argv);
 
72
    if(ret != Option::QMAKE_CMDLINE_SUCCESS) {
 
73
        if ((ret & Option::QMAKE_CMDLINE_ERROR) != 0)
 
74
            return 1;
 
75
        return 0;
 
76
    }
 
77
 
 
78
    QString oldpwd = qmake_getpwd();
 
79
#ifdef Q_WS_WIN
 
80
    if(!(oldpwd.length() == 3 && oldpwd[0].isLetter() && oldpwd.endsWith(":/")))
 
81
#endif
 
82
    {
 
83
        if(oldpwd.right(1) != QString(QChar(QDir::separator())))
 
84
            oldpwd += QDir::separator();
 
85
    }
 
86
    Option::output_dir = oldpwd; //for now this is the output dir
 
87
 
 
88
    if(Option::output.fileName() != "-") {
 
89
        QFileInfo fi(Option::output);
 
90
        QString dir;
 
91
        if(fi.isDir()) {
 
92
            dir = fi.filePath();
 
93
        } else {
 
94
            QString tmp_dir = fi.path();
 
95
            if(!tmp_dir.isEmpty() && QFile::exists(tmp_dir))
 
96
                dir = tmp_dir;
 
97
        }
 
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);
 
103
    }
 
104
 
 
105
    QMakeProperty prop;
 
106
    if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY || Option::qmake_mode == Option::QMAKE_SET_PROPERTY)
 
107
        return prop.exec() ? 0 : 101;
 
108
 
 
109
    QMakeProject proj(&prop);
 
110
    int exit_val = 0;
 
111
    QStringList files;
 
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
 
114
    else
 
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());
 
122
                exit_val = 2;
 
123
                continue;
 
124
            }
 
125
 
 
126
            //setup pwd properly
 
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);
 
130
            if(di != -1) {
 
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);
 
135
            }
 
136
 
 
137
            // read project..
 
138
            if(!proj.read(fn)) {
 
139
                fprintf(stderr, "Error processing project file: %s\n",
 
140
                        fn == "-" ? "(stdin)" : (*pfile).toLatin1().constData());
 
141
                exit_val = 3;
 
142
                continue;
 
143
            }
 
144
            if(Option::mkfile::do_preprocess) //no need to create makefile
 
145
                continue;
 
146
        }
 
147
 
 
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");
 
152
            else
 
153
                fprintf(stderr, "Unable to generate makefile for: %s\n", (*pfile).toLatin1().constData());
 
154
            exit_val = 5;
 
155
        }
 
156
        delete mkfile;
 
157
        mkfile = NULL;
 
158
    }
 
159
    return exit_val;
 
160
}