[Top][All Lists]

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

Re: funtions in rule ?

From: Paul D. Smith
Subject: Re: funtions in rule ?
Date: Wed, 11 Oct 2000 16:45:25 -0400

%% Mirko Viviani <address@hidden> writes:

  mv> I've found nothing in the make.info about using function inside a rule
  mv> so I don't know if there is a way to get it working or if I'm wrong.

You can certainly use functions inside a rule (you can use make functions
wherever you use make variables; they're expanded in exactly the same

However, you cannot use them as you want to below.

  mv>   if [ "$(OBJC_OBJ_FILES)" != "" ]; then objcfiles="$(OBJC_OBJ_FILES)"; \
  mv>   fi; \
  mv>   if [ "$(SUBPROJECT_OBJ_FILES)" != "" ]; then objcfiles="$$objcfiles 
  mv>   fi; \
  mv>   if [ "$$objcfiles" = "" ]; then objcfiles="__dummy__"; \
  mv>   fi;\
  mv>   if [ "$$objcfiles" != "__dummy__" ]; then \
  mv>     for f in $$objcfiles; do \
  mv>       sym=`nm -Pg $$f`; \
  mv>       sym=$(patsubst __objc_class_name_%,%,$$sym); \
  mv>           echo $$sym; \
  mv>     done; \
  mv>   fi;

This can't work.  Remember how make works: it doesn't _interpret_ the
command script you provide, it merely forks a shell to interpret it.

That means that, _before_ it invokes the shell, it must evaluate all the
make variables and make functions; there's no way the shell, as a
subprocess, can "communicate" back up to the make process to have it
run some make function in the middle of the shell script!

Just remember that all make variables and make functions are expanded
before the shell is invoked (this is, after all, why you have to escape
"$" in a shell script with "$$"), and you'll see why your code can't
work: you're trying to expand a make function using the value of a _shell_
variable which won't have any value at all until the shell is invoked
and is running the for-loop!

You will have to use shell commands to perform that operation; change

            sym=`nm -Pg $$f`; \
            sym=$(patsubst __objc_class_name_%,%,$$sym); \

to something like this:

            sym=`nm -Pg $$f | sed s/__objc_class_name_//`; \

 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://www.paulandlesley.org/gmake/
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

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