- fix: Correctly handle files whose name contains spaces in the generated makefile.

- fix: Correctly handle custom obj folder in the generated makefile.
This commit is contained in:
Roy Qu 2023-02-08 17:32:52 +08:00
parent d8f237a10e
commit 62737d6716
2 changed files with 44 additions and 30 deletions

View File

@ -10,6 +10,8 @@ Red Panda C++ Version 2.11
- enhancement: Improve auto indent. - enhancement: Improve auto indent.
- enhancement: Change the way to calculate execution time. - enhancement: Change the way to calculate execution time.
- enhancement: Auto reload openned project files that use "Project Default" as the encoding, when the project encoding setting is changed in the project options dialog. - enhancement: Auto reload openned project files that use "Project Default" as the encoding, when the project encoding setting is changed in the project options dialog.
- fix: Correctly handle files whose name contains spaces in the generated makefile.
- fix: Correctly handle custom obj folder in the generated makefile.
Red Panda C++ Version 2.10 Red Panda C++ Version 2.10

View File

@ -162,8 +162,8 @@ void ProjectCompiler::writeMakeDefines(QFile &file)
QString fullObjFile = includeTrailingPathDelimiter(mProject->options().objectOutput) QString fullObjFile = includeTrailingPathDelimiter(mProject->options().objectOutput)
+ extractFileName(unit->fileName()); + extractFileName(unit->fileName());
QString relativeObjFile = extractRelativePath(mProject->directory(), changeFileExt(fullObjFile, OBJ_EXT)); QString relativeObjFile = extractRelativePath(mProject->directory(), changeFileExt(fullObjFile, OBJ_EXT));
QString ObjFile = genMakePath2(relativeObjFile); QString objFile = genMakePath2(relativeObjFile);
Objects += ' ' + ObjFile; Objects += ' ' + objFile;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
cleanObjects += ' ' + genMakePath1(relativeObjFile).replace("/",QDir::separator()); cleanObjects += ' ' + genMakePath1(relativeObjFile).replace("/",QDir::separator());
#else #else
@ -189,20 +189,30 @@ void ProjectCompiler::writeMakeDefines(QFile &file)
LinkObjects = LinkObjects.trimmed(); LinkObjects = LinkObjects.trimmed();
// Get windres file // Get windres file
QString ObjResFile; QString objResFile;
QString objResFile2;
QString cleanRes;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (!mProject->options().privateResource.isEmpty()) { if (!mProject->options().privateResource.isEmpty()) {
if (!mProject->options().objectOutput.isEmpty()) { if (!mProject->options().objectOutput.isEmpty()) {
ObjResFile = includeTrailingPathDelimiter(mProject->options().objectOutput) + QString fullResFile = includeTrailingPathDelimiter(mProject->options().objectOutput) +
changeFileExt(mProject->options().privateResource, RES_EXT); changeFileExt(mProject->options().privateResource, RES_EXT);
} else
ObjResFile = changeFileExt(mProject->options().privateResource, RES_EXT); QString relativeResFile = extractRelativePath(mProject->directory(), fullResFile);
} objResFile = genMakePath1(relativeResFile);
objResFile2 = genMakePath2(relativeResFile);
cleanRes += ' ' + genMakePath1(changeFileExt(relativeResFile, OBJ_EXT)).replace("/",QDir::separator());
} else {
objResFile = genMakePath1(changeFileExt(mProject->options().privateResource, RES_EXT));
objResFile2 = genMakePath2(changeFileExt(mProject->options().privateResource, RES_EXT));
cleanRes += ' ' + genMakePath1(changeFileExt(mProject->options().privateResource, OBJ_EXT)).replace("/",QDir::separator());
}
}
#endif #endif
// Mention progress in the logs // Mention progress in the logs
if (!ObjResFile.isEmpty()) { if (!objResFile.isEmpty()) {
log(tr("- Resource File: %1").arg(generateAbsolutePath(mProject->directory(),ObjResFile))); log(tr("- Resource File: %1").arg(generateAbsolutePath(mProject->directory(),objResFile)));
} }
log(""); log("");
@ -224,17 +234,17 @@ void ProjectCompiler::writeMakeDefines(QFile &file)
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
writeln(file,"WINDRES = " + extractFileName(compilerSet()->resourceCompiler())); writeln(file,"WINDRES = " + extractFileName(compilerSet()->resourceCompiler()));
#endif #endif
if (!ObjResFile.isEmpty()) { if (!objResFile.isEmpty()) {
writeln(file,"RES = " + genMakePath1(ObjResFile)); writeln(file,"RES = " + objResFile2);
writeln(file,"OBJ = " + Objects + " $(RES)"); writeln(file,"OBJ = " + Objects + " $(RES)");
writeln(file,"LINKOBJ = " + LinkObjects + " $(RES)"); writeln(file,"LINKOBJ = " + LinkObjects + " " + objResFile);
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
writeln(file,"CLEANOBJ = " + cleanObjects + writeln(file,"CLEANOBJ = " + cleanObjects +
" " + genMakePath1(ObjResFile).replace("/",QDir::separator()) " " + cleanRes
+ " " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->executable())).replace("/",QDir::separator()) ); + " " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->executable())).replace("/",QDir::separator()) );
#else #else
writeln(file,"CLEANOBJ = " + cleanObjects + writeln(file,"CLEANOBJ = " + cleanObjects +
" " + genMakePath1(ObjResFile) " " + cleanRes
+ " " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->executable()))); + " " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->executable())));
#endif #endif
} else { } else {
@ -374,22 +384,22 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
objStr = objStr + ' ' + genMakePath2(extractRelativePath(mProject->makeFileName(),unit2->fileName())); objStr = objStr + ' ' + genMakePath2(extractRelativePath(mProject->makeFileName(),unit2->fileName()));
} }
} }
QString ObjFileName; QString objFileName;
QString ObjFileName2; QString objFileName2;
if (!mProject->options().objectOutput.isEmpty()) { if (!mProject->options().objectOutput.isEmpty()) {
ObjFileName = includeTrailingPathDelimiter(mProject->options().objectOutput) + QString fullObjname = includeTrailingPathDelimiter(mProject->options().objectOutput) +
extractFileName(unit->fileName()); extractFileName(unit->fileName());
ObjFileName = genMakePath2(extractRelativePath(mProject->makeFileName(), changeFileExt(ObjFileName, OBJ_EXT))); objFileName = genMakePath2(extractRelativePath(mProject->makeFileName(), changeFileExt(fullObjname, OBJ_EXT)));
ObjFileName2 = genMakePath1(extractRelativePath(mProject->makeFileName(), changeFileExt(ObjFileName, OBJ_EXT))); objFileName2 = genMakePath1(extractRelativePath(mProject->makeFileName(), changeFileExt(fullObjname, OBJ_EXT)));
// if (!extractFileDir(ObjFileName).isEmpty()) { // if (!extractFileDir(ObjFileName).isEmpty()) {
// objStr = genMakePath2(includeTrailingPathDelimiter(extractFileDir(ObjFileName))) + objStr; // objStr = genMakePath2(includeTrailingPathDelimiter(extractFileDir(ObjFileName))) + objStr;
// } // }
} else { } else {
ObjFileName = genMakePath2(changeFileExt(shortFileName, OBJ_EXT)); objFileName = genMakePath2(changeFileExt(shortFileName, OBJ_EXT));
ObjFileName2 = genMakePath1(changeFileExt(shortFileName, OBJ_EXT)); objFileName2 = genMakePath1(changeFileExt(shortFileName, OBJ_EXT));
} }
objStr = ObjFileName + ": "+objStr+precompileStr; objStr = objFileName + ": "+objStr+precompileStr;
writeln(file,objStr); writeln(file,objStr);
@ -456,9 +466,9 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
writeln(file, "\t(CC) -c " + genMakePath1(shortFileName) + " $(CFLAGS) " + encodingStr); writeln(file, "\t(CC) -c " + genMakePath1(shortFileName) + " $(CFLAGS) " + encodingStr);
} else { } else {
if (unit->compileCpp()) if (unit->compileCpp())
writeln(file, "\t$(CPP) -c " + genMakePath1(shortFileName) + " -o " + ObjFileName2 + " $(CXXFLAGS) " + encodingStr); writeln(file, "\t$(CPP) -c " + genMakePath1(shortFileName) + " -o " + objFileName2 + " $(CXXFLAGS) " + encodingStr);
else else
writeln(file, "\t$(CC) -c " + genMakePath1(shortFileName) + " -o " + ObjFileName2 + " $(CFLAGS) " + encodingStr); writeln(file, "\t$(CC) -c " + genMakePath1(shortFileName) + " -o " + objFileName2 + " $(CFLAGS) " + encodingStr);
} }
} }
} }
@ -489,15 +499,17 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
} }
// Determine resource output file // Determine resource output file
QString objFileName; QString fullName;
if (!mProject->options().objectOutput.isEmpty()) { if (!mProject->options().objectOutput.isEmpty()) {
objFileName = includeTrailingPathDelimiter(mProject->options().objectOutput) + fullName = includeTrailingPathDelimiter(mProject->options().objectOutput) +
changeFileExt(mProject->options().privateResource, RES_EXT); changeFileExt(mProject->options().privateResource, RES_EXT);
} else { } else {
objFileName = changeFileExt(mProject->options().privateResource, RES_EXT); fullName = changeFileExt(mProject->options().privateResource, RES_EXT);
} }
objFileName = genMakePath1(extractRelativePath(mProject->filename(), objFileName)); QString objFileName = genMakePath1(extractRelativePath(mProject->filename(), fullName));
QString objFileName2 = genMakePath2(extractRelativePath(mProject->filename(), fullName));
QString privResName = genMakePath1(extractRelativePath(mProject->filename(), mProject->options().privateResource)); QString privResName = genMakePath1(extractRelativePath(mProject->filename(), mProject->options().privateResource));
QString privResName2 = genMakePath2(extractRelativePath(mProject->filename(), mProject->options().privateResource));
// Build final cmd // Build final cmd
QString windresArgs; QString windresArgs;
@ -507,11 +519,11 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
if (mOnlyCheckSyntax) { if (mOnlyCheckSyntax) {
writeln(file); writeln(file);
writeln(file, objFileName + ':'); writeln(file, objFileName2 + ':');
writeln(file, "\t$(WINDRES) -i " + privResName + windresArgs + " --input-format=rc -o nul -O coff $(WINDRESFLAGS)" + ResIncludes); writeln(file, "\t$(WINDRES) -i " + privResName + windresArgs + " --input-format=rc -o nul -O coff $(WINDRESFLAGS)" + ResIncludes);
} else { } else {
writeln(file); writeln(file);
writeln(file, objFileName + ": " + privResName + ' ' + resFiles); writeln(file, objFileName2 + ": " + privResName2 + ' ' + resFiles);
writeln(file, "\t$(WINDRES) -i " + privResName + windresArgs + " --input-format=rc -o " + objFileName + " -O coff $(WINDRESFLAGS)" writeln(file, "\t$(WINDRES) -i " + privResName + windresArgs + " --input-format=rc -o " + objFileName + " -O coff $(WINDRESFLAGS)"
+ ResIncludes); + ResIncludes);
} }