bug-make
[Top][All Lists]
Advanced

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

[bug #18335] Addition of $(math ...) functions


From: Kaz Kylheku
Subject: [bug #18335] Addition of $(math ...) functions
Date: Mon, 05 Oct 2009 19:56:37 +0000
User-agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)

Follow-up Comment #4, bug #18335 (project make):

The make program does a lot of work by generating shell script fragments and
running them. Not only are the lines of rule bodies shell scripts, but GNU
makefiles make other uses of shell features. For instance, calling the find
utility to locate targets and such.

Adding math functions to make is a false optimization, and a self-indulgent
hack.

You can easily generate $(( expr )) shell syntax and have the shell evaluate
it.

Look. Makefile to print two plus two:

.PHONY: all

FOUR := $(shell echo $$(( 2 + 2)) )

all:
        echo "$(FOUR)"


And yes, it's clumsy to type $(shell echo $$(( <expr> )))
instead of just $(expr <expr>).

That's what GNU make macros are for. With macros, you can get it down to
$(call expr, <expr>).

If that's too inconvenient, maybe you're stuffing way too much math into the
Makefile and not enough of the normal stuff to make things.

.PHONY: all

define expr
$(shell echo $$(( $1 )) )
endef

X := 10
Y := 30

all:
        echo $(call expr, $(X) + $(Y))

$ make
echo 40
40


If you want to optimize make by moving computation out of sub-shells into the
make process, this is a poor place to start, because it's not the common
case.

You idiots want to put a Scheme interpreter into make?

Given that half of the make syntax is really shell syntax, which is farmed
out to a sub-process, it would be a much better idea to combine make with a
shell implementation.

That way, when make processes something like:

  target:
       case $@ in ) *.blah ... <complicateed shell script> 
         spanning dozens of lines 
         with lots of nested if and while, and for 
       esac

it could be interpreted without forking off a process. This would actually
benefit the reams of makefiles which are already written.

Then $(shell ...) could be entirely built in, and, therefore so would the $((
expr )) syntax. At that point, you could implement a shortcut to access that
syntax, like $(expr <expr>). It would be icing on the cake.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?18335>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





reply via email to

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