source: trunk/qmake/main.cpp@ 68

Last change on this file since 68 was 8, checked in by dmik, 20 years ago

Transferred Qt for OS/2 version 3.3.1-rc5 sources from the CVS

  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1/****************************************************************************
2** $Id: main.cpp 8 2005-11-16 19:36:46Z dmik $
3**
4** ???
5**
6** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
7**
8** This file is part of qmake.
9**
10** This file may be distributed under the terms of the Q Public License
11** as defined by Trolltech AS of Norway and appearing in the file
12** LICENSE.QPL included in the packaging of this file.
13**
14** This file may be distributed and/or modified under the terms of the
15** GNU General Public License version 2 as published by the Free Software
16** Foundation and appearing in the file LICENSE.GPL included in the
17** packaging of this file.
18**
19** Licensees holding valid Qt Enterprise Edition licenses may use this
20** file in accordance with the Qt Commercial License Agreement provided
21** with the Software.
22**
23** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25**
26** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
27** information about Qt Commercial License Agreements.
28** See http://www.trolltech.com/qpl/ for QPL licensing information.
29** See http://www.trolltech.com/gpl/ for GPL licensing information.
30**
31** Contact info@trolltech.com if any conditions of this licensing are
32** not clear to you.
33**
34**********************************************************************/
35
36#include "project.h"
37#include "property.h"
38#include "option.h"
39#include "makefile.h"
40#include <qnamespace.h>
41#include <qregexp.h>
42#include <qdir.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <ctype.h>
46#include <fcntl.h>
47#include <sys/types.h>
48#include <sys/stat.h>
49
50// for Borland, main is defined to qMain which breaks qmake
51#undef main
52#ifdef Q_OS_MAC
53// for qurl
54bool qt_resolve_symlinks = FALSE;
55#endif
56
57int main(int argc, char **argv)
58{
59 /* parse command line */
60 if(!Option::parseCommandLine(argc, argv))
61 return 666;
62
63 QDir sunworkshop42workaround = QDir::current();
64 QString oldpwd = sunworkshop42workaround.currentDirPath();
65#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
66 if(!(oldpwd.length() == 3 && oldpwd[0].isLetter() && oldpwd.endsWith(":/") ) )
67#endif
68 {
69 if(oldpwd.right(1) != QString(QChar(QDir::separator())))
70 oldpwd += QDir::separator();
71 }
72 Option::output_dir = oldpwd; //for now this is the output dir
73
74 if(Option::output.name() != "-") {
75 QFileInfo fi(Option::output);
76 QString dir;
77 if(fi.isDir()) {
78 dir = fi.filePath();
79 } else {
80 QString tmp_dir = fi.dirPath();
81 if(!tmp_dir.isEmpty() && QFile::exists(tmp_dir))
82 dir = tmp_dir;
83 }
84 if(!dir.isNull() && dir != ".")
85 Option::output_dir = dir;
86 if(QDir::isRelativePath(Option::output_dir))
87 Option::output_dir.prepend(oldpwd);
88 }
89
90 QMakeProperty prop;
91 if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY || Option::qmake_mode == Option::QMAKE_SET_PROPERTY)
92 return prop.exec() ? 0 : 101;
93
94 QMakeProject proj(&prop);
95 int exit_val = 0;
96 QStringList files;
97 if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
98 files << "(*hack*)"; //we don't even use files, but we do the for() body once
99 else
100 files = Option::mkfile::project_files;
101 for(QStringList::Iterator pfile = files.begin(); pfile != files.end(); pfile++) {
102 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
103 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
104 QString fn = Option::fixPathToLocalOS((*pfile));
105
106 //setup pwd properly
107 debug_msg(1, "Resetting dir to: %s", oldpwd.latin1());
108 QDir::setCurrent(oldpwd); //reset the old pwd
109 int di = fn.findRev(Option::dir_sep);
110 if(di != -1) {
111 debug_msg(1, "Changing dir to: %s", fn.left(di).latin1());
112 if(!QDir::setCurrent(fn.left(di)))
113 fprintf(stderr, "Cannot find directory: %s\n", fn.left(di).latin1());
114 fn = fn.right(fn.length() - di - 1);
115 }
116
117 /* read project.. */
118 if(!proj.read(fn, oldpwd)) {
119 fprintf(stderr, "Error processing project file: %s\n",
120 fn == "-" ? "(stdin)" : (*pfile).latin1());
121 exit_val = 2;
122 continue;
123 }
124 if(Option::mkfile::do_preprocess) //no need to create makefile
125 continue;
126
127 /* let Option post-process */
128 if(!Option::postProcessProject(&proj)) {
129 fprintf(stderr, "Error post-processing project file: %s",
130 fn == "-" ? "(stdin)" : (*pfile).latin1());
131 exit_val = 8;
132 continue;
133 }
134 }
135
136 bool using_stdout = FALSE;
137 MakefileGenerator *mkfile = MakefileGenerator::create(&proj); //figure out generator
138 if(mkfile && (Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
139 Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)) {
140 //open output
141 if(!(Option::output.state() & IO_Open)) {
142 if(Option::output.name() == "-") {
143 Option::output.setName("");
144 Option::output_dir = QDir::currentDirPath();
145 Option::output.open(IO_WriteOnly | IO_Translate, stdout);
146 using_stdout = TRUE;
147 } else {
148 if(Option::output.name().isEmpty() && Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE)
149 Option::output.setName(proj.first("QMAKE_MAKEFILE"));
150 Option::output_dir = oldpwd;
151 if(!mkfile->openOutput(Option::output)) {
152 fprintf(stderr, "Failure to open file: %s\n",
153 Option::output.name().isEmpty() ? "(stdout)" : Option::output.name().latin1());
154 return 5;
155 }
156 }
157 }
158 } else {
159 using_stdout = TRUE; //kind of..
160 }
161 if(mkfile && !mkfile->write()) {
162 if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
163 fprintf(stderr, "Unable to generate project file.\n");
164 else
165 fprintf(stderr, "Unable to generate makefile for: %s\n", (*pfile).latin1());
166 if(!using_stdout)
167 QFile::remove(Option::output.name());
168 exit_val = 6;
169 }
170 delete mkfile;
171 mkfile = NULL;
172
173 /* debugging */
174 if(Option::debug_level) {
175 QMap<QString, QStringList> &vars = proj.variables();
176 for(QMap<QString, QStringList>::Iterator it = vars.begin(); it != vars.end(); ++it) {
177 if(!it.key().startsWith(".") && !it.data().isEmpty())
178 debug_msg(1, "%s === %s", it.key().latin1(), it.data().join(" :: ").latin1());
179 }
180 }
181 }
182 return exit_val;
183}
Note: See TracBrowser for help on using the repository browser.