not sure about value of "$(lastword $(MAKEFILE_LIST))" in this example

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

not sure about value of "$(lastword $(MAKEFILE_LIST))" in this example

Robert P. J. Day-2

  a Makefile i was handed (that lives two subdirs down in the total
code base, and which is meant to be run after cd'ing down to its
containing directory), contains early on:

  THIS_FILE := $(lastword $(MAKEFILE_LIST))

  include $(TOP_ROOT)/config.include
  include $(OTHER_DIR)/config.include
  include config.include

now, since this makefile is invoked from that very directory with:

  $ make <target>

i checked and, unsurprisingly, the variable THIS_FILE contains the
string "Makefile". so far, so good.

  the makefile is slightly complicated in that it's a dual-purpose
makefile, being invoked either natively or running a docker container
that invokes targets from the same makefile. again, no big deal.

  what i find odd is that a number of recipes which turn around and
re-invoke make explicitly reference that THIS_FILE variable as
follows:

  @$(MAKE) -f $(THIS_FILE) version

i'm not sure what to make of this since there is only one Makefile in
play in this directory, and the docker container has its working
directory set to this directory, and all of the targets being invoked
are defined in the same Makefile.

  so, while adding "-f $(THIS_FILE)" to those make commands doesn't
hurt, i can't see what value that adds. am i missing something subtle
regarding that variable? i realize that bringing docker containers
into it does complicate things, but as long as all work is done from
the same directory, is that "-f" option really necessary?

rday

--

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

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

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: not sure about value of "$(lastword $(MAKEFILE_LIST))" in this example

Kaz Kylheku (gmake)
On 2019-10-15 08:59, Robert P. J. Day wrote:
> i'm not sure what to make of this since there is only one Makefile in
> play in this directory, and the docker container has its working
> directory set to this directory, and all of the targets being invoked
> are defined in the same Makefile.

It allows the containing file to re-invoke itself regardless of its
name. Even if it is the only makefile in the directory, this would
be required if its name isn't "dir.mk".  It's also required if it does
happen to be invoked from somewhere else.

Basically this is using copy-and-paste boilerplate for "calculate
my own name" to try to be strictly correct.

>   so, while adding "-f $(THIS_FILE)" to those make commands doesn't
> hurt, i can't see what value that adds.

The value is that it's "future-proof".  Suppose things change so that
the build system doesn't chdir into that directory to run that
makefile. If that file tries to re-invoke itself as just $(MAKE), it
will likely succeed by running the the wrong Makefile. Someone will
have a lot of fun debugging that.


_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: not sure about value of "$(lastword $(MAKEFILE_LIST))" in this example

Robert P. J. Day-2
On Tue, 15 Oct 2019, Kaz Kylheku (gmake) wrote:

> On 2019-10-15 08:59, Robert P. J. Day wrote:
> > i'm not sure what to make of this since there is only one Makefile
> > in play in this directory, and the docker container has its
> > working directory set to this directory, and all of the targets
> > being invoked are defined in the same Makefile.
>
> It allows the containing file to re-invoke itself regardless of its
> name. Even if it is the only makefile in the directory, this would
> be required if its name isn't "dir.mk"...

  i understood all of that except for the above ... what is magic
about the makefile name "dir.mk"? what is magic about that name such
that it would be used unless overridden?

rday

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: not sure about value of "$(lastword $(MAKEFILE_LIST))" in this example

Kaz Kylheku (gmake)
On 2019-10-15 10:06, Robert P. J. Day wrote:

> On Tue, 15 Oct 2019, Kaz Kylheku (gmake) wrote:
>
>> On 2019-10-15 08:59, Robert P. J. Day wrote:
>> > i'm not sure what to make of this since there is only one Makefile
>> > in play in this directory, and the docker container has its
>> > working directory set to this directory, and all of the targets
>> > being invoked are defined in the same Makefile.
>>
>> It allows the containing file to re-invoke itself regardless of its
>> name. Even if it is the only makefile in the directory, this would
>> be required if its name isn't "dir.mk"...
>
>   i understood all of that except for the above ... what is magic
> about the makefile name "dir.mk"? what is magic about that name such
> that it would be used unless overridden?

Nothing; I think what I was writing was "if its name isn't
Makefile but something else, like dir.mk". Somehow I bungled
it in editing.


_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: not sure about value of "$(lastword $(MAKEFILE_LIST))" in this example

Robert P. J. Day-2
On Tue, 15 Oct 2019, Kaz Kylheku (gmake) wrote:

> On 2019-10-15 10:06, Robert P. J. Day wrote:
> > On Tue, 15 Oct 2019, Kaz Kylheku (gmake) wrote:
> >
> >> On 2019-10-15 08:59, Robert P. J. Day wrote:
> >> > i'm not sure what to make of this since there is only one Makefile
> >> > in play in this directory, and the docker container has its
> >> > working directory set to this directory, and all of the targets
> >> > being invoked are defined in the same Makefile.
> >>
> >> It allows the containing file to re-invoke itself regardless of its
> >> name. Even if it is the only makefile in the directory, this would
> >> be required if its name isn't "dir.mk"...
> >
> >   i understood all of that except for the above ... what is magic
> > about the makefile name "dir.mk"? what is magic about that name such
> > that it would be used unless overridden?
>
> Nothing; I think what I was writing was "if its name isn't
> Makefile but something else, like dir.mk". Somehow I bungled
> it in editing.

  ok, that makes sense now, thanks.

rday

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make