help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about recursive make


From: Erik Lotspeich
Subject: Re: Question about recursive make
Date: Tue, 02 Jun 2009 02:02:01 -0500
User-agent: Thunderbird 2.0.0.19 (X11/20081227)

Hi Sam,

Thank you so much for your insight and clear explanation.  I appreciate
your help.

Thanks to the others who responded as well.

Regards,

Erik.

On Fri, May 22, 2009 at 04:24:51PM -0500, Erik Lotspeich wrote:
> Hi,
>
> I have a question about recursive make.  I have the FSF GNU Make book by
> Richard Stallman & Roland McGrath (covering Make version 3.77).  In this
> book, it describes the following as equivalent:
>
> cd dirname && $(MAKE)
>
> $(MAKE) -C dirname
>
> It seems that these are not equivalent, however.  When integrating a
> Makefile system with the Linux Kernel build system, these two forms have
> different effects.  The first form works; the second form doesn't.
>
> I will clarify what I mean by integrating with the Linux Kernel build
> system.  For building with the Linux Kernel I will have a Makefile in a
> directory (e.g. kernelmod) that looks like this:
>
> module: mymodule.c
>         make -C $(KDIR) M=$(PWD) PWD=$(PWD) module
>
> In a directory one up from this Makefile, I would like to be able to
write:
>
> $(MAKE) -C kernelmod
>
> This leaves kernel files such as modules.order and Modules.symvers in
> this toplevel directory.  If I use the following:
>
> cd kernelmod && $(MAKE)
>
> Then, the files are in the kernelmod directory, as expected.
>
> Any help sorting this out would be greatly appreciated.

You should realize that the value of $(PWD) is set by the shell,
and not by make.
So when you write:

    $(MAKE) -C kernelmod

then the shell will set PWD to the current directory when make was executed.

But then when you write:

    cd kernelmod && $(MAKE)

Then the shell will update PWD for each command so PWD is set as you
expect when
you call make.

The solution is simple - use $(CURDIR) which is set by make.

        Sam




reply via email to

[Prev in Thread] Current Thread [Next in Thread]