summaryrefslogtreecommitdiff
path: root/qmake/option.cpp
authorzecke <zecke>2004-07-15 17:36:57 (UTC)
committer zecke <zecke>2004-07-15 17:36:57 (UTC)
commit323e9a7472a110b4befba7320540263147505bae (patch) (unidiff)
tree14c810bdb9c0603a30356b17b4bdf9ccb72741c6 /qmake/option.cpp
parentaa292b322f1ecb43dd8f4e3cd295855730dd9f59 (diff)
downloadopie-323e9a7472a110b4befba7320540263147505bae.zip
opie-323e9a7472a110b4befba7320540263147505bae.tar.gz
opie-323e9a7472a110b4befba7320540263147505bae.tar.bz2
Manually updatet to qmake1.06a which includes support for precompiled
headers. Opies 'PRO' keyword was already reintroduced
Diffstat (limited to 'qmake/option.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/option.cpp101
1 files changed, 71 insertions, 30 deletions
diff --git a/qmake/option.cpp b/qmake/option.cpp
index 8b7e5e8..e6928fa 100644
--- a/qmake/option.cpp
+++ b/qmake/option.cpp
@@ -1,504 +1,545 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2**
3** 3**
4** Definition of ________ class. 4** Implementation of Option class.
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 "option.h" 36#include "option.h"
39#include <qdir.h> 37#include <qdir.h>
40#include <qregexp.h> 38#include <qregexp.h>
41#include <stdlib.h> 39#include <stdlib.h>
42#include <stdarg.h> 40#include <stdarg.h>
43 41
44//convenience 42//convenience
45QString Option::prf_ext; 43QString Option::prf_ext;
46QString Option::prl_ext; 44QString Option::prl_ext;
45QString Option::libtool_ext;
46QString Option::pkgcfg_ext;
47QString Option::ui_ext; 47QString Option::ui_ext;
48QStringList Option::h_ext; 48QStringList Option::h_ext;
49QString Option::moc_ext; 49QString Option::cpp_moc_ext;
50QString Option::h_moc_ext;
50QStringList Option::cpp_ext; 51QStringList Option::cpp_ext;
51QString Option::obj_ext; 52QString Option::obj_ext;
52QString Option::lex_ext; 53QString Option::lex_ext;
53QString Option::yacc_ext; 54QString Option::yacc_ext;
54QString Option::dir_sep; 55QString Option::dir_sep;
55QString Option::moc_mod; 56QString Option::h_moc_mod;
57QString Option::cpp_moc_mod;
56QString Option::yacc_mod; 58QString Option::yacc_mod;
57QString Option::lex_mod; 59QString Option::lex_mod;
58 60
59//mode 61//mode
60Option::QMAKE_MODE Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING; 62Option::QMAKE_MODE Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING;
61 63
62//all modes 64//all modes
63int Option::warn_level = WarnLogic; 65int Option::warn_level = WarnLogic;
64int Option::debug_level = 0; 66int Option::debug_level = 0;
65QFile Option::output; 67QFile Option::output;
66QString Option::output_dir; 68QString Option::output_dir;
67QStringList Option::before_user_vars; 69QStringList Option::before_user_vars;
68QStringList Option::after_user_vars; 70QStringList Option::after_user_vars;
69QString Option::user_template; 71QString Option::user_template;
70QString Option::user_template_prefix; 72QString Option::user_template_prefix;
71#if defined(Q_OS_WIN32) 73#if defined(Q_OS_WIN32)
72Option::TARG_MODE Option::target_mode = Option::TARG_WIN_MODE; 74Option::TARG_MODE Option::target_mode = Option::TARG_WIN_MODE;
73#elif defined(Q_OS_MAC9) 75#elif defined(Q_OS_MAC9)
74Option::TARG_MODE Option::target_mode = Option::TARG_MAC9_MODE; 76Option::TARG_MODE Option::target_mode = Option::TARG_MAC9_MODE;
75#elif defined(Q_OS_MACX) 77#elif defined(Q_OS_MACX)
76Option::TARG_MODE Option::target_mode = Option::TARG_MACX_MODE; 78Option::TARG_MODE Option::target_mode = Option::TARG_MACX_MODE;
77#elif defined(Q_OS_QNX6) 79#elif defined(Q_OS_QNX6)
78Option::TARG_MODE Option::target_mode = Option::TARG_QNX6_MODE; 80Option::TARG_MODE Option::target_mode = Option::TARG_QNX6_MODE;
79#else 81#else
80Option::TARG_MODE Option::target_mode = Option::TARG_UNIX_MODE; 82Option::TARG_MODE Option::target_mode = Option::TARG_UNIX_MODE;
81#endif 83#endif
82 84
85//QMAKE_*_PROPERTY stuff
86QStringList Option::prop::properties;
87
83//QMAKE_GENERATE_PROJECT stuff 88//QMAKE_GENERATE_PROJECT stuff
84bool Option::projfile::do_pwd = TRUE; 89bool Option::projfile::do_pwd = TRUE;
85bool Option::projfile::do_recursive = TRUE; 90bool Option::projfile::do_recursive = TRUE;
86QStringList Option::projfile::project_dirs; 91QStringList Option::projfile::project_dirs;
87 92
88//QMAKE_GENERATE_MAKEFILE stuff 93//QMAKE_GENERATE_MAKEFILE stuff
89QString Option::mkfile::qmakespec; 94QString Option::mkfile::qmakespec;
90int Option::mkfile::cachefile_depth = -1; 95int Option::mkfile::cachefile_depth = -1;
91bool Option::mkfile::do_deps = TRUE; 96bool Option::mkfile::do_deps = TRUE;
92bool Option::mkfile::do_mocs = TRUE; 97bool Option::mkfile::do_mocs = TRUE;
93bool Option::mkfile::do_dep_heuristics = TRUE; 98bool Option::mkfile::do_dep_heuristics = TRUE;
94bool Option::mkfile::do_preprocess = FALSE; 99bool Option::mkfile::do_preprocess = FALSE;
95bool Option::mkfile::do_cache = TRUE; 100bool Option::mkfile::do_cache = TRUE;
96QString Option::mkfile::cachefile; 101QString Option::mkfile::cachefile;
97QStringList Option::mkfile::project_files; 102QStringList Option::mkfile::project_files;
98QString Option::mkfile::qmakespec_commandline; 103QString Option::mkfile::qmakespec_commandline;
99 104
100static Option::QMAKE_MODE default_mode(QString progname) 105static Option::QMAKE_MODE default_mode(QString progname)
101{ 106{
102 int s = progname.findRev(Option::dir_sep); 107 int s = progname.findRev(Option::dir_sep);
103 if(s != -1) 108 if(s != -1)
104 progname = progname.right(progname.length() - (s + 1)); 109 progname = progname.right(progname.length() - (s + 1));
105 if(progname == "qmakegen") 110 if(progname == "qmakegen")
106 return Option::QMAKE_GENERATE_PROJECT; 111 return Option::QMAKE_GENERATE_PROJECT;
112 else if(progname == "qt-config")
113 return Option::QMAKE_QUERY_PROPERTY;
107 return Option::QMAKE_GENERATE_MAKEFILE; 114 return Option::QMAKE_GENERATE_MAKEFILE;
108} 115}
109 116
110QString project_builtin_regx(); 117QString project_builtin_regx();
111bool usage(const char *a0) 118bool usage(const char *a0)
112{ 119{
113 fprintf(stdout, "Usage: %s [mode] [options] [files]\n" 120 fprintf(stdout, "Usage: %s [mode] [options] [files]\n"
114 "\n" 121 "\n"
115 " QMake has two modes, one mode for generating project files based on\n" 122 " QMake has two modes, one mode for generating project files based on\n"
116 "some heuristics, and the other for generating makefiles. Normally you\n" 123 "some heuristics, and the other for generating makefiles. Normally you\n"
117 "shouldn't need to specify a mode, as makefile generation is the default\n" 124 "shouldn't need to specify a mode, as makefile generation is the default\n"
118 "mode for qmake, but you may use this to test qmake on an existing project\n" 125 "mode for qmake, but you may use this to test qmake on an existing project\n"
119 "\n" 126 "\n"
120 "Mode:\n" 127 "Mode:\n"
121 "\t-project Put qmake into project file generation mode%s\n" 128 "\t-project Put qmake into project file generation mode%s\n"
122 "\t In this mode qmake interprets files as files to\n" 129 "\t In this mode qmake interprets files as files to\n"
123 "\t be built,\n" 130 "\t be built,\n"
124 "\t defaults to %s\n" 131 "\t defaults to %s\n"
125 "\t-makefile Put qmake into makefile generation mode%s\n" 132 "\t-makefile Put qmake into makefile generation mode%s\n"
126 "\t In this mode qmake interprets files as project files to\n" 133 "\t In this mode qmake interprets files as project files to\n"
127 "\t be processed, if skipped qmake will try to find a project\n" 134 "\t be processed, if skipped qmake will try to find a project\n"
128 "\t file in your current working directory\n" 135 "\t file in your current working directory\n"
129 "\n" 136 "\n"
130 "Warnings Options:\n" 137 "Warnings Options:\n"
131 "\t-Wnone Turn off all warnings\n" 138 "\t-Wnone Turn off all warnings\n"
132 "\t-Wall Turn on all warnings\n" 139 "\t-Wall Turn on all warnings\n"
133 "\t-Wparser Turn on parser warnings\n" 140 "\t-Wparser Turn on parser warnings\n"
134 "\t-Wlogic Turn on logic warnings\n" 141 "\t-Wlogic Turn on logic warnings\n"
135 "\n" 142 "\n"
136 "Options:\n" 143 "Options:\n"
137 "\t * You can place any variable assignment in options and it will be *\n" 144 "\t * You can place any variable assignment in options and it will be *\n"
138 "\t * processed as if it was in [files]. These assignments will be parsed *\n" 145 "\t * processed as if it was in [files]. These assignments will be parsed *\n"
139 "\t * before [files]. *\n" 146 "\t * before [files]. *\n"
140 "\t-o file Write output to file\n" 147 "\t-o file Write output to file\n"
141 "\t-unix Run in unix mode\n" 148 "\t-unix Run in unix mode\n"
142 "\t-win32 Run in win32 mode\n" 149 "\t-win32 Run in win32 mode\n"
143 "\t-macx Run in Mac OS X mode\n" 150 "\t-macx Run in Mac OS X mode\n"
144 "\t-d Increase debug level\n" 151 "\t-d Increase debug level\n"
145 "\t-t templ Overrides TEMPLATE as templ\n" 152 "\t-t templ Overrides TEMPLATE as templ\n"
146 "\t-tp prefix Overrides TEMPLATE so that prefix is prefixed into the value\n" 153 "\t-tp prefix Overrides TEMPLATE so that prefix is prefixed into the value\n"
147 "\t-help This help\n" 154 "\t-help This help\n"
148 "\t-v Version information\n" 155 "\t-v Version information\n"
149 "\t-after All variable assignments after this will be\n" 156 "\t-after All variable assignments after this will be\n"
150 "\t parsed after [files]\n" 157 "\t parsed after [files]\n"
151 "\t-cache file Use file as cache [makefile mode only]\n" 158 "\t-cache file Use file as cache [makefile mode only]\n"
152 "\t-spec spec Use spec as QMAKESPEC [makefile mode only]\n" 159 "\t-spec spec Use spec as QMAKESPEC [makefile mode only]\n"
153 "\t-nocache Don't use a cache file [makefile mode only]\n" 160 "\t-nocache Don't use a cache file [makefile mode only]\n"
154 "\t-nodepend Don't generate dependencies [makefile mode only]\n" 161 "\t-nodepend Don't generate dependencies [makefile mode only]\n"
155 "\t-nomoc Don't generate moc targets [makefile mode only]\n" 162 "\t-nomoc Don't generate moc targets [makefile mode only]\n"
156 "\t-nopwd Don't look for files in pwd [ project mode only]\n" 163 "\t-nopwd Don't look for files in pwd [ project mode only]\n"
157 "\t-norecursive Don't do a recursive search [ project mode only]\n" 164 "\t-norecursive Don't do a recursive search [ project mode only]\n"
158 ,a0, 165 ,a0,
159 default_mode(a0) == Option::QMAKE_GENERATE_PROJECT ? " (default)" : "", project_builtin_regx().latin1(), 166 default_mode(a0) == Option::QMAKE_GENERATE_PROJECT ? " (default)" : "", project_builtin_regx().latin1(),
160 default_mode(a0) == Option::QMAKE_GENERATE_MAKEFILE ? " (default)" : ""); 167 default_mode(a0) == Option::QMAKE_GENERATE_MAKEFILE ? " (default)" : "");
161 return FALSE; 168 return FALSE;
162} 169}
163 170
164bool 171enum {
172 QMAKE_CMDLINE_SUCCESS,
173 QMAKE_CMDLINE_SHOW_USAGE,
174 QMAKE_CMDLINE_BAIL
175};
176int
165Option::internalParseCommandLine(int argc, char **argv, int skip) 177Option::internalParseCommandLine(int argc, char **argv, int skip)
166{ 178{
167 bool before = TRUE; 179 bool before = TRUE;
168 for(int x = skip; x < argc; x++) { 180 for(int x = skip; x < argc; x++) {
169 if(*argv[x] == '-' && strlen(argv[x]) > 1) { /* options */ 181 if(*argv[x] == '-' && strlen(argv[x]) > 1) { /* options */
170 QString opt = argv[x] + 1; 182 QString opt = argv[x] + 1;
171 183
172 //first param is a mode, or we default 184 //first param is a mode, or we default
173 if(x == 1) { 185 if(x == 1) {
174 bool specified = TRUE; 186 bool specified = TRUE;
175 if(opt == "project") { 187 if(opt == "project") {
176 Option::qmake_mode = Option::QMAKE_GENERATE_PROJECT; 188 Option::qmake_mode = Option::QMAKE_GENERATE_PROJECT;
177 } else if(opt == "prl") { 189 } else if(opt == "prl") {
178 Option::mkfile::do_deps = FALSE; 190 Option::mkfile::do_deps = FALSE;
179 Option::mkfile::do_mocs = FALSE; 191 Option::mkfile::do_mocs = FALSE;
180 Option::qmake_mode = Option::QMAKE_GENERATE_PRL; 192 Option::qmake_mode = Option::QMAKE_GENERATE_PRL;
193 } else if(opt == "set") {
194 Option::qmake_mode = Option::QMAKE_SET_PROPERTY;
195 } else if(opt == "query") {
196 Option::qmake_mode = Option::QMAKE_QUERY_PROPERTY;
181 } else if(opt == "makefile") { 197 } else if(opt == "makefile") {
182 Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE; 198 Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE;
183 } else { 199 } else {
184 specified = FALSE; 200 specified = FALSE;
185 } 201 }
186 if(specified) 202 if(specified)
187 continue; 203 continue;
188 } 204 }
189 //all modes 205 //all modes
190 if(opt == "o" || opt == "output") { 206 if(opt == "o" || opt == "output") {
191 Option::output.setName(argv[++x]); 207 Option::output.setName(argv[++x]);
192 } else if(opt == "after") { 208 } else if(opt == "after") {
193 before = FALSE; 209 before = FALSE;
194 } else if(opt == "t" || opt == "template") { 210 } else if(opt == "t" || opt == "template") {
195 Option::user_template = argv[++x]; 211 Option::user_template = argv[++x];
196 } else if(opt == "tp" || opt == "template_prefix") { 212 } else if(opt == "tp" || opt == "template_prefix") {
197 Option::user_template_prefix = argv[++x]; 213 Option::user_template_prefix = argv[++x];
198 } else if(opt == "mac9") { 214 } else if(opt == "mac9") {
199 Option::target_mode = TARG_MAC9_MODE; 215 Option::target_mode = TARG_MAC9_MODE;
200 } else if(opt == "macx") { 216 } else if(opt == "macx") {
201 Option::target_mode = TARG_MACX_MODE; 217 Option::target_mode = TARG_MACX_MODE;
202 } else if(opt == "unix") { 218 } else if(opt == "unix") {
203 Option::target_mode = TARG_UNIX_MODE; 219 Option::target_mode = TARG_UNIX_MODE;
204 } else if(opt == "win32") { 220 } else if(opt == "win32") {
205 Option::target_mode = TARG_WIN_MODE; 221 Option::target_mode = TARG_WIN_MODE;
206 } else if(opt == "d") { 222 } else if(opt == "d") {
207 Option::debug_level++; 223 Option::debug_level++;
208 } else if(opt == "version" || opt == "v" || opt == "-version") { 224 } else if(opt == "version" || opt == "v" || opt == "-version") {
209 fprintf(stderr, "Qmake version: %s (Qt %s)\n", qmake_version(), QT_VERSION_STR); 225 fprintf(stderr, "Qmake version: %s (Qt %s)\n", qmake_version(), QT_VERSION_STR);
210 fprintf(stderr, "Qmake is free software from Trolltech AS.\n"); 226 fprintf(stderr, "Qmake is free software from Trolltech AS.\n");
211 return FALSE; 227 return QMAKE_CMDLINE_BAIL;
212 } else if(opt == "h" || opt == "help") { 228 } else if(opt == "h" || opt == "help") {
213 return FALSE; 229 return QMAKE_CMDLINE_SHOW_USAGE;
214 } else if(opt == "Wall") { 230 } else if(opt == "Wall") {
215 Option::warn_level |= WarnAll; 231 Option::warn_level |= WarnAll;
216 } else if(opt == "Wparser") { 232 } else if(opt == "Wparser") {
217 Option::warn_level |= WarnParser; 233 Option::warn_level |= WarnParser;
218 } else if(opt == "Wlogic") { 234 } else if(opt == "Wlogic") {
219 Option::warn_level |= WarnLogic; 235 Option::warn_level |= WarnLogic;
220 } else if(opt == "Wnone") { 236 } else if(opt == "Wnone") {
221 Option::warn_level = WarnNone; 237 Option::warn_level = WarnNone;
222 } else { 238 } else {
223 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || 239 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
224 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) { 240 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
225 if(opt == "nodepend") { 241 if(opt == "nodepend") {
226 Option::mkfile::do_deps = FALSE; 242 Option::mkfile::do_deps = FALSE;
227 } else if(opt == "nomoc") { 243 } else if(opt == "nomoc") {
228 Option::mkfile::do_mocs = FALSE; 244 Option::mkfile::do_mocs = FALSE;
229 } else if(opt == "nocache") { 245 } else if(opt == "nocache") {
230 Option::mkfile::do_cache = FALSE; 246 Option::mkfile::do_cache = FALSE;
231 } else if(opt == "nodependheuristics") { 247 } else if(opt == "nodependheuristics") {
232 Option::mkfile::do_dep_heuristics = FALSE; 248 Option::mkfile::do_dep_heuristics = FALSE;
233 } else if(opt == "E") { 249 } else if(opt == "E") {
234 Option::mkfile::do_preprocess = TRUE; 250 Option::mkfile::do_preprocess = TRUE;
235 } else if(opt == "cache") { 251 } else if(opt == "cache") {
236 Option::mkfile::cachefile = argv[++x]; 252 Option::mkfile::cachefile = argv[++x];
237 } else if(opt == "platform" || opt == "spec") { 253 } else if(opt == "platform" || opt == "spec") {
238 Option::mkfile::qmakespec = argv[++x]; 254 Option::mkfile::qmakespec = argv[++x];
239 Option::mkfile::qmakespec_commandline = argv[x]; 255 Option::mkfile::qmakespec_commandline = argv[x];
240 } else { 256 } else {
241 fprintf(stderr, "***Unknown option -%s\n", opt.latin1()); 257 fprintf(stderr, "***Unknown option -%s\n", opt.latin1());
242 return usage(argv[0]); 258 return QMAKE_CMDLINE_SHOW_USAGE;
243 } 259 }
244 } else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) { 260 } else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) {
245 if(opt == "nopwd") { 261 if(opt == "nopwd") {
246 Option::projfile::do_pwd = FALSE; 262 Option::projfile::do_pwd = FALSE;
247 } else if(opt == "r") { 263 } else if(opt == "r") {
248 Option::projfile::do_recursive = TRUE; 264 Option::projfile::do_recursive = TRUE;
249 } else if(opt == "norecursive") { 265 } else if(opt == "norecursive") {
250 Option::projfile::do_recursive = FALSE; 266 Option::projfile::do_recursive = FALSE;
251 } else { 267 } else {
252 fprintf(stderr, "***Unknown option -%s\n", opt.latin1()); 268 fprintf(stderr, "***Unknown option -%s\n", opt.latin1());
253 return FALSE; 269 return QMAKE_CMDLINE_SHOW_USAGE;
254 } 270 }
255 } 271 }
256 } 272 }
257 } else { 273 } else {
258 QString arg = argv[x]; 274 QString arg = argv[x];
259 if(arg.find('=') != -1) { 275 if(arg.find('=') != -1) {
260 if(before) 276 if(before)
261 Option::before_user_vars.append(arg); 277 Option::before_user_vars.append(arg);
262 else 278 else
263 Option::after_user_vars.append(arg); 279 Option::after_user_vars.append(arg);
264 } else { 280 } else {
265 QFileInfo fi(arg); 281 bool handled = TRUE;
266 if(!fi.convertToAbs()) //strange 282 if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY ||
267 arg = fi.filePath(); 283 Option::qmake_mode == Option::QMAKE_SET_PROPERTY) {
268 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || 284 Option::prop::properties.append(arg);
269 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) 285 } else {
270 Option::mkfile::project_files.append(arg); 286 QFileInfo fi(arg);
271 else 287 if(!fi.convertToAbs()) //strange
272 Option::projfile::project_dirs.append(arg); 288 arg = fi.filePath();
289 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
290 Option::qmake_mode == Option::QMAKE_GENERATE_PRL)
291 Option::mkfile::project_files.append(arg);
292 else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
293 Option::projfile::project_dirs.append(arg);
294 else
295 handled = FALSE;
296 }
297 if(!handled)
298 return QMAKE_CMDLINE_SHOW_USAGE;
273 } 299 }
274 } 300 }
275 } 301 }
276 return TRUE; 302 return QMAKE_CMDLINE_SUCCESS;
277} 303}
278 304
279 305
280bool 306bool
281Option::parseCommandLine(int argc, char **argv) 307Option::parseCommandLine(int argc, char **argv)
282{ 308{
283 Option::moc_mod = "moc_"; 309 Option::cpp_moc_mod = "";
310 Option::h_moc_mod = "moc_";
284 Option::lex_mod = "_lex"; 311 Option::lex_mod = "_lex";
285 Option::yacc_mod = "_yacc"; 312 Option::yacc_mod = "_yacc";
286 Option::prl_ext = ".prl"; 313 Option::prl_ext = ".prl";
314 Option::libtool_ext = ".la";
315 Option::pkgcfg_ext = ".pc";
287 Option::prf_ext = ".prf"; 316 Option::prf_ext = ".prf";
288 Option::ui_ext = ".ui"; 317 Option::ui_ext = ".ui";
289 Option::h_ext << ".h" << ".hpp" << ".hh" << ".H" << ".hxx"; 318 Option::h_ext << ".h" << ".hpp" << ".hh" << ".H" << ".hxx";
290 Option::moc_ext = ".moc"; 319 Option::cpp_moc_ext = ".moc";
320 Option::h_moc_ext = ".cpp";
291 Option::cpp_ext << ".cpp" << ".cc" << ".cxx" << ".C"; 321 Option::cpp_ext << ".cpp" << ".cc" << ".cxx" << ".C";
292 Option::lex_ext = ".l"; 322 Option::lex_ext = ".l";
293 Option::yacc_ext = ".y"; 323 Option::yacc_ext = ".y";
294 324
295 if(Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING) 325 if(Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING)
296 Option::qmake_mode = default_mode(argv[0]); 326 Option::qmake_mode = default_mode(argv[0]);
297 if(const char *envflags = getenv("QMAKEFLAGS")) { 327 if(const char *envflags = getenv("QMAKEFLAGS")) {
298 int env_argc = 0, env_size = 0, currlen=0; 328 int env_argc = 0, env_size = 0, currlen=0;
299 char quote = 0, **env_argv = NULL; 329 char quote = 0, **env_argv = NULL;
300 for(int i = 0; envflags[i]; i++) { 330 for(int i = 0; envflags[i]; i++) {
301 if(!quote && (envflags[i] == '\'' || envflags[i] == '"')) { 331 if(!quote && (envflags[i] == '\'' || envflags[i] == '"')) {
302 quote = envflags[i]; 332 quote = envflags[i];
303 } else if(envflags[i] == quote) { 333 } else if(envflags[i] == quote) {
304 quote = 0; 334 quote = 0;
305 } else if(!quote && envflags[i] == ' ') { 335 } else if(!quote && envflags[i] == ' ') {
306 if(currlen && env_argv && env_argv[env_argc]) { 336 if(currlen && env_argv && env_argv[env_argc]) {
307 env_argv[env_argc][currlen] = '\0'; 337 env_argv[env_argc][currlen] = '\0';
308 currlen = 0; 338 currlen = 0;
309 env_argc++; 339 env_argc++;
310 } 340 }
311 } else { 341 } else {
312 if(!env_argv || env_argc > env_size) { 342 if(!env_argv || env_argc > env_size) {
313 env_argv = (char **)realloc(env_argv, sizeof(char *)*(env_size+=10)); 343 env_argv = (char **)realloc(env_argv, sizeof(char *)*(env_size+=10));
314 for(int i2 = env_argc; i2 < env_size; i2++) 344 for(int i2 = env_argc; i2 < env_size; i2++)
315 env_argv[i2] = NULL; 345 env_argv[i2] = NULL;
316 } 346 }
317 if(!env_argv[env_argc]) { 347 if(!env_argv[env_argc]) {
318 currlen = 0; 348 currlen = 0;
319 env_argv[env_argc] = (char*)malloc(255); 349 env_argv[env_argc] = (char*)malloc(255);
320 } 350 }
321 if(currlen < 255) 351 if(currlen < 255)
322 env_argv[env_argc][currlen++] = envflags[i]; 352 env_argv[env_argc][currlen++] = envflags[i];
323 } 353 }
324 } 354 }
325 if(env_argv[env_argc]) { 355 if(env_argv[env_argc]) {
326 env_argv[env_argc][currlen] = '\0'; 356 env_argv[env_argc][currlen] = '\0';
327 currlen = 0; 357 currlen = 0;
328 env_argc++; 358 env_argc++;
329 } 359 }
330 internalParseCommandLine(env_argc, env_argv); 360 internalParseCommandLine(env_argc, env_argv);
331 for(int i2 = 0; i2 < env_size; i2++) { 361 for(int i2 = 0; i2 < env_size; i2++) {
332 if(env_argv[i2]) 362 if(env_argv[i2])
333 free(env_argv[i2]); 363 free(env_argv[i2]);
334 } 364 }
335 free(env_argv); 365 free(env_argv);
336 } 366 }
337 if(!internalParseCommandLine(argc, argv, 1)) 367 {
338 return usage(argv[0]); 368 int ret = internalParseCommandLine(argc, argv, 1);
369 if(ret != QMAKE_CMDLINE_SUCCESS)
370 return ret == QMAKE_CMDLINE_SHOW_USAGE ? usage(argv[0]) : FALSE;
371 }
339 372
340 //last chance for defaults 373 //last chance for defaults
341 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || 374 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
342 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) { 375 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
343 if(Option::mkfile::qmakespec.isNull() || Option::mkfile::qmakespec.isEmpty()) 376 if(Option::mkfile::qmakespec.isNull() || Option::mkfile::qmakespec.isEmpty())
344 Option::mkfile::qmakespec = getenv("QMAKESPEC"); 377 Option::mkfile::qmakespec = getenv("QMAKESPEC");
345 378
346 //try REALLY hard to do it for them, lazy.. 379 //try REALLY hard to do it for them, lazy..
347 if(Option::mkfile::project_files.isEmpty()) { 380 if(Option::mkfile::project_files.isEmpty()) {
348 QString pwd = QDir::currentDirPath(), 381 QString pwd = QDir::currentDirPath(),
349 proj = pwd + "/" + pwd.right(pwd.length() - (pwd.findRev('/') + 1)) + ".pro"; 382 proj = pwd + "/" + pwd.right(pwd.length() - (pwd.findRev('/') + 1)) + ".pro";
350 if(QFile::exists(proj)) { 383 if(QFile::exists(proj)) {
351 Option::mkfile::project_files.append(proj); 384 Option::mkfile::project_files.append(proj);
352 } else { //last try.. 385 } else { //last try..
353 QDir d(pwd, "*.pro"); 386 QDir d(pwd, "*.pro");
354 if(d.count() != 1) 387 if(d.count() != 1)
355 return usage(argv[0]); 388 return usage(argv[0]);
356 Option::mkfile::project_files.append(pwd + "/" + d[0]); 389 Option::mkfile::project_files.append(pwd + "/" + d[0]);
357 } 390 }
358 } 391 }
359 } 392 }
360 393
361 //defaults for globals 394 //defaults for globals
362 if(Option::target_mode == Option::TARG_WIN_MODE) { 395 if(Option::target_mode == Option::TARG_WIN_MODE) {
363 Option::dir_sep = "\\"; 396 Option::dir_sep = "\\";
364 Option::obj_ext = ".obj"; 397 Option::obj_ext = ".obj";
365 } else { 398 } else {
366 if(Option::target_mode == Option::TARG_MAC9_MODE) 399 if(Option::target_mode == Option::TARG_MAC9_MODE)
367 Option::dir_sep = ":"; 400 Option::dir_sep = ":";
368 else 401 else
369 Option::dir_sep = "/"; 402 Option::dir_sep = "/";
370 Option::obj_ext = ".o"; 403 Option::obj_ext = ".o";
371 } 404 }
372 return TRUE; 405 return TRUE;
373} 406}
374 407
375bool Option::postProcessProject(QMakeProject *project) 408bool Option::postProcessProject(QMakeProject *project)
376{ 409{
377 Option::cpp_ext = project->variables()["QMAKE_EXT_CPP"]; 410 Option::cpp_ext = project->variables()["QMAKE_EXT_CPP"];
378 if(cpp_ext.isEmpty()) 411 if(cpp_ext.isEmpty())
379 cpp_ext << ".cpp"; //something must be there 412 cpp_ext << ".cpp"; //something must be there
380 Option::h_ext = project->variables()["QMAKE_EXT_H"]; 413 Option::h_ext = project->variables()["QMAKE_EXT_H"];
381 if(h_ext.isEmpty()) 414 if(h_ext.isEmpty())
382 h_ext << ".h"; 415 h_ext << ".h";
383 416
417 if(!project->isEmpty("QMAKE_EXT_PKGCONFIG"))
418 Option::pkgcfg_ext = project->first("QMAKE_EXT_PKGCONFIG");
419 if(!project->isEmpty("QMAKE_EXT_LIBTOOL"))
420 Option::libtool_ext = project->first("QMAKE_EXT_LIBTOOL");
384 if(!project->isEmpty("QMAKE_EXT_PRL")) 421 if(!project->isEmpty("QMAKE_EXT_PRL"))
385 Option::prl_ext = project->first("QMAKE_EXT_PRL"); 422 Option::prl_ext = project->first("QMAKE_EXT_PRL");
386 if(!project->isEmpty("QMAKE_EXT_PRF")) 423 if(!project->isEmpty("QMAKE_EXT_PRF"))
387 Option::prf_ext = project->first("QMAKE_EXT_PRF"); 424 Option::prf_ext = project->first("QMAKE_EXT_PRF");
388 if(!project->isEmpty("QMAKE_EXT_UI")) 425 if(!project->isEmpty("QMAKE_EXT_UI"))
389 Option::ui_ext = project->first("QMAKE_EXT_UI"); 426 Option::ui_ext = project->first("QMAKE_EXT_UI");
390 if(!project->isEmpty("QMAKE_EXT_MOC")) 427 if(!project->isEmpty("QMAKE_EXT_CPP_MOC"))
391 Option::moc_ext = project->first("QMAKE_EXT_MOC"); 428 Option::cpp_moc_ext = project->first("QMAKE_EXT_CPP_MOC");
429 if(!project->isEmpty("QMAKE_EXT_H_MOC"))
430 Option::h_moc_ext = project->first("QMAKE_EXT_H_MOC");
392 if(!project->isEmpty("QMAKE_EXT_LEX")) 431 if(!project->isEmpty("QMAKE_EXT_LEX"))
393 Option::lex_ext = project->first("QMAKE_EXT_LEX"); 432 Option::lex_ext = project->first("QMAKE_EXT_LEX");
394 if(!project->isEmpty("QMAKE_EXT_YACC")) 433 if(!project->isEmpty("QMAKE_EXT_YACC"))
395 Option::yacc_ext = project->first("QMAKE_EXT_YACC"); 434 Option::yacc_ext = project->first("QMAKE_EXT_YACC");
396 if(!project->isEmpty("QMAKE_EXT_OBJ")) 435 if(!project->isEmpty("QMAKE_EXT_OBJ"))
397 Option::obj_ext = project->first("QMAKE_EXT_OBJ"); 436 Option::obj_ext = project->first("QMAKE_EXT_OBJ");
398 if(!project->isEmpty("QMAKE_MOD_MOC")) 437 if(!project->isEmpty("QMAKE_H_MOD_MOC"))
399 Option::moc_mod = project->first("QMAKE_MOD_MOC"); 438 Option::h_moc_mod = project->first("QMAKE_H_MOD_MOC");
439 if(!project->isEmpty("QMAKE_CPP_MOD_MOC"))
440 Option::cpp_moc_mod = project->first("QMAKE_CPP_MOD_MOC");
400 if(!project->isEmpty("QMAKE_MOD_LEX")) 441 if(!project->isEmpty("QMAKE_MOD_LEX"))
401 Option::lex_mod = project->first("QMAKE_MOD_LEX"); 442 Option::lex_mod = project->first("QMAKE_MOD_LEX");
402 if(!project->isEmpty("QMAKE_MOD_YACC")) 443 if(!project->isEmpty("QMAKE_MOD_YACC"))
403 Option::yacc_mod = project->first("QMAKE_MOD_YACC"); 444 Option::yacc_mod = project->first("QMAKE_MOD_YACC");
404 if(!project->isEmpty("QMAKE_DIR_SEP")) 445 if(!project->isEmpty("QMAKE_DIR_SEP"))
405 Option::dir_sep = project->first("QMAKE_DIR_SEP"); 446 Option::dir_sep = project->first("QMAKE_DIR_SEP");
406 return TRUE; 447 return TRUE;
407} 448}
408 449
409void fixEnvVariables(QString &x) 450void fixEnvVariables(QString &x)
410{ 451{
411 int rep; 452 int rep;
412 QRegExp reg_var("\\$\\(.*\\)"); 453 QRegExp reg_var("\\$\\(.*\\)");
413 reg_var.setMinimal( TRUE ); 454 reg_var.setMinimal( TRUE );
414 while((rep = reg_var.search(x)) != -1) 455 while((rep = reg_var.search(x)) != -1)
415 x.replace(rep, reg_var.matchedLength(), QString(getenv(x.mid(rep + 2, reg_var.matchedLength() - 3).latin1()))); 456 x.replace(rep, reg_var.matchedLength(), QString(getenv(x.mid(rep + 2, reg_var.matchedLength() - 3).latin1())));
416} 457}
417static QString fixPath(QString x) 458static QString fixPath(QString x)
418{ 459{
419#if 0 460#if 0
420 QFileInfo fi(x); 461 QFileInfo fi(x);
421 if(fi.isDir()) { 462 if(fi.isDir()) {
422 QDir dir(x); 463 QDir dir(x);
423 x = dir.canonicalPath(); 464 x = dir.canonicalPath();
424 } else { 465 } else {
425 QString dir = fi.dir().canonicalPath(); 466 QString dir = fi.dir().canonicalPath();
426 if(!dir.isEmpty() && dir.right(1) != Option::dir_sep) 467 if(!dir.isEmpty() && dir.right(1) != Option::dir_sep)
427 dir += Option::dir_sep; 468 dir += Option::dir_sep;
428 x = dir + fi.fileName(); 469 x = dir + fi.fileName();
429 } 470 }
430#endif 471#endif
431 return QDir::cleanDirPath(x); 472 return QDir::cleanDirPath(x);
432} 473}
433 474
434 475
435QString 476QString
436Option::fixPathToTargetOS(const QString& in, bool fix_env, bool canonical) 477Option::fixPathToTargetOS(const QString& in, bool fix_env, bool canonical)
437{ 478{
438 QString tmp(in); 479 QString tmp(in);
439 if(fix_env) 480 if(fix_env)
440 fixEnvVariables(tmp); 481 fixEnvVariables(tmp);
441 if(canonical) 482 if(canonical)
442 tmp = fixPath(tmp); 483 tmp = fixPath(tmp);
443 QString rep; 484 QString rep;
444 if(Option::target_mode == TARG_MAC9_MODE) 485 if(Option::target_mode == TARG_MAC9_MODE)
445 tmp = tmp.replace('/', Option::dir_sep).replace('\\', Option::dir_sep); 486 tmp = tmp.replace('/', Option::dir_sep).replace('\\', Option::dir_sep);
446 else if(Option::target_mode == TARG_WIN_MODE) 487 else if(Option::target_mode == TARG_WIN_MODE)
447 tmp = tmp.replace('/', Option::dir_sep); 488 tmp = tmp.replace('/', Option::dir_sep);
448 else 489 else
449 tmp = tmp.replace('\\', Option::dir_sep); 490 tmp = tmp.replace('\\', Option::dir_sep);
450 return tmp; 491 return tmp;
451} 492}
452 493
453QString 494QString
454Option::fixPathToLocalOS(const QString& in, bool fix_env, bool canonical) 495Option::fixPathToLocalOS(const QString& in, bool fix_env, bool canonical)
455{ 496{
456 QString tmp(in); 497 QString tmp(in);
457 if(fix_env) 498 if(fix_env)
458 fixEnvVariables(tmp); 499 fixEnvVariables(tmp);
459 if(canonical) 500 if(canonical)
460 tmp = fixPath(tmp); 501 tmp = fixPath(tmp);
461#if defined(Q_OS_WIN32) 502#if defined(Q_OS_WIN32)
462 return tmp.replace('/', '\\'); 503 return tmp.replace('/', '\\');
463#else 504#else
464 return tmp.replace('\\', '/'); 505 return tmp.replace('\\', '/');
465#endif 506#endif
466} 507}
467 508
468const char *qmake_version() 509const char *qmake_version()
469{ 510{
470 static char *ret = NULL; 511 static char *ret = NULL;
471 if(ret) 512 if(ret)
472 return ret; 513 return ret;
473 ret = (char *)malloc(15); 514 ret = (char *)malloc(15);
474 sprintf(ret, "%d.%02d%c", QMAKE_VERSION_MAJOR, QMAKE_VERSION_MINOR, 'a' + QMAKE_VERSION_PATCH); 515 sprintf(ret, "%d.%02d%c", QMAKE_VERSION_MAJOR, QMAKE_VERSION_MINOR, 'a' + QMAKE_VERSION_PATCH);
475 return ret; 516 return ret;
476} 517}
477 518
478void debug_msg(int level, const char *fmt, ...) 519void debug_msg(int level, const char *fmt, ...)
479{ 520{
480 if(Option::debug_level < level) 521 if(Option::debug_level < level)
481 return; 522 return;
482 fprintf(stderr, "DEBUG %d: ", level); 523 fprintf(stderr, "DEBUG %d: ", level);
483 { 524 {
484 va_list ap; 525 va_list ap;
485 va_start(ap, fmt); 526 va_start(ap, fmt);
486 vfprintf(stderr, fmt, ap); 527 vfprintf(stderr, fmt, ap);
487 va_end(ap); 528 va_end(ap);
488 } 529 }
489 fprintf(stderr, "\n"); 530 fprintf(stderr, "\n");
490} 531}
491 532
492void warn_msg(QMakeWarn type, const char *fmt, ...) 533void warn_msg(QMakeWarn type, const char *fmt, ...)
493{ 534{
494 if(!(Option::warn_level & type)) 535 if(!(Option::warn_level & type))
495 return; 536 return;
496 fprintf(stderr, "WARNING: "); 537 fprintf(stderr, "WARNING: ");
497 { 538 {
498 va_list ap; 539 va_list ap;
499 va_start(ap, fmt); 540 va_start(ap, fmt);
500 vfprintf(stderr, fmt, ap); 541 vfprintf(stderr, fmt, ap);
501 va_end(ap); 542 va_end(ap);
502 } 543 }
503 fprintf(stderr, "\n"); 544 fprintf(stderr, "\n");
504} 545}