- done: view makefile

This commit is contained in:
royqh1979 2021-09-17 19:58:37 +08:00
parent c920a98d85
commit 78ea33d152
10 changed files with 81 additions and 22 deletions

View File

@ -88,6 +88,25 @@ void CompilerManager::compileProject(std::shared_ptr<Project> project, bool rebu
}
}
void CompilerManager::buildProjectMakefile(std::shared_ptr<Project> project)
{
if (!pSettings->compilerSets().defaultSet()) {
QMessageBox::critical(pMainWindow,
tr("No compiler set"),
tr("No compiler set is configured.")+tr("Can't start debugging."));
return;
}
{
QMutexLocker locker(&mCompileMutex);
if (mCompiler!=nullptr) {
return;
}
ProjectCompiler compiler(project,false,false);
compiler.buildMakeFile();
}
}
void CompilerManager::checkSyntax(const QString &filename, const QString &content, bool isAscii, std::shared_ptr<Project> project)
{
if (!pSettings->compilerSets().defaultSet()) {

View File

@ -21,6 +21,7 @@ public:
void compile(const QString& filename, const QByteArray& encoding, bool rebuild, bool silent=false,bool onlyCheckSyntax=false);
void compileProject(std::shared_ptr<Project> project, bool rebuild, bool silent=false,bool onlyCheckSyntax=false);
void buildProjectMakefile(std::shared_ptr<Project> project);
void checkSyntax(const QString&filename, const QString& content, bool isAscii, std::shared_ptr<Project> project);
void run(const QString& filename, const QString& arguments, const QString& workDir);
void stopRun();

View File

@ -121,6 +121,7 @@ void ProjectCompiler::writeMakeDefines(QFile &file)
// Get list of object files
QString Objects;
QString LinkObjects;
QString cleanObjects;
// Create a list of object files
for (int i=0;i<mProject->units().count();i++) {
@ -134,15 +135,19 @@ void ProjectCompiler::writeMakeDefines(QFile &file)
if (fileType == FileType::CSource || fileType == FileType::CppSource) {
if (!mProject->options().objectOutput.isEmpty()) {
// ofile = C:\MyProgram\obj\main.o
QString ObjFile = includeTrailingPathDelimiter(mProject->options().objectOutput)
QString fullObjFile = includeTrailingPathDelimiter(mProject->options().objectOutput)
+ extractFileName(unit->fileName());
ObjFile = genMakePath1(extractRelativePath(mProject->directory(), changeFileExt(ObjFile, OBJ_EXT)));
QString relativeObjFile = extractRelativePath(mProject->directory(), changeFileExt(fullObjFile, OBJ_EXT));
QString ObjFile = genMakePath2(relativeObjFile);
Objects += ' ' + ObjFile;
if (unit->link())
LinkObjects += ' ' + ObjFile;
cleanObjects += ' ' + genMakePath1(relativeObjFile);
if (unit->link()) {
LinkObjects += ' ' + genMakePath1(relativeObjFile);
}
} else {
Objects += ' ' + genMakePath1(changeFileExt(RelativeName, OBJ_EXT));
Objects += ' ' + genMakePath2(changeFileExt(RelativeName, OBJ_EXT));
cleanObjects += ' ' + genMakePath1(changeFileExt(RelativeName, OBJ_EXT));
if (unit->link())
LinkObjects = LinkObjects + ' ' + genMakePath1(changeFileExt(RelativeName, OBJ_EXT));
}
@ -187,9 +192,11 @@ void ProjectCompiler::writeMakeDefines(QFile &file)
writeln(file,"RES = " + genMakePath1(ObjResFile));
writeln(file,"OBJ = " + Objects + " $(RES)");
writeln(file,"LINKOBJ = " + LinkObjects + " $(RES)");
writeln(file,"CLEANOBJ = " + cleanObjects + " $(RES)");
} else {
writeln(file,"OBJ = " + Objects);
writeln(file,"LINKOBJ = " + LinkObjects);
writeln(file,"CLEANOBJ = " + cleanObjects);
};
libraryArguments.replace('\\', '/');
writeln(file,"LIBS = " + libraryArguments);
@ -256,9 +263,9 @@ void ProjectCompiler::writeMakeClean(QFile &file)
{
writeln(file, "clean: clean-custom");
if (mProject->options().type == ProjectType::DynamicLib)
writeln(file, "\t${RM} $(OBJ) $(BIN) $(DEF) $(STATIC)");
writeln(file, "\t${RM} $(CLEANOBJ) $(BIN) $(DEF) $(STATIC)");
else
writeln(file, "\t${RM} $(OBJ) $(BIN)");
writeln(file, "\t${RM} $(CLEANOBJ) $(BIN)");
writeln(file);
}
@ -299,15 +306,18 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
}
}
QString ObjFileName;
QString ObjFileName2;
if (!mProject->options().objectOutput.isEmpty()) {
ObjFileName = includeTrailingPathDelimiter(mProject->options().objectOutput) +
extractFileName(unit->fileName());
ObjFileName = genMakePath1(extractRelativePath(mProject->makeFileName(), changeFileExt(ObjFileName, OBJ_EXT)));
ObjFileName = genMakePath2(extractRelativePath(mProject->makeFileName(), changeFileExt(ObjFileName, OBJ_EXT)));
ObjFileName2 = genMakePath1(extractRelativePath(mProject->makeFileName(), changeFileExt(ObjFileName, OBJ_EXT)));
if (!extractFileDir(ObjFileName).isEmpty()) {
objStr = genMakePath2(includeTrailingPathDelimiter(extractFileDir(ObjFileName))) + objStr;
}
} else {
ObjFileName = genMakePath1(changeFileExt(shortFileName, OBJ_EXT));
ObjFileName = genMakePath2(changeFileExt(shortFileName, OBJ_EXT));
ObjFileName2 = genMakePath1(changeFileExt(shortFileName, OBJ_EXT));
}
objStr = ObjFileName + ": "+objStr+precompileStr;
@ -343,9 +353,9 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
writeln(file, "\t(CC) -c " + genMakePath1(shortFileName) + " $(CFLAGS) " + encodingStr);
} else {
if (unit->compileCpp())
writeln(file, "\t$(CPP) -c " + genMakePath1(shortFileName) + " -o " + ObjFileName + " $(CXXFLAGS) " + encodingStr);
writeln(file, "\t$(CPP) -c " + genMakePath1(shortFileName) + " -o " + ObjFileName2 + " $(CXXFLAGS) " + encodingStr);
else
writeln(file, "\t$(CC) -c " + genMakePath1(shortFileName) + " -o " + ObjFileName + " $(CFLAGS) " + encodingStr);
writeln(file, "\t$(CC) -c " + genMakePath1(shortFileName) + " -o " + ObjFileName2 + " $(CFLAGS) " + encodingStr);
}
}
}

View File

@ -10,9 +10,9 @@ class ProjectCompiler : public Compiler
Q_OBJECT
public:
ProjectCompiler(std::shared_ptr<Project> project, bool silent,bool onlyCheckSyntax);
void buildMakeFile();
private:
void buildMakeFile();
void createStandardMakeFile();
void createStaticMakeFile();
void createDynamicMakeFile();

View File

@ -3,7 +3,6 @@
#include <QMessageBox>
#include <QVariant>
#include <mainwindow.h>
#include <QDebug>
#include <QFileInfo>
#include "settings.h"
#include "project.h"
@ -322,8 +321,6 @@ void EditorList::getVisibleEditors(Editor *&left, Editor *&right)
void EditorList::updateLayout()
{
qDebug()<<mLeftPageWidget->count();
qDebug()<<mRightPageWidget->count();
if (mLeftPageWidget->count() ==0 && mRightPageWidget->count() == 0)
showLayout(LayoutShowType::lstNone);
else if (mLeftPageWidget->count() > 0 && mRightPageWidget->count() == 0)

View File

@ -1463,7 +1463,7 @@ void MainWindow::openShell(const QString &folder, const QString &shellCommand)
}
pathAdded.append(pSettings->dirs().app());
if (!path.isEmpty()) {
path+= PATH_SEPARATOR + pathAdded.join(PATH_SEPARATOR);
path= pathAdded.join(PATH_SEPARATOR) + PATH_SEPARATOR + path;
} else {
path = pathAdded.join(PATH_SEPARATOR);
}
@ -1926,6 +1926,7 @@ void MainWindow::onCompilerSetChanged(int index)
void MainWindow::onCompileLog(const QString &msg)
{
ui->txtCompilerOutput->appendPlainText(msg);
ui->txtCompilerOutput->ensureCursorVisible();
}
void MainWindow::onCompileIssue(PCompileIssue issue)
@ -3061,7 +3062,7 @@ void MainWindow::on_actionRemove_from_project_triggered()
continue;
FolderNode * node = static_cast<FolderNode*>(index.internalPointer());
PFolderNode folderNode = mProject->pointerToNode(node);
if (folderNode)
if (!folderNode)
continue;
selected.insert(folderNode->unitIndex);
};
@ -3075,3 +3076,23 @@ void MainWindow::on_actionRemove_from_project_triggered()
updateProjectView();
}
void MainWindow::on_actionView_Makefile_triggered()
{
if (!mProject)
return;
if (!mProject->saveUnits())
return;
// Check if saves have been succesful
for (int i=0; i<mEditorList->pageCount();i++) {
Editor * e= (*(mEditorList))[i];
if (e->inProject() && e->modified())
return;
}
mProject->buildPrivateResource();
mCompilerManager->buildProjectMakefile(mProject);
openFile(mProject->makeFileName());
}

View File

@ -320,6 +320,8 @@ private slots:
void on_actionRemove_from_project_triggered();
void on_actionView_Makefile_triggered();
private:
Ui::MainWindow *ui;
EditorList *mEditorList;

View File

@ -110,7 +110,10 @@
<item>
<widget class="QTreeView" name="projectView">
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="headerVisible">
<bool>false</bool>
@ -279,7 +282,7 @@
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>3</number>
<number>1</number>
</property>
<widget class="QWidget" name="tabIssues">
<attribute name="icon">

View File

@ -581,11 +581,17 @@ void Project::updateNodeIndexes()
mUnits[idx]->node()->unitIndex = idx;
}
PFolderNode Project::pointerToNode(FolderNode *p)
PFolderNode Project::pointerToNode(FolderNode *p, PFolderNode parent)
{
foreach (const PFolderNode& node , mFolderNodes) {
if (!parent) {
parent = mNode;
}
foreach (const PFolderNode& node , parent->children) {
if (node.get()==p)
return node;
PFolderNode result = pointerToNode(p,node);
if (result)
return result;
}
return PFolderNode();
}

View File

@ -151,7 +151,7 @@ public:
void sortUnitsByAlpha();
void updateFolders();
void updateNodeIndexes();
PFolderNode pointerToNode(FolderNode * p);
PFolderNode pointerToNode(FolderNode * p, PFolderNode parent=PFolderNode());
//void showOptions();
bool assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate);