On 11/26/06, Brian Lewis <[EMAIL PROTECTED]> wrote:
I'd like a user-defined function to say x="M"$(N), increment N, and
return x. I know how to write user-defined functions, but I don't
understand how they can cause side effects like the incrementing of the
variable N. In case it isn't clear, this function would return M0 the
first time, M1 the second time, etc. User-defined functions in make seem
functional. Maybe I can use semicolons? Is the value of a function the
value of its last expression? Thanks.

Here are two alternatives to what you came up with if you are still
interested.  The first one requires Lua support which is provided by
the patches posted here.

 http://lists.gnu.org/archive/html/help-make/2006-10/msg00018.html

The second requires GNU bc.  The advantage of the first is that there
will be no fork/exec for the shell process.  This may matter if you
call the macro repeatedly.  The advantage of the second is that it
will work with unpatched GNU make.

First Solution
x := 1
N := 1
$(info x = $(x))
$(info N = $(N))

generate-module-name = \
$(strip \
 $(eval x := M$(N)) \
 $(eval N := $(lua printmake($(N) + 1))) \
 $(x) \
)

$(info generate-module-name result = $(generate-module-name))
$(info x = $(x))
$(info N = $(N))


Second Solution
x := 1
N := 1
$(info x = $(x))
$(info N = $(N))

generate-module-name = \
$(strip \
 $(eval x := M$(N)) \
 $(eval N := $(shell echo $(N) + 1|bc)) \
 $(x) \
)

$(info generate-module-name result = $(generate-module-name))
$(info x = $(x))
$(info N = $(N))


 Ken Smith


_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to