[chbot] Is there a GNU makefile guru out there?

Volker Kuhlmann list57 at top.geek.nz
Mon Aug 3 07:31:33 BST 2020

On Mon 03 Aug 2020 16:54:17 NZST +1200, Robin Gilks wrote:

[Makefile for different projects]

I've done fairly extensive Makefile construction, but haven't had to
make major changes in a while. I can see 2 approaches here:

1) Share a Makefile

Use shell globs to create the sources list, and run the Makefile in the
project directory.

Alternatively, use static sources lists, but then you'll have to assign
variables dependent on the currently active target. It works, but can
get a bit unpredicted because IIRC the assignments were not
hierarchical, i.e. when a sub-target is made, the assignment disappears.
Using both immediate and deferred variable assignments cleverly might

I'm not sure having the same Makefile for when you add projects later is
a good approach. Makefile changes for projectB might change the build of

2) Have a Makefile per project

This is usually the done thing. You can place the not-changing bulk of
your Makefile into common, and use include. That's what I do. Make a
template Makefile and include everything but the differences for this
project. Parameterisation is good.

You could add a top-level Makefile that makes all in subdirectories.

If however your projects are different build variants (I have that
lots), suitable parameterisation should do wonders.

Always use implicit rules. As soon as you have explicit rules, things
get complicated. The exception is where your explicit rules are
automatically generated. There's a gcc option to auto-create the
dependency list for each module. That's a good one to use too.

Or did I misunderstand your requirements?


Volker Kuhlmann
http://volker.top.geek.nz/	Please do not CC list postings to me.

More information about the Chchrobotics mailing list