[distcc] Re: implicit compiler name

Martin Pool mbp at samba.org
Sat Sep 14 09:46:00 GMT 2002


(Dimitri, if you don't mind could you write to the mailing list so
that other people can follow the discussion?)

On 13 Sep 2002, Dimitri PAPADOPOULOS-ORFANOS <papadopo at shfj.cea.fr> wrote:
> Hi,
> 
> I see the following code in distcc-0.10.1:
> 
> int dcc_check_implicit_compiler(char **argv, char ***out_argv)
> {
>     if (argv[1][0] == '-'
>         || dcc_is_source(argv[1])) {
>         dcc_shallowcopy_argv(argv, out_argv, 0);
>         /* FIXME: Allow the command name to be specified by a
>          * client-side environment variable */
>         (*out_argv)[0] = "cc";
> 

The most serious obstacle to "ln -s distcc gcc" is that a naive
implementation would cause any local executions to recurse without
terminating.  distcc would try to execute gcc locally, but it would
really be distcc, etc.  

This can be avoided by processing the path "by hand" to find the first
program that is not distcc (e.g. not a symlink).  This has to be done
on the client, and possibly also on the server, in case the server's
path is set the same way.  ccache does this, although I think the
algorithm is not as clean as it should be.

A slight disincentive is that the GNU Standards recommend against
varying behaviour based on argv[0], because it is historically a
source of confusion.  For example, somebody might install distcc as
"distcc-0.9", which would break any tests along the lines of
strcmp(argv[0], "distcc").  

  http://www.gnu.org/prep/standards_16.html#SEC16

Possibly this case is special enough to justify doing it.

> If I understand correctly, you'd like the compiler command to be specified by an 
> environment variable. But we have a mixture of C/C++ code here, so we cannot 
> specify the compiler using a single environment variable. 

But for a long time g++ has been the same program as gcc.  "gcc
foo.cpp" works fine.  I suppose this might not be the case for some
other compilers.  

(I suspect distcc may end up being somewhat gcc specific because of
varying options.  In any case I do not feel very obliged to help
proprietary vendors for free.)

  http://www.gnu.org/prep/standards_58.html#SEC58

Another approach, although not so general, would be to have both
DISTCC_CC and DISTCC_CXX, and use one or the other depending on
whether C or C++ code is being compiled.

> I believe it's better 
> to use symlinks and call directly the compiler by its name as Teambuiler, on 
> Linux:
> 	$ ln -s distcc cc
> 	$ ln -s distcc gcc
> 	$ ln -s distcc c++
> 	$ ln -s distcc g++
> and on Solaris:
> 	$ ln -s distcc cc
> 	$ ln -s distcc CC
> Then you put the above directory first in the PATH.
> 
> Then argv[0] is one of:
> 	<PATH>/cc
> 	<PATH>/gcc
> 	<PATH>/g++
> 	<PATH>/c++
> 	<PATH>/CC
> which gives the name of the implicit compiler.
> 
> I think its enough to change:
>         (*out_argv)[0] = "c";
> to:
>         (*out_argv)[0] = basename(argv[0]);
> where basename() is defined in <libgen.h>:
> http://www.opengroup.org/onlinepubs/007904975/functions/basename.html
> 
> Dimitri
-- 
Martin 



More information about the distcc mailing list