is there a make style guide somewhere?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

is there a make style guide somewhere?

Robert P. J. Day-2

  was dropped into an existing project where the makefiles were
designed based on the only understood workflow at the time, and those
makefiles are not really compatible with what we're trying to do now,
and some of it has to do with what looks like pretty basic design
issues. here's just one of them.

  lots of the makefiles have recipes of the form:

  $(OUTPUT_DIR)/target.elf: $(INPUT_DIR)/src.c
        ... do what it takes to turn src.c into target.elf ...

perfectly respectable, as long as that target is invoked within the
context of the makefile so that those variables have values. however,
it makes it difficult to invoke *just* that target since you never
know what the OUTPUT_DIR or INPUT_DIR might be.

  my suggestion was, for any targets for which it is feasible to
invoke directly, add a redirection(?) target with a meaningful name:

  turn_src_into_elf: $(OUTPUT_DIR)/target.elf
  $(OUTPUT_DIR)/target.elf: $(INPUT_DIR)/src.c
        ... do what it takes to turn src.c into target.elf ...

at which point, of course:

  $ make turn_src_into_elf

does this make sense? is it a well-known make idiom? is there a list
somewhere of such idioms and style recommendations?

rday

--

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                         http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================

Reply | Threaded
Open this post in threaded view
|

Re: is there a make style guide somewhere?

David
On Fri, 1 Nov 2019 at 02:08, Robert P. J. Day <[hidden email]> wrote:

[...]

>   my suggestion was, for any targets for which it is feasible to
> invoke directly, add a redirection(?) target with a meaningful name:
>
>   turn_src_into_elf: $(OUTPUT_DIR)/target.elf
>   $(OUTPUT_DIR)/target.elf: $(INPUT_DIR)/src.c
>         ... do what it takes to turn src.c into target.elf ...
>
> at which point, of course:
>
>   $ make turn_src_into_elf
>
> does this make sense? is it a well-known make idiom? is there a list
> somewhere of such idioms and style recommendations?

Makes sense to me.

FYI, because the recipe does not actually create a file named
"turn_src_into_elf", it is named a "phony target", and it is a
good idea to inform make that fact, using this statement:
.phony turn_src_into_elf

Doing so has some benefits, which are documented here:
https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets

I use them a lot, so I consider them well known.

Reply | Threaded
Open this post in threaded view
|

Re: is there a make style guide somewhere?

David
In reply to this post by Robert P. J. Day-2
On Fri, 1 Nov 2019 at 02:08, Robert P. J. Day <[hidden email]> wrote:

[...]

> is there a list
> somewhere of such idioms and style recommendations?

There's this, if you haven't seen it:
https://www.gnu.org/software/make/manual/html_node/Makefile-Conventions.html#Makefile-Conventions

There's also some books on Gnu Make:
https://www.amazon.com/Managing-Projects-GNU-Make-Handbooks/dp/0596006101
https://www.allitebooks.in/gnu-make-book/

Reply | Threaded
Open this post in threaded view
|

Re: is there a make style guide somewhere?

Robert P. J. Day-2
In reply to this post by David
On Sat, 2 Nov 2019, David wrote:

> On Fri, 1 Nov 2019 at 02:08, Robert P. J. Day <[hidden email]> wrote:
>
> [...]
>
> >   my suggestion was, for any targets for which it is feasible to
> > invoke directly, add a redirection(?) target with a meaningful name:
> >
> >   turn_src_into_elf: $(OUTPUT_DIR)/target.elf
> >   $(OUTPUT_DIR)/target.elf: $(INPUT_DIR)/src.c
> >         ... do what it takes to turn src.c into target.elf ...
> >
> > at which point, of course:
> >
> >   $ make turn_src_into_elf
> >
> > does this make sense? is it a well-known make idiom? is there a list
> > somewhere of such idioms and style recommendations?
>
> Makes sense to me.
>
> FYI, because the recipe does not actually create a file named
> "turn_src_into_elf", it is named a "phony target", and it is a good
> idea to inform make that fact, using this statement: .phony
> turn_src_into_elf

  ah, so because "turn_src_into_elf" is just my pet name for an
*actual* possibly updated file, my pet name should be .PHONY, as
in:

.PHONY: turn_src_into_elf
turn_src_into_elf: $(OUTPUT_DIR)/target.elf
$(OUTPUT_DIR)/target.elf: $(INPUT_DIR)/src.c
         ... recipe ...

while its dependency would, of course, not be. that's the
clarification i was after.

> Doing so has some benefits, which are documented here:
> https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets

  working my way through make manual as we speak, thanks.

rday

--

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                         http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================

Reply | Threaded
Open this post in threaded view
|

Re: is there a make style guide somewhere?

Robert P. J. Day-2
In reply to this post by David
On Sat, 2 Nov 2019, David wrote:

> On Fri, 1 Nov 2019 at 02:08, Robert P. J. Day <[hidden email]> wrote:
>
> [...]
>
> > is there a list
> > somewhere of such idioms and style recommendations?
>
> There's this, if you haven't seen it:
> https://www.gnu.org/software/make/manual/html_node/Makefile-Conventions.html#Makefile-Conventions

  i was unaware of that ... my only concern is whether the denizens of
this list approve of the conventions listed there, as i remember linus
torvalds once saying about the GNU coding standards that one should
print them off, then burn them in a cleansing ritual.

  i'll go over them as soon as i finish poring over the official make
manual. thanks again.

rday

--

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                         http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================

Reply | Threaded
Open this post in threaded view
|

Re: is there a make style guide somewhere?

Galen Seitz
In reply to this post by David
On 11/1/19 8:49 PM, David wrote:

> On Fri, 1 Nov 2019 at 02:08, Robert P. J. Day <[hidden email]> wrote:
>
> [...]
>
>> is there a list
>> somewhere of such idioms and style recommendations?
>
> There's this, if you haven't seen it:
> https://www.gnu.org/software/make/manual/html_node/Makefile-Conventions.html#Makefile-Conventions
>
> There's also some books on Gnu Make:
> https://www.amazon.com/Managing-Projects-GNU-Make-Handbooks/dp/0596006101
> https://www.allitebooks.in/gnu-make-book/
>

There are more make resources listed at Paul's make site.
<http://make.mad-scientist.net/#resources>

In particular, I found his papers very useful.  I recommend reading
through all of them if you have the time.
<http://make.mad-scientist.net/papers/>


galen
--
Galen Seitz
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: is there a make style guide somewhere?

Martin d'Anjou-5
Google for "Recursive Make Considered Harmful pdf by Peter Miller". You
will learn a lot, whether you agree or not with the "harmful" assessment.

Martin

On Sat., Nov. 2, 2019, 12:25 Galen Seitz, <[hidden email]> wrote:

> On 11/1/19 8:49 PM, David wrote:
> > On Fri, 1 Nov 2019 at 02:08, Robert P. J. Day <[hidden email]>
> wrote:
> >
> > [...]
> >
> >> is there a list
> >> somewhere of such idioms and style recommendations?
> >
> > There's this, if you haven't seen it:
> >
> https://www.gnu.org/software/make/manual/html_node/Makefile-Conventions.html#Makefile-Conventions
> >
> > There's also some books on Gnu Make:
> >
> https://www.amazon.com/Managing-Projects-GNU-Make-Handbooks/dp/0596006101
> > https://www.allitebooks.in/gnu-make-book/
> >
>
> There are more make resources listed at Paul's make site.
> <http://make.mad-scientist.net/#resources>
>
> In particular, I found his papers very useful.  I recommend reading
> through all of them if you have the time.
> <http://make.mad-scientist.net/papers/>
>
>
> galen
> --
> Galen Seitz
> [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: is there a make style guide somewhere?

Robert P. J. Day-2
On Sat, 2 Nov 2019, Martin d'Anjou wrote:

> Google for "Recursive Make Considered Harmful pdf by Peter Miller".
> You will learn a lot, whether you agree or not with the "harmful"
> assessment.

  i read that a while back ... one does not need to agree or disagree
to learn from it.

rday