From 697bdca25558f5c157605a4a54ce7698431ba4e1 Mon Sep 17 00:00:00 2001 From: zw9629 <31214590+zw9629@users.noreply.github.com> Date: Sun, 14 Apr 2024 12:13:39 +0800 Subject: [PATCH] =?UTF-8?q?sdcc=20makefile=E7=94=9F=E6=88=90=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20(#377)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * sdcc makefile生成优化 1.隐藏删除文件的错误提示 2.支持生成目标文件输出目录 * 修复删不了文件 * 确保能删除编译文件同时不提示任何错误 * 更正clean脚本错误(%1 2>&1)应为(%1 2>%1) 指定生成目标文件输出目录支持跨盘,跨平台(理论) * 预防配置项为相对路径 * clean 目标与>%1中间添加空格,避免错误 --- RedPandaIDE/compiler/sdccprojectcompiler.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/RedPandaIDE/compiler/sdccprojectcompiler.cpp b/RedPandaIDE/compiler/sdccprojectcompiler.cpp index a754f732..28d4e661 100644 --- a/RedPandaIDE/compiler/sdccprojectcompiler.cpp +++ b/RedPandaIDE/compiler/sdccprojectcompiler.cpp @@ -195,7 +195,7 @@ void SDCCProjectCompiler::writeMakeIncludes(QFile &file) void SDCCProjectCompiler::writeMakeClean(QFile &file) { 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); } @@ -256,6 +256,7 @@ void SDCCProjectCompiler::writeMakeObjFilesRules(QFile &file) writeln(file, objStr); // Write custom build command + if (unit->overrideBuildCmd() && !unit->buildCmd().isEmpty()) { QString BuildCmd = unit->buildCmd(); BuildCmd.replace("", "\n\t"); @@ -263,8 +264,16 @@ void SDCCProjectCompiler::writeMakeObjFilesRules(QFile &file) // Or roll our own } else { 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"; } - QString makefile = + QString makefile = extractRelativePath(mProject->directory(), mProject->makeFileName()); QStringList cleanArgs{ "-f",