[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Math and GMake
From: |
Tzafrir Cohen |
Subject: |
Re: Math and GMake |
Date: |
Sat, 25 Sep 2004 08:30:59 +0200 |
User-agent: |
Mutt/1.5.6i |
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) ?
--
Tzafrir Cohen +---------------------------+
http://www.technion.ac.il/~tzafrir/ |vim is a mutt's best friend|
mailto:address@hidden +---------------------------+
- Math and GMake, Ken Smith, 2004/09/24
- Re: Math and GMake,
Tzafrir Cohen <=
- Re: Math and GMake, Noel Yap, 2004/09/26
- Re: Math and GMake, Ken Smith, 2004/09/27
- 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