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