help-make
[Top][All Lists]
Advanced

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

Re: Making multiple action lines from a varaible


From: Kristof Provost
Subject: Re: Making multiple action lines from a varaible
Date: Wed, 1 Aug 2007 20:25:14 +0200
User-agent: Mutt/1.5.13 (2006-08-11)

On 2007-08-01 12:29:13 (-0500), EXT-Pennington, Dale K <address@hidden> wrote:
> My existing make environment has multiple .mak files for different
> chunks of my library in one Scripts directory, and a master build shell
> script that looks like :
> 
> gmake -f a.mak %1
> gmake -f b.mak %1 
> gmake -f c.mak %1
> 
> I would much perfer to have a master make makefile so that, among other
> things, when one fails we stop and can fix it before heading to the
> others. 
Add 'set -e' to the shell script to achieve this. 'set -ex' will also
echo the command before executing it, just like Make does.

> Now I could obviously do a brute force approach :
> 
> all :
>       gmake -f a.mak all
>       gmake -f b.mak all
>       gmake -f c.mak all
> 
> clean :
>       gmake -f a.mak clean
>       gmake -f b.mak clean
>       gmake -f c.mak clean
> 
> But I would much perfer to not have to do that. So far I have the
> following approach
> 
> MAKFILES = a.mak b.mak c.mak
> 
> all :
>       $(foreach make,$(MAKFILES),gmake -f $(make) all;)
> 
> clean :
>       $(foreach make,$(MAKFILES),gmake -f $(make) clean;)
> 
> This generates the desired result, almost. The problem is that since all
> the makes are done on 1 line, they are all submitted as one shell
> action, and all are attempted before a possible failure return. (I
> tested this by deliberately putting a command line option error to make
> gmake fail). 
> 
> So the question is :
> Is there a way to use the spare format of the second example to produce
> equivalent results of the first example ?

One solution is to replace ';' by '&&'.
all:
    $(foreach make, $(MAKEFILES), gmake -f $(make) all &&) true

A slightly different way might be:
TARGETS := a.mak b.mak c.mak

CLEANTARGETS := $(addprefix phony-clean-, $(TARGETS))
ALLTARGETS := $(addprefix phony-all-, $(TARGETS))

clean: $(CLEANTARGETS)
all: $(ALLTARGETS)

phony-clean-%:
    gmake -f $* clean

phony-all-%:
    gmake -f $* all

.PHONY: $(CLEANTARGERS) $(ALLTARGETS)

It won't guarantee the order, but you can run it with -j N.

Kristof





reply via email to

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