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