help-make
[Top][All Lists]
Advanced

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

Re: Is it possible to break from a GMAKE foreach loop and then exit from


From: Kaz Kylheku
Subject: Re: Is it possible to break from a GMAKE foreach loop and then exit from make?
Date: Fri, 27 May 2022 23:11:03 -0700
User-agent: Roundcube Webmail/1.4.13

On 2022-05-27 06:35, Pierre Rouleau wrote:
> Hi all,
> 
> I have a makefile tha patches the kernel but does not check if the patch
> succeeded.
> The rule is shown below.  It uses a foreach loop to apply a set of patches
> identified by
> a list of patches.
> 
> Is it possible to use the `|| exit 1' construct inside the text portion of
> the foreach loop to detect
> failing patches and stop make execution?

As you know, foreach is run by Make, like a macro. The generated shell code
then performs exit detection.

What you probably want is to generate clauses joined by &&

  $(foreach ....) --> patch < this && patch < that && ... && patch < last

I believe that "set -e" also works, keeping in mind that each recipe
line is run in a separate shell invocation (in the absence of .ONESHELL:
being used).

So that is to say:

   target: prereq
        set -e; command; command; command; ...

with set -e, the shell will bail upon the first unsuccessful command,
with a failed termination status, much like the way Make bails on the
first unsuccessful recipe line.

Compare the effect of removing "set -e" from this Makefile:

  .PHONY: all
  
  all:
        set -e; echo foo; false; true


> 
> ie, Is it possible to transform the following:
> 
> $(OUTPUT_ROOT_DIR)/.kernel_patched: $(OUTPUT_ROOT_DIR)/.kernel_original
>         @echo -e "Applying only specific patch to kernel"
>         (cd $(OUTPUT_ROOT_DIR)/$(CFG_GLOBAL_LINUX_VERSION); $(foreach
> thepatch,$(KERNEL_PATCH_ONE),echo patching $(thepatch); patch
> --ignore-whitespace -p1 < $(thepatch);))
> 
> 
> into this and is it the best way or are there better alternatives?

The better alternative is to patch like it's 2002 and use the quilt
program.

If I had to manage patches being applied with Makefiles, I wouldn't use
anything else.

quilt will push on all the patches with one command "quilt push -a"
and that reports success or failure. 

This command is idempotent; if you run it again, quilt knows all patches
have been applied and so does nothing.

quilt has the nice workflows in it for situations when you have to
fix those patches: rebase them to different code, or make other changes
to them, to produce new versions of the patches.








reply via email to

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