help-make
[Top][All Lists]
Advanced

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

Functions $(globalvar assign,string) and $(echo string) was GNU Make enh


From: Jason Wessel
Subject: Functions $(globalvar assign,string) and $(echo string) was GNU Make enhansment patch - batching compiles
Date: Mon, 7 May 2001 05:31:46 -0500

----- Original Message -----
From: "Eli Zaretskii" <address@hidden>
To: <address@hidden>
Cc: <address@hidden>; <address@hidden>
Sent: Friday, May 04, 2001 2:32 AM
Subject: Re: GNU Make enhansment patch - batching compiles


> > From: "Jason Wessel" <address@hidden>
> > Date: Thu, 3 May 2001 14:00:42 -0500
> >
> > > I thought about doing that from the rule which is normally used to
> > > compile .java into .class.  Something like this:
> > >
> > >    %.class : %.java
> > > echo '$< \\' >> files_list
> > >
> >
> > Using an implicit rule is not really what I want to do
>
> It's not important.  What I meant was that you can put something like
> the above into every rule which normally generates a compiled file.
> In effect, you will be using the file files_list as the accumulator
> for the value of the variable you wanted.

I agree that you can use a file_list as an accumulator, but it has:
A) Overhead of launching yet another shell
B) There is another transient file that needs to be cleaned up

>From what I can tell, if you have a rule where the command
section evaluates to a null string, no sub shell is spawned.
Using the proposed globalvar function will run much, much
faster when iterating over hundreds of files, since you don't
have to pay the penalty of a fork(), exec("sh -c ......").  The
idea here is to allow make to figure out what to build with
as few sub processes as possible.

The statement below theoretically never executes a subshell.
%.class : %.java
    $(globalvar targlist,${targlist} $<)

Noting, that there can be substantial overhead with spawning
shells.  Another easy enhancement to make would be to add
the function $(echo text_or_variable_expansion).

The $(echo) function does nothing more than expand the variables
and perform the semantic equivalent of the shell echo function.
The key advantage is that no sub shell has to be spawned.
The implementation is a simple printf("%s",expanded_variable_and_text);.

This can serve two purposes.
1) It gives you the ability to print ability to echo/print output
    in the variable assignment sections of the make file
    - Today there is no way to print output in the variable assignment
section.
    - Here is an example of a way it might be used:
        ifeq (${batch},1)
            dummy_var = $(echo Conducting batch build)
            ...do other stuff...
        else
            dummy_var = $(echo Conducting standard build)
            ...do other stuff...
        endif

2) You can put echo statements in the command section of a make
     rule and not pay a subshell penalty.
    - The following do the same thing.  "b)" doesn't spawn a subshell.
        a)
            print_dir:
                @echo "***Building in $(CURDIR)***"
        b)
            print_dir:
                $(echo ***Building in $(CURDIR)***)

Summary:  There are two requested new function to make, of which I
                 will gladly supply the patch. Below are the short
descriptions
                 of the two functions.
$(globalvar variable_name, string)
    Assigns the expanded value of string to the variable variable_name.
    It is the equivalent of using the := operator.  It always returns a null
    string.  This function is best suited to be used in the command section
    of a rule.
        %.c : %.o
            $(globalvar targlist,${targlist} $<)
     The above rule would collect all the .c files that needed to be
compiled.

$(echo string)
    Prints the value of string to standard out.  It always returns a null
    string. It has two uses.  It can send out put in the variable assignment
    section of a make file ie:
        dummy_var = $(echo hello world)
    dummy_var is assigned the string "", but the text "hello world" was
    sent to standard out.

    It is probably more useful to use the echo function to avoid spawning
    shell in a rule that only prints text ie:
        print_curdir:
            $(echo Current dir is: $(CURDIR))
    Since the echo function evaluates to the string "" no subshell is
    spawned and text is printed.



Jason.






reply via email to

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