int main(int argc, char **argv)
{
    if (argc == 1) {
        usage();
        return 0;
    }
    QString sdkName;
    bool operationList = false;
    QString scriptFile;

    QStringList arguments;
    for (int i=0; i < argc; ++i)
        arguments.append(QLatin1String(argv[i]));
    for (int i=1; i < arguments.size(); ++i) {
        if (arguments[i].toLower() == QLatin1String("-help")) {
            usage();
            return 0;
        } else if (arguments[i].toLower() == QLatin1String("-list")) {
            operationList = true;
        } else if (arguments[i].toLower() == QLatin1String("-sdk")) {
            if (i+1 >= arguments.size()) {
                qWarning("No SDK specified.");
                return -1;
            }
            sdkName = arguments[++i];
        } else if (arguments[i].toLower() == QLatin1String("-script")) {
            if (i+1 >= arguments.size()) {
                qWarning("No scriptfile specified.");
                return -1;
            }
            scriptFile = arguments[++i];
        } else {
            qWarning("Unknown option:%s", qPrintable(arguments[i]));
            usage();
            return -1;
        }
    }

    CeSdkHandler handler;
    if (!handler.parse()) {
        qWarning("Could not find any installed SDK, aborting!");
        return -1;
    }

    QList<CeSdkInfo> list = handler.listAll();

    if (operationList) {
        printf("Available SDKs:\n");
        for (QList<CeSdkInfo>::iterator it = list.begin(); it != list.end(); ++it) {
            printf("SDK Name: ");
            printf(qPrintable(it->name()));
            printf("\n");
        }
        return 0;
    }

    // Check for SDK Name, otherwise use Windows Mobile as default
    if (sdkName.isEmpty()) {
        qWarning("No SDK specified: Defaulting to Windows Mobile 5.0 Pocket PC SDK");
        sdkName = QString::fromLatin1("Windows Mobile 5.0 Pocket PC SDK (ARMV4I)");
    }

    // finally find the given SDK and prompt out the environment to be set
    for (QList<CeSdkInfo>::iterator it = list.begin(); it != list.end(); ++it ) {
        if (sdkName == it->name()) {
            if (!it->isValid()) {
                qWarning("Selected SDK is not valid!");
                return -1;
            } else if (!it->isSupported()) {
                qWarning("Selected SDK is not officially supported and might not work");
            }
            QString binPath, includePath, libPath;
            binPath = QString::fromLatin1("PATH=") + it->binPath();
            includePath = QString::fromLatin1("INCLUDE=") + it->includePath();
            libPath = QString::fromLatin1("LIB=") + it->libPath();
            if (scriptFile.isEmpty()) {
                printf("Please set up your environment with the following paths:\n");
                printf(qPrintable(binPath));
                printf("\n");
                printf(qPrintable(includePath));
                printf("\n");
                printf(qPrintable(libPath));
                printf("\n");
                return 0;
            } else {
                QFile file(scriptFile);
                if (!file.open(QIODevice::WriteOnly)) {
                    qWarning("Could not open target script file");
                    return -1;
                }
                QString content;
                content += QLatin1String("@echo off\n");
                content += QLatin1String("echo Environment Selection:") + sdkName + QLatin1String("\n");
                content += QLatin1String("set ") + binPath + QLatin1String("\n");
                content += QLatin1String("set ") + includePath + QLatin1String("\n");
                content += QLatin1String("set ") + libPath + QLatin1String("\n");
                file.write(content.toLatin1());
                return 0;
            }
        }
    }
    qWarning("Could not find specified SDK: %s" , qPrintable(sdkName));
    return -1;
}
Пример #2
0
bool
NmakeMakefileGenerator::writeMakefile(QTextStream &t)
{
    writeHeader(t);
    if (writeDummyMakefile(t))
        return true;

    if(project->first("TEMPLATE") == "app" ||
       project->first("TEMPLATE") == "lib" ||
       project->first("TEMPLATE") == "aux") {
#if 0
        if(Option::mkfile::do_stub_makefile)
            return MakefileGenerator::writeStubMakefile(t);
#endif
        if (!project->isHostBuild()) {
            const ProValueMap &variables = project->variables();
            if (project->isActiveConfig("wince")) {
                CeSdkHandler sdkhandler;
                sdkhandler.parse();
                const QString sdkName = variables["CE_SDK"].join(' ')
                                        + " (" + variables["CE_ARCH"].join(' ') + ")";
                const QList<CeSdkInfo> sdkList = sdkhandler.listAll();
                CeSdkInfo sdk;
                foreach (const CeSdkInfo &info, sdkList) {
                    if (info.name().compare(sdkName, Qt::CaseInsensitive ) == 0) {
                        sdk = info;
                        break;
                    }
                }
                if (sdk.isValid()) {
                    t << "\nINCLUDE = " << sdk.includePath();
                    t << "\nLIB = " << sdk.libPath();
                    t << "\nPATH = " << sdk.binPath() << "\n";
                } else {
                    QStringList sdkStringList;
                    foreach (const CeSdkInfo &info, sdkList)
                        sdkStringList << info.name();

                    fprintf(stderr, "Failed to find Windows CE SDK matching %s, found: %s\n"
                                    "SDK needs to be specified in mkspec (using: %s/qmake.conf)\n"
                                    "SDK name needs to match the following format: CE_SDK (CE_ARCH)\n",
                            qPrintable(sdkName), qPrintable(sdkStringList.join(", ")),
                            qPrintable(variables["QMAKESPEC"].first().toQString()));
                    return false;
                }
            } else if (project->isActiveConfig(QStringLiteral("winrt"))) {
                QString arch = project->first("VCPROJ_ARCH").toQString().toLower();
                QString compiler;
                QString compilerArch;
                if (arch == QStringLiteral("arm")) {
                    compiler = QStringLiteral("x86_arm");
                    compilerArch = QStringLiteral("arm");
                } else if (arch == QStringLiteral("x64")) {
                    const ProStringList hostArch = project->values("QMAKE_TARGET.arch");
                    if (hostArch.contains("x86_64"))
                        compiler = QStringLiteral("amd64");
                    else
                        compiler = QStringLiteral("x86_amd64");
                    compilerArch = QStringLiteral("amd64");
                } else {
                    arch = QStringLiteral("x86");
                }

                const QString msvcVer = project->first("MSVC_VER").toQString();
                if (msvcVer.isEmpty()) {
                    fprintf(stderr, "Mkspec does not specify MSVC_VER. Cannot continue.\n");
                    return false;
                }
                const QString winsdkVer = project->first("WINSDK_VER").toQString();
                if (winsdkVer.isEmpty()) {
                    fprintf(stderr, "Mkspec does not specify WINSDK_VER. Cannot continue.\n");
                    return false;
                }
                const QString targetVer = project->first("WINTARGET_VER").toQString();
                if (targetVer.isEmpty()) {
                    fprintf(stderr, "Mkspec does not specify WINTARGET_VER. Cannot continue.\n");
                    return false;
                }

                const bool isPhone = project->isActiveConfig(QStringLiteral("winphone"));
#ifdef Q_OS_WIN
                QString regKeyPrefix;
#if !defined(Q_OS_WIN64) && _WIN32_WINNT >= 0x0501
                BOOL isWow64;
                IsWow64Process(GetCurrentProcess(), &isWow64);
                if (!isWow64)
                    regKeyPrefix = QStringLiteral("Software\\");
                else
#endif
                    regKeyPrefix = QStringLiteral("Software\\Wow6432Node\\");

                QString regKey = regKeyPrefix + QStringLiteral("Microsoft\\VisualStudio\\") + msvcVer + ("\\Setup\\VC\\ProductDir");
                const QString vcInstallDir = qt_readRegistryKey(HKEY_LOCAL_MACHINE, regKey);
                if (vcInstallDir.isEmpty()) {
                    fprintf(stderr, "Failed to find the Visual Studio installation directory.\n");
                    return false;
                }

                regKey = regKeyPrefix
                        + (isPhone ? QStringLiteral("Microsoft\\Microsoft SDKs\\WindowsPhone\\v")
                                   : QStringLiteral("Microsoft\\Microsoft SDKs\\Windows\\v"))
                        + winsdkVer + QStringLiteral("\\InstallationFolder");
                const QString kitDir = qt_readRegistryKey(HKEY_LOCAL_MACHINE, regKey);
                if (kitDir.isEmpty()) {
                    fprintf(stderr, "Failed to find the Windows Kit installation directory.\n");
                    return false;
                }
#else
                const QString vcInstallDir = "/fake/vc_install_dir";
                const QString kitDir = "/fake/sdk_install_dir";
#endif // Q_OS_WIN

                QStringList incDirs;
                QStringList libDirs;
                QStringList binDirs;
                if (isPhone) {
                    QString sdkDir = vcInstallDir + QStringLiteral("/WPSDK/") + targetVer;
                    if (!QDir(sdkDir).exists()) {
                        fprintf(stderr, "Failed to find the Windows Phone SDK in %s.\n"
                                        "Check that it is properly installed.\n",
                                qPrintable(QDir::toNativeSeparators(sdkDir)));
                        return false;
                    }
                    incDirs << sdkDir + QStringLiteral("/include");
                    libDirs << sdkDir + QStringLiteral("/lib/") + compilerArch;
                    binDirs << sdkDir + QStringLiteral("/bin/") + compiler;
                    libDirs << kitDir + QStringLiteral("/lib/") + arch;
                    incDirs << kitDir + QStringLiteral("/include")
                            << kitDir + QStringLiteral("/include/abi")
                            << kitDir + QStringLiteral("/include/mincore")
                            << kitDir + QStringLiteral("/include/minwin");
                } else {
                    incDirs << vcInstallDir + QStringLiteral("/include");
                    libDirs << vcInstallDir + QStringLiteral("/lib/store/") + compilerArch
                            << vcInstallDir + QStringLiteral("/lib/") + compilerArch;
                    binDirs << vcInstallDir + QStringLiteral("/bin/") + compiler
                            << vcInstallDir + QStringLiteral("/../Common7/IDE");
                    libDirs << kitDir + QStringLiteral("/Lib/") + targetVer + ("/um/") + arch;
                    incDirs << kitDir + QStringLiteral("/include/um")
                            << kitDir + QStringLiteral("/include/shared")
                            << kitDir + QStringLiteral("/include/winrt");
                }

                // Inherit PATH
                binDirs << QString::fromLocal8Bit(qgetenv("PATH")).split(QLatin1Char(';'));

                t << "\nINCLUDE = " << nmakePathList(incDirs);
                t << "\nLIB = " << nmakePathList(libDirs);
                t << "\nPATH = " << nmakePathList(binDirs) << '\n';
            }
        }