help-make
[Top][All Lists]
Advanced

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

Re: Change a target within Makefile?


From: Masahiro Yamada
Subject: Re: Change a target within Makefile?
Date: Thu, 25 Jul 2024 12:01:40 +0900

On Thu, Jul 25, 2024 at 1:36 AM Dmitry Goncharov
<dgoncharov@users.sf.net> wrote:
>
> On Wed, Jul 24, 2024 at 5:46 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> > Of course, it does not work since MAKECMDGOALS is read-only.
> Well, it is possible to assign a new value to makecmdgoals. i guess,
> you mean that make proceeds to build the target specified on the
> command line, regardless.


Right. The manual says the following:


MAKECMDGOALS

 The targets given to make on the command line.
 Setting this variable has no effect on the operation of make.






>
> > If recursion is allowed, the following might work, but
>
> i agree with "but". Make has a certain user interface and when the
> user specified x.a, i prefer a makefile that builds x.a. Attempts to
> override users choice are misleading.
> Somebody else reads the build log and cannot figure out why x.b was
> build, even though x.a was specified. And then another user inherits
> this env var accidentally and cannot figure out why x.b is getting
> build when they say x.a. And most users don't know the clever trick
> that turns x.a to x.b. Etc.
>
> Why don't you have the user specify x.b when they need x.b?
> If a shell program calls make, then the same logic applies, the shell
> program can look at the env variable and specify x.a or x.b.
>
> regards, Dmitry



My motivation is to improve the kernel build system (Kbuild).
I had this commit in my mind:
https://github.com/torvalds/linux/commit/d7c6ea024c08bbdb799768f51ffd9fdd6236d190

Kbuild is somewhat complex.
So, let me explain a slightly simplified version.


A device tree binary (%.dtb) is compiled from a device tree source (%.dts).

When the CHECK_DTB flag is set, some additional test (schema check)
must be executed.

A straightforward rule to achieve this will look like this:


%.dtb: %.dts
        [ compile the device tree ]
ifdef CHECK_DTB
        [ check the schema ]
endif


However, when the schema check command is changed,
we need to re-run the schema check.
(this is what commit d7c6ea024c08 achieved)

I do not want to re-compile %.dtb when the schema check
command is changed because "compiling %.dtb" and
"testing %.dtb" are two different things.

Decoupling them works well:


%.dtb: %.dts
       [ compile the device tree ]

.%.dtb.checked: %.dtb
       [ check the schema ]
       touch $@


A new timestamp file, .%.dtb.checked has been introduced here
because I want to run the schema check just once, unless the
schema check command is changed.

You could do "make .foo.dtb.check" to compile foo.dtb, followed by
the schema checking.

I do not want to expose the presence of the timestamp file,
as it is an internal implementation detail
(and that is why I added '.' prefix to make it a hidden file).


The behavior I would hope to see is:


"make foo.dtb bar.dtb"
   -> Generate foo.dtb and bar.dtb


"make foo.dtb bar.dtb CHECK_DTB=y"
   -> Generate foo.dtb and bar.dtb
      Their schema is also checked.


However, as I said in the initial email,
the following code does not work.

ifdef CHECK_DTB
MAKECMDGOALS := $(patsubst %.dtb, .%.dtb.checked, $(MAKECMDGOALS))
endif




I think the above description answered others.

.%.dtb.checked must be executed after %.dtb, not before.
It is not so simple as adding $(a_prereq).



Anyway, I understand there is no simple solution for this.

Thank you.



--
Best Regards
Masahiro Yamada



reply via email to

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