sdcc makefile生成优化 (#377)

* sdcc makefile生成优化
1.隐藏删除文件的错误提示
2.支持生成目标文件输出目录

* 修复删不了文件

* 确保能删除编译文件同时不提示任何错误

* 更正clean脚本错误(%1 2>&1)应为(%1 2>%1)
指定生成目标文件输出目录支持跨盘,跨平台(理论)

* 预防配置项为相对路径

* clean 目标与>%1中间添加空格,避免错误
This commit is contained in:
zw9629 2024-04-14 12:13:39 +08:00 committed by GitHub
parent c6c7d92e1c
commit 697bdca255
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 4 deletions

View File

@ -195,7 +195,7 @@ void SDCCProjectCompiler::writeMakeIncludes(QFile &file)
void SDCCProjectCompiler::writeMakeClean(QFile &file) void SDCCProjectCompiler::writeMakeClean(QFile &file)
{ {
writeln(file, "clean: clean-custom"); writeln(file, "clean: clean-custom");
writeln(file, QString("\t-$(RM) $(CLEANOBJ) > %1 2>&1").arg(NULL_FILE)); writeln(file, QString("\t@-$(RM) $(CLEANOBJ) >%1 2>%1||:").arg(NULL_FILE));
writeln(file); writeln(file);
} }
@ -256,6 +256,7 @@ void SDCCProjectCompiler::writeMakeObjFilesRules(QFile &file)
writeln(file, objStr); writeln(file, objStr);
// Write custom build command // Write custom build command
if (unit->overrideBuildCmd() && !unit->buildCmd().isEmpty()) { if (unit->overrideBuildCmd() && !unit->buildCmd().isEmpty()) {
QString BuildCmd = unit->buildCmd(); QString BuildCmd = unit->buildCmd();
BuildCmd.replace("<CRTAB>", "\n\t"); BuildCmd.replace("<CRTAB>", "\n\t");
@ -263,8 +264,16 @@ void SDCCProjectCompiler::writeMakeObjFilesRules(QFile &file)
// Or roll our own // Or roll our own
} else { } else {
if (fileType==FileType::CSource) { if (fileType==FileType::CSource) {
writeln(file, "\t$(CC) $(CFLAGS) -c " + escapeArgumentForMakefileRecipe(shortFileName, false)); if(mProject->options().folderForObjFiles.isEmpty()) {
} writeln(file, "\t$(CC) $(CFLAGS) -c " + escapeArgumentForMakefileRecipe(shortFileName, false));
}else{
QString fullObjDir = includeTrailingPathDelimiter(mProject->options().folderForObjFiles);
QString relativeObjDir = extractRelativePath(mProject->directory(),fullObjDir);
QString objfile=extractRelativePath(generateAbsolutePath(mProject->directory(),relativeObjDir),unit->fileName());
writeln(file, "\tpushd "+ localizePath(relativeObjDir)+" &&$(CC) $(CFLAGS) -c " + localizePath(objfile));
}
}
} }
} }
@ -316,7 +325,7 @@ bool SDCCProjectCompiler::prepareForCompile()
parallelParam = "-j1"; parallelParam = "-j1";
} }
QString makefile = QString makefile =
extractRelativePath(mProject->directory(), mProject->makeFileName()); extractRelativePath(mProject->directory(), mProject->makeFileName());
QStringList cleanArgs{ QStringList cleanArgs{
"-f", "-f",