summaryrefslogtreecommitdiff
path: root/qmake/option.cpp
Unidiff
Diffstat (limited to 'qmake/option.cpp') (more/less context) (show whitespace changes)
-rw-r--r--qmake/option.cpp85
1 files changed, 63 insertions, 22 deletions
diff --git a/qmake/option.cpp b/qmake/option.cpp
index 8b7e5e8..e6928fa 100644
--- a/qmake/option.cpp
+++ b/qmake/option.cpp
@@ -1,16 +1,14 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$
3** 2**
4** Definition of ________ class.
5** 3**
6** Created : 970521 4** Implementation of Option class.
7** 5**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 6** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
9** 7**
10** This file is part of the network module of the Qt GUI Toolkit. 8** This file is part of qmake.
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
@@ -41,21 +39,25 @@
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
@@ -77,12 +79,15 @@ Option::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
@@ -101,12 +106,14 @@ static 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{
@@ -158,13 +165,18 @@ bool usage(const char *a0)
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;
@@ -175,12 +187,16 @@ Option::internalParseCommandLine(int argc, char **argv, int skip)
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)
@@ -205,15 +221,15 @@ Option::internalParseCommandLine(int argc, char **argv, int skip)
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;
@@ -236,61 +252,75 @@ Option::internalParseCommandLine(int argc, char **argv, int skip)
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 {
281 bool handled = TRUE;
282 if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY ||
283 Option::qmake_mode == Option::QMAKE_SET_PROPERTY) {
284 Option::prop::properties.append(arg);
285 } else {
265 QFileInfo fi(arg); 286 QFileInfo fi(arg);
266 if(!fi.convertToAbs()) //strange 287 if(!fi.convertToAbs()) //strange
267 arg = fi.filePath(); 288 arg = fi.filePath();
268 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || 289 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
269 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) 290 Option::qmake_mode == Option::QMAKE_GENERATE_PRL)
270 Option::mkfile::project_files.append(arg); 291 Option::mkfile::project_files.append(arg);
271 else 292 else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
272 Option::projfile::project_dirs.append(arg); 293 Option::projfile::project_dirs.append(arg);
294 else
295 handled = FALSE;
273 } 296 }
297 if(!handled)
298 return QMAKE_CMDLINE_SHOW_USAGE;
274 } 299 }
275 } 300 }
276 return TRUE; 301 }
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]);
@@ -331,14 +361,17 @@ Option::parseCommandLine(int argc, char **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");
@@ -378,28 +411,36 @@ bool Option::postProcessProject(QMakeProject *project)
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");