Patch #2558 2008-09-06 23:33

gryphon

Can specify the execution directory for a custom makefile
Download
2558-Can_specify_th.patch (17.5 KB)
Category
Application::Refinement
Status
Accepted
Close date
2009-04-02 22:16
Assigned to
jenslody
Index: src/sdk/cbproject.cpp
===================================================================
--- src/sdk/cbproject.cpp    (revision 5201)
+++ src/sdk/cbproject.cpp    (working copy)
@@ -1550,6 +1550,25 @@
     return m_Makefile;
 }
 
+void cbProject::SetMakefileExecutionDir(const wxString& dir)
+{
+    if (m_MakefileExecutionDir != dir)
+    {
+        m_MakefileExecutionDir = dir;
+        SetModified(true);
+    }
+}
+
+const wxString& cbProject::GetMakefileExecutionDir() const
+{
+    if (!m_MakefileExecutionDir.IsEmpty())
+        return m_MakefileExecutionDir;
+
+    wxFileName makefile_execution_dir(GetBasePath());
+    m_MakefileExecutionDir = makefile_execution_dir.GetFullPath();
+    return m_MakefileExecutionDir;
+}
+
 ProjectFile* cbProject::GetFile(int index)
 {
     FilesList::Node* node = m_Files.Item(index);
Index: src/sdk/projectoptionsdlg.cpp
===================================================================
--- src/sdk/projectoptionsdlg.cpp    (revision 5201)
+++ src/sdk/projectoptionsdlg.cpp    (working copy)
@@ -68,6 +68,7 @@
     EVT_BUTTON(    XRCID("btnBrowseOutputFilename"),   ProjectOptionsDlg::OnBrowseOutputFilenameClick)
     EVT_BUTTON(    XRCID("btnBrowseWorkingDir"),       ProjectOptionsDlg::OnBrowseDirClick)
     EVT_BUTTON(    XRCID("btnBrowseObjectDir"),        ProjectOptionsDlg::OnBrowseDirClick)
+    EVT_BUTTON(    XRCID("btnMakefileExecutionDir"),   ProjectOptionsDlg::OnBrowseDirClick)
     EVT_BUTTON(    XRCID("btnVirtualBuildTargets"),    ProjectOptionsDlg::OnVirtualTargets)
     EVT_BUTTON(    XRCID("btnExternalDeps"),           ProjectOptionsDlg::OnEditDepsClick)
     EVT_BUTTON(    XRCID("btnExportTarget"),           ProjectOptionsDlg::OnExportTargetClick)
@@ -110,6 +111,7 @@
     XRCCTRL(*this, "txtPlatformProj", wxTextCtrl)->SetValue(GetStringFromPlatforms(m_Project->GetPlatforms()));
     XRCCTRL(*this, "txtProjectMakefile", wxTextCtrl)->SetValue(m_Project->GetMakefile());
     XRCCTRL(*this, "chkCustomMakefile", wxCheckBox)->SetValue(m_Project->IsMakefileCustom());
+    XRCCTRL(*this, "txtMakefileExecutionDir", wxTextCtrl)->SetValue(m_Project->GetMakefileExecutionDir());
     XRCCTRL(*this, "rbPCHStrategy", wxRadioBox)->SetSelection((int)m_Project->GetModeForPCH());
 
     Compiler* compiler = CompilerFactory::GetCompiler(project->GetCompilerID());
@@ -687,6 +689,8 @@
         targettext = XRCCTRL(*this, "txtWorkingDir", wxTextCtrl);
     else if (event.GetId() == XRCID("btnBrowseObjectDir"))
         targettext = XRCCTRL(*this, "txtObjectDir", wxTextCtrl);
+    else if (event.GetId() == XRCID("btnMakefileExecutionDir"))
+        targettext = XRCCTRL(*this, "txtMakefileExecutionDir", wxTextCtrl);
     else
         return;
 
@@ -1021,6 +1025,10 @@
     XRCCTRL(*this, "btnToggleCheckmarks", wxButton)->Enable(!customMake && en);
     list->Enable(!customMake);
 
+    // enable some stuff if using a custom makefile
+    XRCCTRL(*this, "txtMakefileExecutionDir", wxTextCtrl)->Enable(customMake);
+    XRCCTRL(*this, "btnMakefileExecutionDir", wxTextCtrl)->Enable(customMake);
+
     // scripts page
     wxTreeCtrl* tc = XRCCTRL(*this, "tcOverview", wxTreeCtrl);
     tc->Enable(!customMake);
@@ -1055,6 +1063,7 @@
         m_Project->RenameInTree(m_Project->GetTitle());
         m_Project->SetMakefile(XRCCTRL(*this, "txtProjectMakefile", wxTextCtrl)->GetValue());
         m_Project->SetMakefileCustom(XRCCTRL(*this, "chkCustomMakefile", wxCheckBox)->GetValue());
+        m_Project->SetMakefileExecutionDir(XRCCTRL(*this, "txtMakefileExecutionDir", wxTextCtrl)->GetValue());
         m_Project->SetTargetType(TargetType(XRCCTRL(*this, "cmbProjectType", wxComboBox)->GetSelection()));
         m_Project->SetModeForPCH((PCHMode)XRCCTRL(*this, "rbPCHStrategy", wxRadioBox)->GetSelection());
         m_Project->SetExtendedObjectNamesGeneration(XRCCTRL(*this, "chkExtendedObjNames", wxCheckBox)->GetValue());
Index: src/sdk/projectloader.cpp
===================================================================
--- src/sdk/projectloader.cpp    (revision 5201)
+++ src/sdk/projectloader.cpp    (working copy)
@@ -377,6 +377,7 @@
     wxString title;
     wxString makefile;
     bool makefile_custom = false;
+    wxString makefile_execution_dir;
     wxString defaultTarget;
     wxString compilerId = _T("gcc");
     bool extendedObjectNames = false;
@@ -405,6 +406,9 @@
         else if (node->Attribute("makefile_is_custom"))
             makefile_custom = strncmp(node->Attribute("makefile_is_custom"), "1", 1) == 0;
 
+        else if (node->Attribute("makefile_execution_dir"))
+            makefile_execution_dir = cbC2U(node->Attribute("makefile_execution_dir"));
+
         // old default_target (int) node
         else if (node->QueryIntAttribute("default_target", &m_1_4_to_1_5_deftarget) == TIXML_SUCCESS)
         {
@@ -442,6 +446,7 @@
     m_pProject->SetPlatforms(platformsFinal);
     m_pProject->SetMakefile(makefile);
     m_pProject->SetMakefileCustom(makefile_custom);
+    m_pProj
download for full patch...
gryphon 2008-09-06 23:46

For some projects that make use of a custom makefile it is required that the execution directory of the makefile be specified. Paths within the makefile are relative to this execution directory and so will not be found.

For example given the following locations:

base/build/aaaa/source/sub_source/file.cpp

base/build/aaaa/source/Makefile

base/cbs/project/project.cbp

The makefile references files as:

./source/sub_source/file.cpp

The patch basically allows specification of an execution directory for the makefile other than the default of:

base/cbs/project/

In this case the required execution working directory would be:

../../build/aaaa

The patch then attempts to perform two things:

1. It sets the correct directory for the piped process that runs make to the execution directory specified.

2. It changes the logged compile error and warning file paths into valid paths by combining the makefile execution directory and the invalid relative path taken from the makefile. This ensures that clicking on such error and warning messages results in the correct line in the correct file being focused as usual.

gryphon 2008-09-07 15:16

Uploading a revised version of the patch that provides two important changes:

1. Custom Makefile commands are now inherited from the project if they are not present in the target.

2. Codeblocks variables now get replaced inside the makefile commands.

These changes allow a project to define a 'master' makefile command with variables and have targets specify values for those variables and hence allow a high degree of flexibility when forced to use a custom makefile.

jenslody 2009-04-02 22:16

The patch is added to trunk in slightly modified form (svn r5497)

Thanks for your effort,

Jens