summaryrefslogtreecommitdiffstats
path: root/qmake/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qmake/main.cpp')
-rw-r--r--qmake/main.cpp70
1 files changed, 69 insertions, 1 deletions
diff --git a/qmake/main.cpp b/qmake/main.cpp
index 6d7e023b41..2bdb5370df 100644
--- a/qmake/main.cpp
+++ b/qmake/main.cpp
@@ -47,6 +47,8 @@
# include <qt_windows.h>
#endif
+using namespace QMakeInternal;
+
QT_BEGIN_NAMESPACE
#ifdef Q_OS_WIN
@@ -232,20 +234,86 @@ static int doLink(int argc, char **argv)
return 0;
}
+#endif
+
+static int installFile(const QString &source, const QString &targetFileOrDirectory, bool exe = false)
+{
+ QFile sourceFile(source);
+
+ QString target(targetFileOrDirectory);
+ if (QFileInfo(target).isDir())
+ target += QDir::separator() + QFileInfo(sourceFile.fileName()).fileName();
+
+ if (QFile::exists(target))
+ QFile::remove(target);
+
+ QDir::root().mkpath(QFileInfo(target).absolutePath());
+
+ if (!sourceFile.copy(target)) {
+ fprintf(stderr, "Error copying %s to %s: %s\n", source.toLatin1().constData(), qPrintable(target), qPrintable(sourceFile.errorString()));
+ return 3;
+ }
+
+ if (exe) {
+ QFile targetFile(target);
+ if (!targetFile.setPermissions(sourceFile.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeUser |
+ QFileDevice::ExeGroup | QFileDevice::ExeOther)) {
+ fprintf(stderr, "Error setting execute permissions on %s: %s\n",
+ qPrintable(target), qPrintable(targetFile.errorString()));
+ return 3;
+ }
+ }
+
+ // Copy file times
+ QString error;
+ if (!IoUtils::touchFile(target, sourceFile.fileName(), &error)) {
+ fprintf(stderr, "%s", qPrintable(error));
+ return 3;
+ }
+ return 0;
+}
+
+static int doQInstall(int argc, char **argv)
+{
+ if (argc != 3) {
+ fprintf(stderr, "Error: this qinstall command requires exactly three arguments (type, source, destination)\n");
+ return 3;
+ }
+
+ const QString source = QString::fromLocal8Bit(argv[1]);
+ const QString target = QString::fromLocal8Bit(argv[2]);
+
+ if (!strcmp(argv[0], "file"))
+ return installFile(source, target);
+ if (!strcmp(argv[0], "program"))
+ return installFile(source, target, /*exe=*/true);
+
+ fprintf(stderr, "Error: Unsupported qinstall command type %s\n", argv[0]);
+ return 3;
+}
+
+
static int doInstall(int argc, char **argv)
{
if (!argc) {
fprintf(stderr, "Error: -install requires further arguments\n");
return 3;
}
+#ifdef Q_OS_WIN
if (!strcmp(argv[0], "sed"))
return doSed(argc - 1, argv + 1);
if (!strcmp(argv[0], "ln"))
return doLink(argc - 1, argv + 1);
+#endif
+ if (!strcmp(argv[0], "qinstall"))
+ return doQInstall(argc - 1, argv + 1);
fprintf(stderr, "Error: unrecognized -install subcommand '%s'\n", argv[0]);
return 3;
}
+
+#ifdef Q_OS_WIN
+
static int dumpMacros(const wchar_t *cmdline)
{
// from http://stackoverflow.com/questions/3665537/how-to-find-out-cl-exes-built-in-macros
@@ -300,11 +368,11 @@ int runQMake(int argc, char **argv)
// This is particularly important for things like QtCreator and scripted builds.
setvbuf(stdout, (char *)NULL, _IONBF, 0);
-#ifdef Q_OS_WIN
// Workaround for inferior/missing command line tools on Windows: make our own!
if (argc >= 2 && !strcmp(argv[1], "-install"))
return doInstall(argc - 2, argv + 2);
+#ifdef Q_OS_WIN
{
// Support running as Visual C++'s compiler
const wchar_t *cmdline = _wgetenv(L"MSC_CMD_FLAGS");