There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

How do you comment your makefiles?

cross-posted from: lemmy.ml/post/6863402

Fed up w/ my ad-hoc scripts to display the targets and variables in a makefile(s), I’ve decided to write a reusable piece of code to do that: github.com/bahmanm/bmakelib/issues/81


The first step toward that would be to understand the common commenting styles. So far I have identified 4 patterns in the wild which you can find below.

Are there any style guides/conventions around this topic? Any references to well-written makefiles I can get inspiration from?


A


<span style="color:#323232;">VAR1 = foo   ## short one-liner comment
</span><span style="color:#323232;">my-target:   ## short one-liner comment 
</span><span style="color:#323232;">	…
</span>

B


<span style="color:#323232;"># longer comment which 
</span><span style="color:#323232;"># may span
</span><span style="color:#323232;"># several lines
</span><span style="color:#323232;">VAR1 = foo
</span><span style="color:#323232;">
</span><span style="color:#323232;">## comments can be prefixed w/ more than # 
</span><span style="color:#323232;">## lorem ipsum dolor
</span><span style="color:#323232;">my-target: 
</span><span style="color:#323232;">	…
</span>

C


<span style="color:#323232;">#####
</span><span style="color:#323232;"># a comment block which is marked w/ several #s on
</span><span style="color:#323232;"># an otherwise blank line
</span><span style="color:#323232;">#####
</span><span style="color:#323232;">VAR1 = foo
</span>

D


<span style="color:#323232;">#####
</span><span style="color:#323232;">#>    # heading 1
</span><span style="color:#323232;">#     This is a variation to have markdown comments
</span><span style="color:#323232;">#     inside makefile comments.
</span><span style="color:#323232;">#
</span><span style="color:#323232;">#     ## It's a made-up style!  
</span><span style="color:#323232;">#     I came up w/ this style and used it to document `bmakelib`.
</span><span style="color:#323232;">#     For example: https://is.gd/QtiqyA (opens github)
</span><span style="color:#323232;">#&lt;
</span><span style="color:#323232;">#####
</span><span style="color:#323232;">VAR1 = foo
</span>
Penguincoder ,

We’re supposed to be commenting Makefiles?

bahmanm OP ,
@bahmanm@lemmy.ml avatar

I usually capture all my development-time “automation” in Make and Ansible files. I also use makefiles to provide a consisent set of commands for the CI/CD pipelines to work w/ in case different projects use different build tools. That way CI/CD only needs to know about make build, make test, make package, … instead of Gradle/Maven/… specific commands.

Most of the times, the makefiles are quite simple and don’t need much comments. However, there are times that’s not the case and hence the need to write a line of comment on particular targets and variables.

cbarrick ,

The GNU Coding Standards has a section on Make, which I would think is the most prominent Make style guide.

The doc itself doesn’t have a section on comments, but in the few examples given in that doc, they use style B.

www.gnu.org/prep/…/Makefile-Conventions.html

bahmanm OP ,
@bahmanm@lemmy.ml avatar

That’s a great starting point - and a good read anyways!

Thanks 🙏

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • [email protected]
  • lifeLocal
  • goranko
  • All magazines