From bac2b0ef369503a9f00c503c1d8c5b12a496c3eb Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 9 May 2019 10:42:03 +0200 Subject: qmake: Escape trailing backslash for OBJECTS_DIR for MinGW qmake automatically appends a dir_sep to a few directory paths (see MakefileGenerator::initOutPaths), and various .pri and .prf files rely on that. Anyhow, for non-MSys MinGW on Windows this creates a problem, because mingw32-make will interpret the backslash in OBJECTS_DIR = some_path\ to escape the following newline. We have been working around this problem in various ways: - winmakefile.cpp just removes the trailing \ for OBJECTS_DIR, at the cost of not being compatible with logic in .prf/.pri files that rely on the separator. - winmakefile.cpp adds a '#avoid trailing-slash linebreak' comment for DESTDIR. Anyhow, this does not seem to work for mingw32-make: If you reference $(DESTDIR), the variable will contain trailing spaces. - unixmakefile2.cpp duplicates a trailing \ for DESTDIR. The last approach is now taken also for OBJECTS_DIR. Task-number: QTBUG-75257 Change-Id: Ie8171a990a9ce1cfbf1b94037252ef2392313338 Reviewed-by: Joerg Bornemann --- qmake/generators/unix/unixmake2.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'qmake/generators/unix') diff --git a/qmake/generators/unix/unixmake2.cpp b/qmake/generators/unix/unixmake2.cpp index 7d8c70ec3b..b9de61fbc7 100644 --- a/qmake/generators/unix/unixmake2.cpp +++ b/qmake/generators/unix/unixmake2.cpp @@ -169,6 +169,16 @@ static QString rfc1034Identifier(const QString &str) return s; } +static QString escapeDir(const QString &dir) +{ + // When building on non-MSys MinGW, the path ends with a backslash, which + // GNU make will interpret that as a line continuation. Doubling the backslash + // avoids the problem, at the cost of the variable containing *both* backslashes. + if (dir.endsWith('\\')) + return dir + '\\'; + return dir; +} + void UnixMakefileGenerator::writeMakeParts(QTextStream &t) { @@ -231,7 +241,7 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t) t << "####### Output directory\n\n"; // This is used in commands by some .prf files. if (! project->values("OBJECTS_DIR").isEmpty()) - t << "OBJECTS_DIR = " << fileVar("OBJECTS_DIR") << endl; + t << "OBJECTS_DIR = " << escapeDir(fileVar("OBJECTS_DIR")) << endl; else t << "OBJECTS_DIR = ./\n"; t << endl; @@ -277,13 +287,7 @@ UnixMakefileGenerator::writeMakeParts(QTextStream &t) t << "DIST = " << valList(fileFixify(project->values("DISTFILES").toQStringList())) << " " << fileVarList("HEADERS") << ' ' << fileVarList("SOURCES") << endl; t << "QMAKE_TARGET = " << fileVar("QMAKE_ORIG_TARGET") << endl; - QString destd = fileVar("DESTDIR"); - // When building on non-MSys MinGW, the path ends with a backslash, which - // GNU make will interpret that as a line continuation. Doubling the backslash - // avoids the problem, at the cost of the variable containing *both* backslashes. - if (destd.endsWith('\\')) - destd += '\\'; - t << "DESTDIR = " << destd << endl; + t << "DESTDIR = " << escapeDir(fileVar("DESTDIR")) << endl; t << "TARGET = " << fileVar("TARGET") << endl; if(project->isActiveConfig("plugin")) { t << "TARGETD = " << fileVar("TARGET") << endl; -- cgit v1.2.3