Author Topic: Minor error with makefile  (Read 5283 times)

Offline Triniti

  • Single posting newcomer
  • *
  • Posts: 2
Minor error with makefile
« on: July 22, 2014, 12:54:52 am »
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.
Code
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.
« Last Edit: July 22, 2014, 12:58:03 am by Triniti »

Offline Alex

  • Single posting newcomer
  • *
  • Posts: 3
Re: Minor error with makefile
« Reply #1 on: July 26, 2014, 08:46:01 pm »
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13151
    • Travis build status
Re: Minor error with makefile
« Reply #2 on: July 28, 2014, 10:00:21 am »
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!]

Offline Alex

  • Single posting newcomer
  • *
  • Posts: 3
Re: Minor error with makefile
« Reply #3 on: July 28, 2014, 10:23: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).

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7067
    • My Best Post
Re: Minor error with makefile
« Reply #4 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.

Code
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++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Alex

  • Single posting newcomer
  • *
  • Posts: 3
Re: Minor error with makefile
« Reply #5 on: August 05, 2014, 05:33:59 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?


Offline stahta01

  • Lives here!
  • ****
  • Posts: 7067
    • My Best Post
Re: Minor error with makefile
« Reply #6 on: August 05, 2014, 05:51:01 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++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org