[Top][All Lists]

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

Re: [Question] Set a variable while building a specific target

From: Paul Smith
Subject: Re: [Question] Set a variable while building a specific target
Date: Sat, 22 May 2021 09:33:41 -0400
User-agent: Evolution 3.36.4-0ubuntu1

On Sat, 2021-05-22 at 21:13 +0900, Masahiro Yamada wrote:
>  - 'make vmlinux modules' builds __common with
> I know the example above does not work like that.

This is the part that won't work; the rest works fine AFAICS.

The problem is a common misconception, that make targets are like
functions or subroutines.  They are not: they are recipes to build
files.  Even .PHONY targets.

This means that once a target is built one time in a makefile it will
_never be built again_ (in that run of make).  So, unlike a function or
a subroutine you can't "call" a target multiple times in a makefile.

So you cannot collect a "common part" of a recipe into a separate
target that is depended on by multiple other targets, if you need that
common part to be run multiple times.  It just doesn't work like that.

You could put the common part into a variable and then use that
variable in all the targets, something like this:

define __common
        [ common build rules,
which internally uses
           BUILDING_{VMLINUX,MODULES} conditionals

.PHONY: vmlinux modules

vmlinux: export BUILDING_VMLINUX=y
modules: export BUILDING_MODULES=y

vmlinux modules:

reply via email to

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