News:

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

Main Menu

Custom Makefile: How to build one module.obj from module.cpp ?

Started by JoJo, April 25, 2023, 03:54:22 PM

Previous topic - Next topic

JoJo

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.

stahta01

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.

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]

JoJo

> 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.

stahta01

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.
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]

stahta01

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.
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]

stahta01

I just realized I have never used "build file" with an custom makefile it might or might not work correctly.

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]

JoJo

Quote from: stahta01 on April 25, 2023, 06:36:33 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.

stahta01

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

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.
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]

JoJo

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.