author | llornkcor <llornkcor> | 2003-07-10 02:40:10 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-07-10 02:40:10 (UTC) |
commit | 155d68c1e7d7dc0fed2534ac43d6d77ce2781f55 (patch) (unidiff) | |
tree | e6edaa5a7040fe6c224c3943d1094dcf02e4f74c /qmake/option.cpp | |
parent | 86703e8a5527ef114facd02c005b6b3a7e62e263 (diff) | |
download | opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.zip opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.tar.gz opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.tar.bz2 |
update qmake to 1.05a
-rw-r--r-- | qmake/option.cpp | 145 |
1 files changed, 100 insertions, 45 deletions
diff --git a/qmake/option.cpp b/qmake/option.cpp index 34b3ee2..8b7e5e8 100644 --- a/qmake/option.cpp +++ b/qmake/option.cpp | |||
@@ -82,7 +82,7 @@ Option::TARG_MODE Option::target_mode = Option::TARG_UNIX_MODE; | |||
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 |
@@ -97,6 +97,17 @@ 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" |
@@ -107,11 +118,11 @@ bool usage(const char *a0) | |||
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" |
@@ -136,33 +147,25 @@ bool usage(const char *a0) | |||
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 | ||
@@ -179,7 +182,6 @@ Option::parseCommandLine(int argc, char **argv) | |||
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; |
@@ -204,11 +206,11 @@ Option::parseCommandLine(int argc, char **argv) | |||
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") { |
@@ -244,16 +246,15 @@ Option::parseCommandLine(int argc, char **argv) | |||
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) |
@@ -272,8 +273,69 @@ Option::parseCommandLine(int argc, char **argv) | |||
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 || |
@@ -283,27 +345,20 @@ Option::parseCommandLine(int argc, char **argv) | |||
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.. |
353 | QDir d(pwd, "*.pro"); | ||
354 | if(d.count() != 1) | ||
291 | return usage(argv[0]); | 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"; |
@@ -387,12 +442,12 @@ Option::fixPathToTargetOS(const QString& in, bool fix_env, bool 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 |