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:[EMAIL PROTECTED] +---------------------------+ _______________________________________________ Help-make mailing list [EMAIL PROTECTED] http://lists.gnu.org/mailman/listinfo/help-make
