bug-make
[Top][All Lists]
Advanced

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

Re: Problem setting a variable inside a target


From: Bahman Movaqar
Subject: Re: Problem setting a variable inside a target
Date: Tue, 26 Sep 2023 09:42:15 -0700
User-agent: Evolution 3.50.0

I stand to be corrected however, no.

Not a direct answer to your question but in my experience, the best way
is to approach such situations is to let Make figure out what depends
on what, should it make a particular target or not and to avoid `if'
and `define' as much as possible.

-- 
Bahman


On Tue, 2023-09-26 at 16:30 +0000, Ed L Wolf wrote:
> The problem is that $(eval SUPPLIER_A2l := $(sort $(shell find
> $(DIR_A2LGEN_SUPPLIER) -type f -name "*.a2l"))) runs before the
> directory was created and the a2l files were copied to the directory.
> Since this ran before the directory creation and copy  of the a2l
> file  SUPPLIER_A2L is always null. IS there anyway to force this
> statement to be ran in the exact sequence its listed?
> 
> Ed L Wolf
> Technical Advisor - Embedded Software
> e.l.wolf@cummins.com
> Cummins Inc.
> Mail Code: C7004
> 1460 National Road
> Columbus, Indiana 47201
> United States
> 
> -----Original Message-----
> From: Bahman Movaqar <bahman@bahmanm.com> 
> Sent: Tuesday, September 26, 2023 12:11 PM
> To: Ed L Wolf <e.l.wolf@cummins.com>; bug-make@gnu.org
> Subject: Re: Problem setting a variable inside a target
> 
> EXTERNAL SENDER: This email originated outside of Cummins. Do not
> click links or open attachments unless you verify the sender and know
> the content is safe.
> 
> 
> OK, it took me a while but I think I may have something relatively
> more readable.
> 
> The idea is to let Make handle the prerequisites and the order of
> build for you by using well laid out targets.
> 
> The challenge I was facing trying to understand your code was that
> you'd condensed the original hierarchy of `*.a2l' files into
> `DIR_A2LGEN_SUPPLIER' which had made very difficult to tell Make how
> to make a target and when.
> 
> Here's my further slimmed down version of your snippet.  Let me know
> if that makes sense and whether it solves your problem.  You can also
> view on pastebin w/ syntax highlighting:
> https://pastebin.com/cHy8CuUt
> 
> 
> 🙶
> 
> SHELL := /usr/bin/env -S bash -o pipefail .DEFAULT_GOAL := all
> 
> #####################################################################
> ##
> 
> ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) build.dir :=
> $(ROOT)build/ src.dir := $(ROOT)
> 
> #####################################################################
> ##
> 
> A2L-files.src = $(shell find $(src.dir) -type f -name '*.a2l') A2L-
> files.dst = $(subst $(src.dir),$(build.dir),$(A2L-files.src))
> 
> #####################################################################
> ##
> 
> $(build.dir) :
>         mkdir -p $(@)
> 
> #####################################################################
> ##
> 
> $(build.dir)%.a2l : $(src.dir)%.a2l
>         mkdir -p $(build.dir)$(subst $(src.dir),,$(dir $(<))) \
>         && cp $(<) $(@)
> 
> #####################################################################
> ##
> 
> .PHONY : merge
> 
> ifneq ($(A2L-files.dst),)
> 
> merge : $(A2L-files.dst)
>         @echo MERGE POSSIBLE
>         @echo ...
> 
> else
> 
> merge :
>         @echo MERGE NOT POSSIBLE
>         @echo ...
> 
> endif
> 
> #####################################################################
> ##
> 
> .PHONY : clean
> 
> clean :
>         -rm -rf $(build.dir)
> 
> #####################################################################
> ##
> 
> .PHONY : all
> 
> all : | $(build.dir)
> all : merge
> 
> 🙷
> 
> 
> --
> Bahman
> 
> 
> On Tue, 2023-09-26 at 12:17 +0000, Ed L Wolf wrote:
> > Here is the strip down version
> > 
> > $(DIR_A2LGEN_SETUP)/McData-setup.a2l:
> >             @echo "A2L        $@"
> > 
> > 
> >             @find $(DIR_BSWPROJECT) -type f -name "*.a2l" | xargs -
> > i 
> > cp {} $(DIR_A2LGEN_SETUP)
> > 
> > 
> > 
> > 
> > ifneq ($(wildcard $(DIR_SUPPLIER)),)
> >             @find $(DIR_SUPPLIER) -type f -name "*.a2l" | xargs -i
> > cp 
> > {} $(DIR_A2LGEN_SUPPLIER)
> >             $(eval SUPPLIER_A2l := $(sort $(shell find
> > $(DIR_A2LGEN_SUPPLIER) -type f -name "*.a2l")))
> >             @echo "A2L        Supplier folder detected"
> >             @echo "Supplier a2l         $(SUPPLIER_A2l)"
> > 
> > 
> > # Just becuase there is a supplier folder does not mean it has a2l 
> > files.
> > ifeq ($(SUPPLIER_A2l),"*.a2l")
> >             @echo "A2L        Supplier a2l files
> > found"
> > 
> > else
> >             @cp $(DIR_A2LGEN_SETUP)/McData-copyright-can.a2l
> > $(DIR_A2LGEN_SETUP)/McData-setup.a2l
> >             @echo "A2L        Supplier folder detected but no a2l
> > files present"
> > endif
> > 
> > else
> >             @cp $(DIR_A2LGEN_SETUP)/McData-copyright-can.a2l
> > $(DIR_A2LGEN_SETUP)/McData-setup.a2l
> >             @echo "A2L        Supplier folder not available"
> > endif
> > 
> > Ed L Wolf
> > Technical Advisor - Embedded Software
> > e.l.wolf@cummins.com
> > Cummins Inc.
> > Mail Code: C7004
> > 1460 National Road
> > Columbus, Indiana 47201
> > United States
> > 
> > -----Original Message-----
> > From: Bahman Movaqar <bahman@bahmanm.com>
> > Sent: Tuesday, September 26, 2023 6:35 AM
> > To: Ed L Wolf <e.l.wolf@cummins.com>; bug-make@gnu.org
> > Subject: Re: Problem setting a variable inside a target
> > 
> > EXTERNAL SENDER: This email originated outside of Cummins. Do not 
> > click links or open attachments unless you verify the sender and
> > know 
> > the content is safe.
> > 
> > 
> > On Sun, 2023-09-24 at 17:23 +0000, Ed L Wolf wrote:
> > 
> > > 
> > > ifneq ($(wildcard $(DIR_SUPPLIER)),) ...
> > > > $(eval SUPPLIER_A2l := $(sort $(shell find
> > > > $(DIR_A2LGEN_SUPPLIER)
> > > > -
> > > > type f -name "*.a2l")))
> > > ...
> > > ifeq ($(SUPPLIER_A2l),"*.a2l")
> > > 
> > 
> > Quickly skimming through your code, I can see that the above
> > `ifneq'
> > and `ifeq' are evaluated at the very same time/pass.  That means
> > the 
> > result of `eval' will not be visible to `ifeq'.
> > 
> > HTH,
> > 
> > 
> > PS: I could have tried to come up w/ an alternative approach to
> > laying 
> > out the code but, I found the snippet crowded w/ too much logic 
> > specific to your case which makes it hard for me to see the
> > abstract 
> > patterns in play.  Can you try to slim down the snippet and push it
> > to 
> > a public repo somewhere so I can take a look?
> > 
> > --
> > Bahman



reply via email to

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