RedPanda-CPP/RedPandaIDE/compiler/projectcompiler.cpp

633 lines
26 KiB
C++
Raw Normal View History

2021-12-26 23:18:28 +08:00
/*
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2021-09-13 07:49:36 +08:00
#include "projectcompiler.h"
2021-09-13 22:45:50 +08:00
#include "../project.h"
2021-09-13 10:48:44 +08:00
#include "compilermanager.h"
#include "../systemconsts.h"
2022-09-26 12:01:45 +08:00
#include "qt_utils/charsetinfo.h"
2021-09-13 22:45:50 +08:00
#include "../editor.h"
2021-09-13 10:48:44 +08:00
#include <QDir>
2021-09-13 07:49:36 +08:00
ProjectCompiler::ProjectCompiler(std::shared_ptr<Project> project, bool silent, bool onlyCheckSyntax):
Compiler("",silent,onlyCheckSyntax),
mOnlyClean(false)
2021-09-13 07:49:36 +08:00
{
setProject(project);
}
void ProjectCompiler::buildMakeFile()
{
2021-09-13 10:48:44 +08:00
//we are using custom make file, don't overwrite it
if (mProject->options().useCustomMakefile && !mProject->options().customMakefile.isEmpty())
2021-09-13 10:48:44 +08:00
return;
2021-09-13 07:49:36 +08:00
switch(mProject->options().type) {
case ProjectType::StaticLib:
createStaticMakeFile();
break;
case ProjectType::DynamicLib:
createDynamicMakeFile();
break;
default:
createStandardMakeFile();
}
}
2021-09-13 10:48:44 +08:00
void ProjectCompiler::createStandardMakeFile()
{
QFile file(mProject->makeFileName());
newMakeFile(file);
file.write("$(BIN): $(OBJ)\n");
if (!mOnlyCheckSyntax) {
if (mProject->options().isCpp) {
writeln(file,"\t$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)");
2021-09-13 10:48:44 +08:00
} else
writeln(file,"\t$(CC) $(LINKOBJ) -o $(BIN) $(LIBS)");
2021-09-13 10:48:44 +08:00
}
writeMakeObjFilesRules(file);
}
2021-09-13 22:45:50 +08:00
void ProjectCompiler::createStaticMakeFile()
{
QFile file(mProject->makeFileName());
newMakeFile(file);
writeln(file,"$(BIN): $(LINKOBJ)");
2021-09-13 22:45:50 +08:00
if (!mOnlyCheckSyntax) {
writeln(file,"\tar r $(BIN) $(LINKOBJ)");
writeln(file,"\tranlib $(BIN)");
2021-09-13 22:45:50 +08:00
}
writeMakeObjFilesRules(file);
}
void ProjectCompiler::createDynamicMakeFile()
{
QFile file(mProject->makeFileName());
newMakeFile(file);
writeln(file,"$(BIN): $(LINKOBJ)");
2021-09-13 22:45:50 +08:00
if (!mOnlyCheckSyntax) {
if (mProject->options().isCpp) {
writeln(file, "\t$(CPP) -mdll $(LINKOBJ) -o $(BIN) $(LIBS) -Wl,--output-def,$(DEF),--out-implib,$(STATIC)");
2021-09-13 22:45:50 +08:00
} else {
writeln(file, "\t$(CC) -mdll $(LINKOBJ) -o $(BIN) $(LIBS) -Wl,--output-def,$(DEF),--out-implib,$(STATIC)");
2021-09-13 22:45:50 +08:00
}
}
writeMakeObjFilesRules(file);
}
2021-09-13 10:48:44 +08:00
void ProjectCompiler::newMakeFile(QFile& file)
{
// Create OBJ output directory
if (!mProject->options().objectOutput.isEmpty()) {
QDir(mProject->directory()).mkpath(mProject->options().objectOutput);
}
// Create executable output directory
if (!mProject->options().exeOutput.isEmpty()) {
QDir(mProject->directory()).mkpath(mProject->options().exeOutput);
}
2021-09-13 10:48:44 +08:00
// Write more information to the log file than before
log(tr("Building makefile..."));
log("--------");
log(tr("- Filename: %1").arg(mProject->makeFileName()));
// Create the actual file
if (!file.open(QFile::WriteOnly | QFile::Truncate))
2021-09-13 22:45:50 +08:00
throw CompileError(tr("Can't open '%1' for write!").arg(mProject->makeFileName()));
2021-09-13 10:48:44 +08:00
// Write header
writeMakeHeader(file);
// Writes definition list
writeMakeDefines(file);
// Write PHONY and all targets
writeMakeTarget(file);
// Write list of includes
writeMakeIncludes(file);
// Write clean command
writeMakeClean(file);
// PCH
if (mProject->options().usePrecompiledHeader
&& fileExists(mProject->options().precompiledHeader)) {
writeln(file, "$(PCH) : $(PCH_H)");
writeln(file, "\t$(CPP) -c $(PCH_H) -o $(PCH) $(CXXFLAGS)");
writeln(file);
}
2021-09-13 10:48:44 +08:00
}
void ProjectCompiler::writeMakeHeader(QFile &file)
{
writeln(file,"# Project: " + mProject->name());
2022-01-05 09:08:44 +08:00
writeln(file,QString("# Makefile created by Red Panda C++ ") + REDPANDA_CPP_VERSION);
2021-09-13 10:48:44 +08:00
writeln(file);
if (mOnlyCheckSyntax) {
writeln(file,"# This Makefile is written for syntax check!");
writeln(file,"# Regenerate it if you want to use this Makefile to build.");
writeln(file);
}
}
void ProjectCompiler::writeMakeDefines(QFile &file)
{
// Get list of object files
QString Objects;
QString LinkObjects;
2021-09-17 19:58:37 +08:00
QString cleanObjects;
2021-09-13 10:48:44 +08:00
// Create a list of object files
2022-10-01 08:54:44 +08:00
foreach(const PProjectUnit &unit, mProject->unitList()) {
2021-09-13 10:48:44 +08:00
if (!unit->compile() && !unit->link())
continue;
// Only process source files
QString RelativeName = extractRelativePath(mProject->directory(), unit->fileName());
FileType fileType = getFileType(RelativeName);
if (fileType == FileType::CSource || fileType == FileType::CppSource
|| fileType==FileType::GAS) {
2021-09-13 10:48:44 +08:00
if (!mProject->options().objectOutput.isEmpty()) {
// ofile = C:\MyProgram\obj\main.o
2021-09-17 19:58:37 +08:00
QString fullObjFile = includeTrailingPathDelimiter(mProject->options().objectOutput)
2021-09-13 10:48:44 +08:00
+ extractFileName(unit->fileName());
2021-09-17 19:58:37 +08:00
QString relativeObjFile = extractRelativePath(mProject->directory(), changeFileExt(fullObjFile, OBJ_EXT));
QString objFile = genMakePath2(relativeObjFile);
Objects += ' ' + objFile;
#ifdef Q_OS_WIN
cleanObjects += ' ' + genMakePath1(relativeObjFile).replace("/",QDir::separator());
#else
2021-09-17 19:58:37 +08:00
cleanObjects += ' ' + genMakePath1(relativeObjFile);
#endif
2021-09-17 19:58:37 +08:00
if (unit->link()) {
LinkObjects += ' ' + genMakePath1(relativeObjFile);
}
2021-09-13 10:48:44 +08:00
} else {
2021-09-17 19:58:37 +08:00
Objects += ' ' + genMakePath2(changeFileExt(RelativeName, OBJ_EXT));
#ifdef Q_OS_WIN
cleanObjects += ' ' + genMakePath1(changeFileExt(RelativeName, OBJ_EXT)).replace("/",QDir::separator());
#else
2021-09-17 19:58:37 +08:00
cleanObjects += ' ' + genMakePath1(changeFileExt(RelativeName, OBJ_EXT));
#endif
2021-09-13 10:48:44 +08:00
if (unit->link())
LinkObjects = LinkObjects + ' ' + genMakePath1(changeFileExt(RelativeName, OBJ_EXT));
}
}
}
Objects = Objects.trimmed();
LinkObjects = LinkObjects.trimmed();
// Get windres file
QString objResFile;
QString objResFile2;
QString cleanRes;
#ifdef Q_OS_WIN
2021-09-13 10:48:44 +08:00
if (!mProject->options().privateResource.isEmpty()) {
if (!mProject->options().objectOutput.isEmpty()) {
QString fullResFile = includeTrailingPathDelimiter(mProject->options().objectOutput) +
2021-09-13 10:48:44 +08:00
changeFileExt(mProject->options().privateResource, RES_EXT);
QString relativeResFile = extractRelativePath(mProject->directory(), fullResFile);
objResFile = genMakePath1(relativeResFile);
objResFile2 = genMakePath2(relativeResFile);
cleanRes += ' ' + genMakePath1(changeFileExt(relativeResFile, RES_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, RES_EXT)).replace("/",QDir::separator());
}
}
#endif
2021-09-13 10:48:44 +08:00
// Mention progress in the logs
if (!objResFile.isEmpty()) {
log(tr("- Resource File: %1").arg(generateAbsolutePath(mProject->directory(),objResFile)));
2021-09-13 10:48:44 +08:00
}
log("");
// Get list of applicable flags
QString cCompileArguments = getCCompileArguments(mOnlyCheckSyntax);
2021-09-13 10:48:44 +08:00
QString cppCompileArguments = getCppCompileArguments(mOnlyCheckSyntax);
2021-09-13 19:09:15 +08:00
QString libraryArguments = getLibraryArguments(FileType::Project);
QString cIncludeArguments = getCIncludeArguments() + " " + getProjectIncludeArguments();
QString cppIncludeArguments = getCppIncludeArguments() + " " +getProjectIncludeArguments();
if (cCompileArguments.indexOf(" -g3")>=0
|| cCompileArguments.startsWith("-g3")) {
cCompileArguments += " -D__DEBUG__";
cppCompileArguments+= " -D__DEBUG__";
}
2021-09-13 22:45:50 +08:00
writeln(file,"CPP = " + extractFileName(compilerSet()->cppCompiler()));
writeln(file,"CC = " + extractFileName(compilerSet()->CCompiler()));
#ifdef Q_OS_WIN
2021-09-13 22:45:50 +08:00
writeln(file,"WINDRES = " + extractFileName(compilerSet()->resourceCompiler()));
#endif
if (!objResFile.isEmpty()) {
writeln(file,"RES = " + objResFile2);
2021-09-13 19:09:15 +08:00
writeln(file,"OBJ = " + Objects + " $(RES)");
writeln(file,"LINKOBJ = " + LinkObjects + " " + objResFile);
#ifdef Q_OS_WIN
writeln(file,"CLEANOBJ = " + cleanObjects +
" " + cleanRes
+ " " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->executable())).replace("/",QDir::separator()) );
#else
writeln(file,"CLEANOBJ = " + cleanObjects +
" " + cleanRes
+ " " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->executable())));
#endif
2021-09-13 19:09:15 +08:00
} else {
writeln(file,"OBJ = " + Objects);
writeln(file,"LINKOBJ = " + LinkObjects);
#ifdef Q_OS_WIN
writeln(file,"CLEANOBJ = " + cleanObjects +
+ " " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->executable())).replace("/",QDir::separator()) );
#else
writeln(file,"CLEANOBJ = " + cleanObjects +
+ " " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->executable())));
#endif
2021-09-13 19:09:15 +08:00
};
libraryArguments.replace('\\', '/');
writeln(file,"LIBS = " + libraryArguments);
cIncludeArguments.replace('\\', '/');
writeln(file,"INCS = " + cIncludeArguments);
cppIncludeArguments.replace('\\', '/');
writeln(file,"CXXINCS = " + cppIncludeArguments);
writeln(file,"BIN = " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->executable())));
cppCompileArguments.replace('\\', '/');
writeln(file,"CXXFLAGS = $(CXXINCS) " + cppCompileArguments);
//writeln(file,"ENCODINGS = -finput-charset=utf-8 -fexec-charset='+GetSystemCharsetName);
cCompileArguments.replace('\\', '/');
writeln(file,"CFLAGS = $(INCS) " + cCompileArguments);
writeln(file, QString("RM = ") + CLEAN_PROGRAM );
if (mProject->options().usePrecompiledHeader
&& fileExists(mProject->options().precompiledHeader)){
writeln(file,"PCH_H = " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->options().precompiledHeader )));
writeln(file,"PCH = " + genMakePath1(extractRelativePath(mProject->makeFileName(), mProject->options().precompiledHeader+"."+GCH_EXT)));
2021-09-13 19:09:15 +08:00
}
#ifdef Q_OS_WIN
writeln(file,"WINDRESFLAGS = " + mProject->options().resourceCmd);
#endif
2021-09-13 10:48:44 +08:00
// This needs to be put in before the clean command.
2021-09-13 19:09:15 +08:00
if (mProject->options().type == ProjectType::DynamicLib) {
QString outputFileDir = extractFilePath(mProject->executable());
QString outputFilename = extractFileName(mProject->executable());
QString libOutputFile;
if (!outputFilename.startsWith("lib")) {
libOutputFile = includeTrailingPathDelimiter(outputFileDir) + "lib" + outputFilename;
} else {
libOutputFile = includeTrailingPathDelimiter(outputFileDir) + outputFilename;
}
2021-09-13 19:09:15 +08:00
if (QFileInfo(libOutputFile).absoluteFilePath()
== mProject->directory())
libOutputFile = extractFileName(libOutputFile);
else
libOutputFile = extractRelativePath(mProject->makeFileName(), libOutputFile);
writeln(file,"DEF = " + genMakePath1(changeFileExt(libOutputFile, DEF_EXT)));
writeln(file,"STATIC = " + genMakePath1(changeFileExt(libOutputFile, LIB_EXT)));
#ifdef Q_OS_WIN
writeln(file,"CLEAN_DEF = " + genMakePath1(changeFileExt(libOutputFile, DEF_EXT)).replace("/",QDir::separator()));
writeln(file,"CLEAN_STATIC = " + genMakePath1(changeFileExt(libOutputFile, LIB_EXT)).replace("/",QDir::separator()));
#else
writeln(file,"CLEAN_DEF = " + genMakePath1(changeFileExt(libOutputFile, DEF_EXT)));
writeln(file,"CLEAN_STATIC = " + genMakePath1(changeFileExt(libOutputFile, LIB_EXT)));
#endif
2021-09-13 19:09:15 +08:00
}
writeln(file);
2021-09-13 10:48:44 +08:00
}
2021-09-13 22:45:50 +08:00
void ProjectCompiler::writeMakeTarget(QFile &file)
{
if (mOnlyCheckSyntax)
writeln(file, ".PHONY: all all-before all-after clean clean-custom $(OBJ) $(BIN)");
else
writeln(file, ".PHONY: all all-before all-after clean clean-custom");
writeln(file);
writeln(file, "all: all-before $(BIN) all-after");
writeln(file);
2021-09-13 22:45:50 +08:00
}
void ProjectCompiler::writeMakeIncludes(QFile &file)
{
foreach(const QString& s, mProject->options().makeIncludes) {
writeln(file, "include " + genMakePath1(s));
}
if (!mProject->options().makeIncludes.isEmpty()) {
writeln(file);
}
}
void ProjectCompiler::writeMakeClean(QFile &file)
{
writeln(file, "clean: clean-custom");
QString target="$(CLEANOBJ)";
if (mProject->options().usePrecompiledHeader
&& fileExists(mProject->options().precompiledHeader)) {
target += " $(PCH)";
}
if (mProject->options().type == ProjectType::DynamicLib) {
target +=" $(CLEAN_DEF) $(CLEAN_STATIC)";
}
writeln(file, QString("\t-$(RM) %1 > %2 2>&1").arg(target,NULL_FILE));
2021-09-13 22:45:50 +08:00
writeln(file);
}
void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
{
PCppParser parser = mProject->cppParser();
QString precompileStr;
QList<PProjectUnit> projectUnits=mProject->unitList();
2022-10-01 08:54:44 +08:00
foreach(const PProjectUnit &unit, projectUnits) {
if (!unit->compile())
continue;
2021-09-13 22:45:50 +08:00
FileType fileType = getFileType(unit->fileName());
// Only process source files
if (fileType!=FileType::CSource && fileType!=FileType::CppSource
&& fileType!=FileType::GAS)
2021-09-13 22:45:50 +08:00
continue;
QString shortFileName = extractRelativePath(mProject->makeFileName(),unit->fileName());
writeln(file);
QString objStr=genMakePath2(shortFileName);
// if we have scanned it, use scanned info
if (parser && parser->scannedFiles().contains(unit->fileName())) {
QSet<QString> fileIncludes = parser->getFileIncludes(unit->fileName());
foreach(const PProjectUnit &unit2, projectUnits) {
if (unit2==unit)
2021-09-13 22:45:50 +08:00
continue;
if (fileIncludes.contains(unit2->fileName())) {
if (mProject->options().usePrecompiledHeader &&
unit2->fileName() == mProject->options().precompiledHeader)
precompileStr = " $(PCH) ";
else
objStr = objStr + ' ' + genMakePath2(extractRelativePath(mProject->makeFileName(),unit2->fileName()));
2021-09-13 22:45:50 +08:00
}
}
} else {
2022-10-01 08:54:44 +08:00
foreach(const PProjectUnit &unit2, projectUnits) {
FileType fileType = getFileType(unit2->fileName());
2021-09-13 22:45:50 +08:00
if (fileType == FileType::CHeader || fileType==FileType::CppHeader)
2022-10-01 08:54:44 +08:00
objStr = objStr + ' ' + genMakePath2(extractRelativePath(mProject->makeFileName(),unit2->fileName()));
2021-09-13 22:45:50 +08:00
}
}
QString objFileName;
QString objFileName2;
2021-09-13 22:45:50 +08:00
if (!mProject->options().objectOutput.isEmpty()) {
QString fullObjname = includeTrailingPathDelimiter(mProject->options().objectOutput) +
2021-09-13 22:45:50 +08:00
extractFileName(unit->fileName());
objFileName = genMakePath2(extractRelativePath(mProject->makeFileName(), changeFileExt(fullObjname, OBJ_EXT)));
objFileName2 = genMakePath1(extractRelativePath(mProject->makeFileName(), changeFileExt(fullObjname, OBJ_EXT)));
// if (!extractFileDir(ObjFileName).isEmpty()) {
// objStr = genMakePath2(includeTrailingPathDelimiter(extractFileDir(ObjFileName))) + objStr;
// }
2021-09-13 22:45:50 +08:00
} else {
objFileName = genMakePath2(changeFileExt(shortFileName, OBJ_EXT));
objFileName2 = genMakePath1(changeFileExt(shortFileName, OBJ_EXT));
2021-09-13 22:45:50 +08:00
}
objStr = objFileName + ": "+objStr+precompileStr;
2021-09-13 22:45:50 +08:00
writeln(file,objStr);
// Write custom build command
if (unit->overrideBuildCmd() && !unit->buildCmd().isEmpty()) {
QString BuildCmd = unit->buildCmd();
BuildCmd.replace("<CRTAB>", "\n\t");
writeln(file, '\t' + BuildCmd);
// Or roll our own
} else {
QString encodingStr;
if (compilerSet()->compilerType() != CompilerType::Clang && mProject->options().addCharset) {
QByteArray defaultSystemEncoding=pCharsetInfoManager->getDefaultSystemEncoding();
QByteArray encoding = mProject->options().execEncoding;
QByteArray targetEncoding;
QByteArray sourceEncoding;
if ( encoding == ENCODING_SYSTEM_DEFAULT || encoding.isEmpty()) {
targetEncoding = defaultSystemEncoding;
} else if (encoding == ENCODING_UTF8_BOM) {
targetEncoding = "UTF-8";
} else if (encoding == ENCODING_UTF16_BOM) {
targetEncoding = "UTF-16";
} else if (encoding == ENCODING_UTF32_BOM) {
targetEncoding = "UTF-32";
} else {
targetEncoding = encoding;
}
if (unit->realEncoding().isEmpty()) {
if (unit->encoding() == ENCODING_AUTO_DETECT) {
Editor* editor = mProject->unitEditor(unit);
if (editor && editor->fileEncoding()!=ENCODING_ASCII
&& editor->fileEncoding()!=targetEncoding) {
sourceEncoding = editor->fileEncoding();
} else {
sourceEncoding = targetEncoding;
}
2023-01-24 11:31:30 +08:00
} else if (unit->encoding()==ENCODING_PROJECT) {
sourceEncoding=mProject->options().encoding;
} else if (unit->encoding()==ENCODING_SYSTEM_DEFAULT) {
sourceEncoding = defaultSystemEncoding;
} else if (unit->encoding()!=ENCODING_ASCII && !unit->encoding().isEmpty()) {
sourceEncoding = unit->encoding();
} else {
sourceEncoding = targetEncoding;
}
} else if (unit->realEncoding()==ENCODING_ASCII) {
sourceEncoding = targetEncoding;
} else {
sourceEncoding = unit->realEncoding();
}
if (sourceEncoding!=targetEncoding) {
encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2")
.arg(QString(sourceEncoding),
QString(targetEncoding));
2021-09-13 22:45:50 +08:00
}
}
if (fileType==FileType::CppSource || fileType==FileType::CppSource) {
if (mOnlyCheckSyntax) {
if (unit->compileCpp())
writeln(file, "\t$(CPP) -c " + genMakePath1(shortFileName) + " $(CXXFLAGS) " + encodingStr);
else
writeln(file, "\t(CC) -c " + genMakePath1(shortFileName) + " $(CFLAGS) " + encodingStr);
} else {
if (unit->compileCpp())
writeln(file, "\t$(CPP) -c " + genMakePath1(shortFileName) + " -o " + objFileName2 + " $(CXXFLAGS) " + encodingStr);
else
writeln(file, "\t$(CC) -c " + genMakePath1(shortFileName) + " -o " + objFileName2 + " $(CFLAGS) " + encodingStr);
}
} else if (fileType==FileType::GAS) {
if (!mOnlyCheckSyntax) {
writeln(file, "\t$(CC) -c " + genMakePath1(shortFileName) + " -o " + objFileName2 + " $(CFLAGS) " + encodingStr);
}
2021-09-13 22:45:50 +08:00
}
}
}
#ifdef Q_OS_WIN
2021-09-13 22:45:50 +08:00
if (!mProject->options().privateResource.isEmpty()) {
// Concatenate all resource include directories
QString ResIncludes(" ");
for (int i=0;i<mProject->options().resourceIncludes.count();i++) {
QString filename = mProject->options().resourceIncludes[i];
if (!filename.isEmpty())
ResIncludes = ResIncludes + " --include-dir " + genMakePath1(filename);
}
QString resFiles;
2021-09-13 22:45:50 +08:00
// Concatenate all resource filenames (not created when syntax checking)
if (!mOnlyCheckSyntax) {
2022-10-01 08:54:44 +08:00
foreach(const PProjectUnit& unit, mProject->unitList()) {
2021-09-13 22:45:50 +08:00
if (getFileType(unit->fileName())!=FileType::WindowsResourceSource)
continue;
if (fileExists(unit->fileName())) {
2021-09-13 22:45:50 +08:00
QString ResFile = extractRelativePath(mProject->makeFileName(), unit->fileName());
resFiles = resFiles + genMakePath2(ResFile) + ' ';
2021-09-13 22:45:50 +08:00
}
}
resFiles = resFiles.trimmed();
2021-09-13 22:45:50 +08:00
}
// Determine resource output file
QString fullName;
2021-09-13 22:45:50 +08:00
if (!mProject->options().objectOutput.isEmpty()) {
fullName = includeTrailingPathDelimiter(mProject->options().objectOutput) +
2021-09-13 22:45:50 +08:00
changeFileExt(mProject->options().privateResource, RES_EXT);
} else {
fullName = changeFileExt(mProject->options().privateResource, RES_EXT);
2021-09-13 22:45:50 +08:00
}
QString objFileName = genMakePath1(extractRelativePath(mProject->filename(), fullName));
QString objFileName2 = genMakePath2(extractRelativePath(mProject->filename(), fullName));
QString privResName = genMakePath1(extractRelativePath(mProject->filename(), mProject->options().privateResource));
QString privResName2 = genMakePath2(extractRelativePath(mProject->filename(), mProject->options().privateResource));
2021-09-13 22:45:50 +08:00
// Build final cmd
QString windresArgs;
if (mProject->getCompileOption(CC_CMD_OPT_POINTER_SIZE)=="32")
windresArgs = " -F pe-i386";
2021-09-13 22:45:50 +08:00
if (mOnlyCheckSyntax) {
writeln(file);
writeln(file, objFileName2 + ':');
writeln(file, "\t$(WINDRES) -i " + privResName + windresArgs + " --input-format=rc -o nul -O coff $(WINDRESFLAGS)" + ResIncludes);
2021-09-13 22:45:50 +08:00
} else {
writeln(file);
writeln(file, objFileName2 + ": " + privResName2 + ' ' + resFiles);
writeln(file, "\t$(WINDRES) -i " + privResName + windresArgs + " --input-format=rc -o " + objFileName + " -O coff $(WINDRESFLAGS)"
2021-09-13 22:45:50 +08:00
+ ResIncludes);
}
writeln(file);
}
#endif
2021-09-13 22:45:50 +08:00
}
2021-09-13 10:48:44 +08:00
void ProjectCompiler::writeln(QFile &file, const QString &s)
{
if (!s.isEmpty())
file.write(s.toLocal8Bit());
file.write("\n");
}
bool ProjectCompiler::onlyClean() const
{
return mOnlyClean;
}
void ProjectCompiler::setOnlyClean(bool newOnlyClean)
{
mOnlyClean = newOnlyClean;
}
2021-09-13 10:48:44 +08:00
bool ProjectCompiler::prepareForRebuild()
{
//we use make argument to clean
return true;
}
2021-09-13 07:49:36 +08:00
bool ProjectCompiler::prepareForCompile()
{
if (!mProject)
return false;
//initProgressForm();
log(tr("Compiling project changes..."));
log("--------");
log(tr("- Project Filename: %1").arg(mProject->filename()));
log(tr("- Compiler Set Name: %1").arg(compilerSet()->name()));
log("");
buildMakeFile();
2021-09-13 10:48:44 +08:00
mCompiler = compilerSet()->make();
if (!fileExists(mCompiler)) {
throw CompileError(
tr("Make program '%1' doesn't exists!").arg(mCompiler)
+"<br />"
+tr("Please check the \"program\" page of compiler settings."));
}
QString parallelParam;
if (mProject->options().allowParallelBuilding) {
if (mProject->options().parellelBuildingJobs==0) {
parallelParam = " --jobs";
} else {
parallelParam = QString(" -j%1").arg(mProject->options().parellelBuildingJobs);
}
}
if (mOnlyClean) {
mArguments = QString(" %1 -f \"%2\" clean").arg(parallelParam,
extractRelativePath(
mProject->directory(),
mProject->makeFileName()));
} else if (mRebuild) {
mArguments = QString(" -f \"%1\" clean").arg(extractRelativePath(
2021-09-13 22:45:50 +08:00
mProject->directory(),
mProject->makeFileName()));
mExtraCompilersList.append(mCompiler);
mExtraArgumentsList.append(QString(" %1 -f \"%2\" all").arg(parallelParam,
extractRelativePath(
mProject->directory(),
mProject->makeFileName())));
2021-09-13 10:48:44 +08:00
} else {
mArguments = QString(" %1 -f \"%2\" all").arg(parallelParam,
extractRelativePath(
2021-09-13 22:45:50 +08:00
mProject->directory(),
mProject->makeFileName()));
2021-09-13 10:48:44 +08:00
}
2021-09-13 22:45:50 +08:00
mDirectory = mProject->directory();
log(tr("Processing makefile:"));
log("--------");
log(tr("- makefile processer: %1").arg(mCompiler));
log(tr("- Command: %1 %2").arg(extractFileName(mCompiler)).arg(mArguments));
for(int i=0;i<mExtraCompilersList.count();i++) {
log(tr("- Command: %1 %2").arg(extractFileName(mExtraCompilersList[i])).arg(mExtraArgumentsList[i]));
}
2021-09-13 22:45:50 +08:00
log("");
return true;
2021-09-13 07:49:36 +08:00
}