-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 @@ -77,46 +77,57 @@ Option::TARG_MODE Option::target_mode = Option::TARG_MACX_MODE; #elif defined(Q_OS_QNX6) Option::TARG_MODE Option::target_mode = Option::TARG_QNX6_MODE; #else Option::TARG_MODE Option::target_mode = Option::TARG_UNIX_MODE; #endif //QMAKE_GENERATE_PROJECT stuff bool Option::projfile::do_pwd = TRUE; -bool Option::projfile::do_recursive = FALSE; +bool Option::projfile::do_recursive = TRUE; QStringList Option::projfile::project_dirs; //QMAKE_GENERATE_MAKEFILE stuff QString Option::mkfile::qmakespec; int Option::mkfile::cachefile_depth = -1; bool Option::mkfile::do_deps = TRUE; bool Option::mkfile::do_mocs = TRUE; bool Option::mkfile::do_dep_heuristics = TRUE; bool Option::mkfile::do_preprocess = FALSE; bool Option::mkfile::do_cache = TRUE; QString Option::mkfile::cachefile; QStringList Option::mkfile::project_files; QString Option::mkfile::qmakespec_commandline; +static Option::QMAKE_MODE default_mode(QString progname) +{ + int s = progname.findRev(Option::dir_sep); + if(s != -1) + progname = progname.right(progname.length() - (s + 1)); + if(progname == "qmakegen") + return Option::QMAKE_GENERATE_PROJECT; + return Option::QMAKE_GENERATE_MAKEFILE; +} + +QString project_builtin_regx(); bool usage(const char *a0) { fprintf(stdout, "Usage: %s [mode] [options] [files]\n" "\n" " QMake has two modes, one mode for generating project files based on\n" "some heuristics, and the other for generating makefiles. Normally you\n" "shouldn't need to specify a mode, as makefile generation is the default\n" "mode for qmake, but you may use this to test qmake on an existing project\n" "\n" "Mode:\n" - "\t-project Put qmake into project file generation mode\n" + "\t-project Put qmake into project file generation mode%s\n" "\t In this mode qmake interprets files as files to\n" "\t be built,\n" - "\t defaults to *.cpp; *.l; *.y; *.ui\n" - "\t-makefile Put qmake into makefile generation mode (default)\n" + "\t defaults to %s\n" + "\t-makefile Put qmake into makefile generation mode%s\n" "\t In this mode qmake interprets files as project files to\n" "\t be processed, if skipped qmake will try to find a project\n" "\t file in your current working directory\n" "\n" "Warnings Options:\n" "\t-Wnone Turn off all warnings\n" "\t-Wall Turn on all warnings\n" "\t-Wparser Turn on parser warnings\n" @@ -131,60 +142,51 @@ bool usage(const char *a0) "\t-win32 Run in win32 mode\n" "\t-macx Run in Mac OS X mode\n" "\t-d Increase debug level\n" "\t-t templ Overrides TEMPLATE as templ\n" "\t-tp prefix Overrides TEMPLATE so that prefix is prefixed into the value\n" "\t-help This help\n" "\t-v Version information\n" "\t-after All variable assignments after this will be\n" - "\t parsed after [files] [makefile mode only]\n" + "\t parsed after [files]\n" "\t-cache file Use file as cache [makefile mode only]\n" "\t-spec spec Use spec as QMAKESPEC [makefile mode only]\n" "\t-nocache Don't use a cache file [makefile mode only]\n" "\t-nodepend Don't generate dependencies [makefile mode only]\n" "\t-nomoc Don't generate moc targets [makefile mode only]\n" "\t-nopwd Don't look for files in pwd [ project mode only]\n" - "\t-r Recursive search [ project mode only]\n" - ,a0); + "\t-norecursive Don't do a recursive search [ project mode only]\n" + ,a0, + default_mode(a0) == Option::QMAKE_GENERATE_PROJECT ? " (default)" : "", project_builtin_regx().latin1(), + default_mode(a0) == Option::QMAKE_GENERATE_MAKEFILE ? " (default)" : ""); return FALSE; } -static Option::QMAKE_MODE default_mode(QString progname) -{ - int s = progname.findRev(Option::dir_sep); - if(s != -1) - progname = progname.right(progname.length() - (s + 1)); - if(progname == "qmakegen") - return Option::QMAKE_GENERATE_PROJECT; - return Option::QMAKE_GENERATE_MAKEFILE; -} - bool -Option::parseCommandLine(int argc, char **argv) +Option::internalParseCommandLine(int argc, char **argv, int skip) { bool before = TRUE; - for(int x = 1; x < argc; x++) { + for(int x = skip; x < argc; x++) { if(*argv[x] == '-' && strlen(argv[x]) > 1) { /* options */ QString opt = argv[x] + 1; //first param is a mode, or we default if(x == 1) { bool specified = TRUE; if(opt == "project") { Option::qmake_mode = Option::QMAKE_GENERATE_PROJECT; } else if(opt == "prl") { Option::mkfile::do_deps = FALSE; Option::mkfile::do_mocs = FALSE; Option::qmake_mode = Option::QMAKE_GENERATE_PRL; } else if(opt == "makefile") { Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE; } else { specified = FALSE; - Option::qmake_mode = default_mode(argv[0]); } if(specified) continue; } //all modes if(opt == "o" || opt == "output") { Option::output.setName(argv[++x]); } else if(opt == "after") { @@ -199,21 +201,21 @@ Option::parseCommandLine(int argc, char **argv) Option::target_mode = TARG_MACX_MODE; } else if(opt == "unix") { Option::target_mode = TARG_UNIX_MODE; } else if(opt == "win32") { Option::target_mode = TARG_WIN_MODE; } else if(opt == "d") { Option::debug_level++; } else if(opt == "version" || opt == "v" || opt == "-version") { - fprintf(stderr, "Qmake version: %s\n", qmake_version()); + fprintf(stderr, "Qmake version: %s (Qt %s)\n", qmake_version(), QT_VERSION_STR); fprintf(stderr, "Qmake is free software from Trolltech AS.\n"); return FALSE; } else if(opt == "h" || opt == "help") { - return usage(argv[0]); + return FALSE; } else if(opt == "Wall") { Option::warn_level |= WarnAll; } else if(opt == "Wparser") { Option::warn_level |= WarnParser; } else if(opt == "Wlogic") { Option::warn_level |= WarnLogic; } else if(opt == "Wnone") { Option::warn_level = WarnNone; @@ -239,26 +241,25 @@ Option::parseCommandLine(int argc, char **argv) fprintf(stderr, "***Unknown option -%s\n", opt.latin1()); return usage(argv[0]); } } else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) { if(opt == "nopwd") { Option::projfile::do_pwd = FALSE; } else if(opt == "r") { Option::projfile::do_recursive = TRUE; + } else if(opt == "norecursive") { + Option::projfile::do_recursive = FALSE; } else { fprintf(stderr, "***Unknown option -%s\n", opt.latin1()); - return usage(argv[0]); + return FALSE; } } } } else { - if(x == 1) - Option::qmake_mode = default_mode(argv[0]); - QString arg = argv[x]; if(arg.find('=') != -1) { if(before) Option::before_user_vars.append(arg); else Option::after_user_vars.append(arg); } else { QFileInfo fi(arg); @@ -267,48 +268,102 @@ Option::parseCommandLine(int argc, char **argv) if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || Option::qmake_mode == Option::QMAKE_GENERATE_PRL) Option::mkfile::project_files.append(arg); else Option::projfile::project_dirs.append(arg); } } } + return TRUE; +} + + +bool +Option::parseCommandLine(int argc, char **argv) +{ + Option::moc_mod = "moc_"; + Option::lex_mod = "_lex"; + Option::yacc_mod = "_yacc"; + Option::prl_ext = ".prl"; + Option::prf_ext = ".prf"; + Option::ui_ext = ".ui"; + Option::h_ext << ".h" << ".hpp" << ".hh" << ".H" << ".hxx"; + Option::moc_ext = ".moc"; + Option::cpp_ext << ".cpp" << ".cc" << ".cxx" << ".C"; + Option::lex_ext = ".l"; + Option::yacc_ext = ".y"; + if(Option::qmake_mode == Option::QMAKE_GENERATE_NOTHING) Option::qmake_mode = default_mode(argv[0]); + if(const char *envflags = getenv("QMAKEFLAGS")) { + int env_argc = 0, env_size = 0, currlen=0; + char quote = 0, **env_argv = NULL; + for(int i = 0; envflags[i]; i++) { + if(!quote && (envflags[i] == '\'' || envflags[i] == '"')) { + quote = envflags[i]; + } else if(envflags[i] == quote) { + quote = 0; + } else if(!quote && envflags[i] == ' ') { + if(currlen && env_argv && env_argv[env_argc]) { + env_argv[env_argc][currlen] = '\0'; + currlen = 0; + env_argc++; + } + } else { + if(!env_argv || env_argc > env_size) { + env_argv = (char **)realloc(env_argv, sizeof(char *)*(env_size+=10)); + for(int i2 = env_argc; i2 < env_size; i2++) + env_argv[i2] = NULL; + } + if(!env_argv[env_argc]) { + currlen = 0; + env_argv[env_argc] = (char*)malloc(255); + } + if(currlen < 255) + env_argv[env_argc][currlen++] = envflags[i]; + } + } + if(env_argv[env_argc]) { + env_argv[env_argc][currlen] = '\0'; + currlen = 0; + env_argc++; + } + internalParseCommandLine(env_argc, env_argv); + for(int i2 = 0; i2 < env_size; i2++) { + if(env_argv[i2]) + free(env_argv[i2]); + } + free(env_argv); + } + if(!internalParseCommandLine(argc, argv, 1)) + return usage(argv[0]); //last chance for defaults if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || Option::qmake_mode == Option::QMAKE_GENERATE_PRL) { if(Option::mkfile::qmakespec.isNull() || Option::mkfile::qmakespec.isEmpty()) Option::mkfile::qmakespec = getenv("QMAKESPEC"); //try REALLY hard to do it for them, lazy.. if(Option::mkfile::project_files.isEmpty()) { - QString proj = QDir::currentDirPath(); - proj = proj.right(proj.length() - (proj.findRev('/') + 1)) + ".pro"; - if(QFile::exists(proj)) + QString pwd = QDir::currentDirPath(), + proj = pwd + "/" + pwd.right(pwd.length() - (pwd.findRev('/') + 1)) + ".pro"; + if(QFile::exists(proj)) { Option::mkfile::project_files.append(proj); - else - return usage(argv[0]); + } else { //last try.. + QDir d(pwd, "*.pro"); + if(d.count() != 1) + return usage(argv[0]); + Option::mkfile::project_files.append(pwd + "/" + d[0]); + } } } //defaults for globals - Option::moc_mod = "moc_"; - Option::lex_mod = "_lex"; - Option::yacc_mod = "_yacc"; - Option::prl_ext = ".prl"; - Option::prf_ext = ".prf"; - Option::ui_ext = ".ui"; - Option::h_ext << ".h" << ".hpp" << ".hh" << ".H" << ".hxx"; - Option::moc_ext = ".moc"; - Option::cpp_ext << ".cpp" << ".cc" << ".cxx" << ".C"; - Option::lex_ext = ".l"; - Option::yacc_ext = ".y"; if(Option::target_mode == Option::TARG_WIN_MODE) { Option::dir_sep = "\\"; Option::obj_ext = ".obj"; } else { if(Option::target_mode == Option::TARG_MAC9_MODE) Option::dir_sep = ":"; else Option::dir_sep = "/"; @@ -381,23 +436,23 @@ QString Option::fixPathToTargetOS(const QString& in, bool fix_env, bool canonical) { QString tmp(in); if(fix_env) fixEnvVariables(tmp); if(canonical) tmp = fixPath(tmp); QString rep; - if(Option::target_mode == TARG_MAC9_MODE) - rep = "[/\\\\]"; - else if(Option::target_mode == TARG_WIN_MODE) - rep = "[/]"; - else - rep = "[\\\\]"; - return tmp.replace(QRegExp(rep), Option::dir_sep); + if(Option::target_mode == TARG_MAC9_MODE) + tmp = tmp.replace('/', Option::dir_sep).replace('\\', Option::dir_sep); + else if(Option::target_mode == TARG_WIN_MODE) + tmp = tmp.replace('/', Option::dir_sep); + else + tmp = tmp.replace('\\', Option::dir_sep); + return tmp; } QString Option::fixPathToLocalOS(const QString& in, bool fix_env, bool canonical) { QString tmp(in); if(fix_env) fixEnvVariables(tmp); |