[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Math and GMake
From: |
Ken Smith |
Subject: |
Re: Math and GMake |
Date: |
Mon, 27 Sep 2004 09:22:15 -0400 |
User-agent: |
Mutt/1.5.6i |
On Sat, Sep 25, 2004 at 08:30:59AM +0200, Tzafrir Cohen wrote:
> On Fri, Sep 24, 2004 at 05:08:21PM -0400, Ken Smith wrote:
> > Is there a simple way to do math in GMake? I am currently doing
> > something like this.
> >
> > # GNUmakefile
> > os_math = $(shell echo "$(1)" | bc)
>
> bash has $(( )) for math calculations. I'm not sure if this is also
> supported by other bourne shells, though.
>
> > os_add = $(call os_math,$(1)+$(2))
> > ge = $(shell [[ "$(1)" -ge "$(2)" ]] && echo t)
> >
> > range = $(if $(call ge,$(strip $(2)),$(strip $(1))),$(call range,$(call
> > os_add,$(1),1),$(2),$(3) $(1)),$(strip $(3)))
> >
> > VAR=$(call range,1,10)
> >
> > all:
> > @echo VAR=$(VAR)
> > # end GNUmakefile
>
> my gmake 3.79.1 complains about the recusive variable range, and quits.
>
> >
> > An strace of gmake running on the above example shows how painfully slow
> > this code will make a build which uses it at all. (How many times will
> > os_add fork? Yikes.) I would like to know if the above can be done
> > using only GMake primitives? Maybe? Please?
> >
> > I'll also appreciate hearing any other suggestions or optimizations.
> > Can any clever mailgroup participant think of a nonrecursive way to
> > write the range function?
>
> Why not simply use seq(1) ?
I knew there had to be a simple command for this somewhere. Thanks.
But my problem is more general. I cannot use bash or zsh where the
double parentheses notation is available. I would also like to come
up with a better way to do math in gmake.
Also, I forgot to mention that the the above example does require gmake
3.80 or later.
Thanks for your help.
Ken
- Math and GMake, Ken Smith, 2004/09/24
- Re: Math and GMake, Tzafrir Cohen, 2004/09/25
- Re: Math and GMake, Noel Yap, 2004/09/26
- Re: Math and GMake,
Ken Smith <=
- Re: Math and GMake, Tzafrir Cohen, 2004/09/27
- Re: Math and GMake, Ken Smith, 2004/09/27
- Re: Math and GMake, Noel Yap, 2004/09/27
- Re: Math and GMake, Ken Smith, 2004/09/27
- Re: Math and GMake, Noel Yap, 2004/09/27
- Re: Math and GMake, Ken Smith, 2004/09/27
- Re: Math and GMake, Tzafrir Cohen, 2004/09/27