Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: JoJo on April 25, 2023, 03:54:22 pm

Title: Custom Makefile: How to build one module.obj from module.cpp ?
Post by: JoJo on April 25, 2023, 03:54:22 pm
Hi, I am new to C::B and am tying to import a project with a custom Makefile.

When I have a source module like "module.cpp", the command to build the respective object file would be to issue "make module.obj". How can I get there?

As far as I can see, Project->Build Commands->Make command support

$make
$makefile
$target
$file

For the "Compile single file" I entered

"$make -f $makefile $file.obj"

But when I hit "Build file" for a source.cpp, C::B issues

g++ [options]  -c source.cpp -o obj/Debug/source.o

but nowhere in my Makefile there is such a thing like "obj/Debug", and the options are different from the ones used with "make source.obj". So C::B is still using its own build scheme even though I used custom Makefile.

If $file the correct command to get the basename (without path or extendion) of a file?

Please help me.
Title: Re: Custom Makefile: How to build one module.obj from module.cpp ?
Post by: stahta01 on April 25, 2023, 06:23:08 pm
Project -> Properties...

Tab: Project Setting
Is there a Checkmark on "This is an custom makefile"
What did you change the makefile name to?

Tim S.

Title: Re: Custom Makefile: How to build one module.obj from module.cpp ?
Post by: JoJo on April 25, 2023, 06:28:07 pm
> Is there a Checkmark on "This is an custom makefile"

Yes.

> What did you change the makefile name to?

Makefile is named "Makefile", I never changed that.
Title: Re: Custom Makefile: How to build one module.obj from module.cpp ?
Post by: stahta01 on April 25, 2023, 06:31:04 pm
Post the full build log in code tags.
Edit: In your case build file results of the build log would likely be correct.

Tim S.
Title: Re: Custom Makefile: How to build one module.obj from module.cpp ?
Post by: stahta01 on April 25, 2023, 06:36:33 pm
Is the Makefile and the CB Project file in the same folder?
If not, then I normally create an Makefile in the CB Project folder that calls the other makefile.

Tim S.
Title: Re: Custom Makefile: How to build one module.obj from module.cpp ?
Post by: stahta01 on April 25, 2023, 06:40:35 pm
I just realized I have never used "build file" with an custom makefile it might or might not work correctly.

Tim S.
Title: Re: Custom Makefile: How to build one module.obj from module.cpp ?
Post by: JoJo on April 25, 2023, 08:37:06 pm
Is the Makefile and the CB Project file in the same folder?

Yes. The Makefile already existed when I created the CB project file.
Title: Re: Custom Makefile: How to build one module.obj from module.cpp ?
Post by: stahta01 on April 26, 2023, 01:39:19 am
I just visual traced the code and it looks to me that "Build file" does not use the custom makefile.

From compilergcc.cpp line 3133 current SVN
Code
return CompileFileDefault(m_pProject, pf, bt); // compile file using default build system

Edit: Adding the use of  "UseMake" call in compilergcc.cpp would be a partial fix; but, other than adding an error saying not supported I have no idea what to add without a lot more work.

Tim S.
Title: Re: Custom Makefile: How to build one module.obj from module.cpp ?
Post by: JoJo on April 28, 2023, 03:24:17 pm
IMO, with a custom Makefile, it's hard or impossible to guess how that works, and it's likely you build wrong assumptions into C::B.

What I was expecting that there is some custom command that could be issued on "build file" etc., where I can provide a string that can be composed from parts like basename of the file, extension of the file, folder where the file is located, etc. C::B would then just issue that command.

Or if you allow to attach command to special keys like F7, where you provide file name, extension, etc.