News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Minor error with makefile

Started by Triniti, July 22, 2014, 12:54:52 AM

Previous topic - Next topic

Triniti

Hello,
It is not relevant for many people, but there is something unexpected.
The  "Compile single file" with makefile does not work.
To repreat the bug you have to create a HelloWorld project and apply this makefile.

main.o: main.c
mingw32-gcc.exe -Wall -O2  -c main.c -o main.o

HelloWorld.exe: main.o
mingw32-g++.exe  -o HelloWorld.exe main.o  -s

Then right click on file (main.c) to build this file. Codeblocks does not run makefile but run default compiler settings.

I discovered it when I was trying to implement another compiler in codeblocks. I am using codeblocks with PowerPC EABI compiler. I hope to share my compiller settings in the future, when I finished it.

Alex

Same here.

I installed CB 13.12 yesterday after using 10.05 for years. Today I was trying to find out what might be wrong. It caused me a headache.

I don't think it is only relevant to a few people. It's a very annoying bug which I hope gets fixed as soon as possible.

Fortunately I found 10.05 and installed it again. I will continue to use it.

oBFusCATed

What command do you expect to get executed?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Alex

Quote from: oBFusCATed on July 28, 2014, 10:00:21 AM
What command do you expect to get executed?

That what is set at
Project's build options -> <selected target> -> "Make" commands -> Compile single file

I've usually filled this field with: $make -f $makefile $(ACTIVE_EDITOR_STEM).o to overcome some limitations of CB10.05.

In CB13.12 whatever is in the field it is ignored. Instead this is executed: "g++ -c <inputfile>.c -o .objs\<outputfile>.o" (don't know where the subdirectory .objs comes from, I definitely don't set it somewhere or ever used it).

stahta01

Patch file that might fix the issue. I am way too tired to be sure this patch is correct.

Tim S.


Index: src/plugins/compilergcc/compilergcc.cpp
===================================================================
--- src/plugins/compilergcc/compilergcc.cpp (revision 9854)
+++ src/plugins/compilergcc/compilergcc.cpp (working copy)
@@ -2903,10 +2903,29 @@
        return -2;
    }
    if (m_pProject)
-        wxSetWorkingDirectory(m_pProject->GetBasePath());
+    {
+        if ( UseMake(m_pProject) )
+        {
+            wxSetWorkingDirectory(m_pProject->GetExecutionDir());
+            return CompileFileWithMake(file, m_pProject, bt); // compile file using custom makefile
+        }
+        else
+        {
+            wxSetWorkingDirectory(m_pProject->GetBasePath());
+        }
+    }
    return CompileFileDefault(m_pProject, pf, bt); // compile file using default build system
}

+int CompilerGCC::CompileFileWithMake(const wxString& file, cbProject* project, ProjectBuildTarget* bt)
+{
+    wxString cmd = GetMakeCommandFor(mcCompileFile, project, bt);
+    cmd.Replace(_T("$file"), file);
+    m_CommandQueue.Add(new CompilerCommand(cmd, wxEmptyString, project, bt));
+
+    return DoRunQueue();
+}
+
int CompilerGCC::CompileFileWithoutProject(const wxString& file)
{
    // compile single file not belonging to a project
Index: src/plugins/compilergcc/compilergcc.h
===================================================================
--- src/plugins/compilergcc/compilergcc.h (revision 9854)
+++ src/plugins/compilergcc/compilergcc.h (working copy)
@@ -115,6 +115,7 @@
        virtual int RebuildWorkspace(const wxString& target = wxEmptyString);
        virtual int CompileFile(const wxString& file);
        virtual int CompileFileWithoutProject(const wxString& file);
+        virtual int CompileFileWithMake(const wxString& file, cbProject* project, ProjectBuildTarget* bt);
        virtual int CompileFileDefault(cbProject* project, ProjectFile* pf, ProjectBuildTarget* bt);
        virtual int KillProcess();
        virtual bool IsRunning() const;
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Alex

Quote from: stahta01 on July 31, 2014, 12:53:48 PM
Patch file that might fix the issue. I am way too tired to be sure this patch is correct.
Tim S.

Thanks a lot for your work. I don't know anything about CB internals but aren't there several variables missing like ACTIVE_EDITOR_STEM ... ?  Nevertheless I think you're on the right path now.

Tim or anybody else with a sourceforge account, could someone be so kind and open a ticket? This problem is still not reported there.


BTW: When will there be the next (bugfixed) CB release?


stahta01

Quote from: Alex on August 05, 2014, 05:33:59 PM
Quote from: stahta01 on July 31, 2014, 12:53:48 PM
Patch file that might fix the issue. I am way too tired to be sure this patch is correct.
Tim S.

Thanks a lot for your work. I don't know anything about CB internals but aren't there several variables missing like ACTIVE_EDITOR_STEM ... ?  Nevertheless I think you're on the right path now.

Tim or anybody else with a sourceforge account, could someone be so kind and open a ticket? This problem is still not reported there.


BTW: When will there be the next (bugfixed) CB release?



The GetMakeCommandFor command should handle  ACTIVE_EDITOR_STEM when it calls the Macro replacement function.
I just ported and adapted the code from the last working version for "custom makefile", it had the $file in it. I think it was 10.05.
I am NOT sure why the $file was needed and decided to leave it; in case Macro replacement function does NOT do $file.

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]