DEV Community

Discussion on: How To Make A Makefile

Collapse
 
deciduously profile image
Ben Lovy • Edited

How is that different from just this?

You know... I'm not sure, looking at it. Indeed, it does work perfectly fine as you've written it. I've just always handled this case like this, I'm going to have to think about what, if any, benefit the fancier syntax nets you.

I suppose there's a case to be made for documentation - there's a rule with a dependency on $(OBJ), so it makes sense we should be able to find that variable as a target. It's less clear at a glance that your rule results in the proper target.

annoying to write and read

Exactly, that's pretty much the only reason I do it like this :)

make won’t rebuild an existing target file if it’s more recent than all its dependencies

This is a really good point. You're right, I also think make is still a strong tool stacked up against more recent choices. Its very unix-y, it does what it does and nothing else, and does that one thing very well. It's definitely more flexible than those other tools.

Collapse
 
oscherler profile image
Olivier “Ölbaum” Scherler

I read about static pattern rules, and I think I’m seeing a difference, but I’ll have to make tests.

web.mit.edu/gnu/doc/html/make_4.ht...

Maybe you could have two lists of %.o files that you want to process with two different rules, so you prepend each rule with the corresponding list.

And also, as you said, for documentation/readability. I once made a big Makefile that was using ImageMagick to generate 12 derivatives from 3 intermediate formats for two types of source images. So that’s 18 rules that you only distinguish from the pattern. If I prepend it with the variable containing the list, it surely becomes more readable.

Thread Thread
 
deciduously profile image
Ben Lovy

Ah, cool - thanks for the link!

I've still got so much to learn about make. That's a complex use case...my biggest issue with makefiles is readability, so anything to help yourself out it worthwhile to me.