Adding Compilers to Distcc
Distcc now has support for muliple compilers (not just gcc). Most of distcc is compiler agnostic, however certain parts obviously can't be.
distcc code standards
- All distcc functions are prefixed with dcc_.
- All words are seperated by underscores. notCamelCase.
- All compiler specific functions are prefixed with dcc_<compilerName> (e.g. dcc_cl_, dcc_gcc_, etc.)
How a compiler is chosen
One of the first functions called is dcc_set_compiler(char**) - defined in compiler.c. This function is responsible for checking argv and finding out which compiler is being used. Once a compiler is found, distcc must be configured to use that compiler specific code. This is done via a series of if else if statements. distcc defaults to gcc when a compiler is not recognized. When adding a new compiler you will have to add a new else if statement to assign values to the vtable.
The vtable is a struct consisting of a bunch of function pointers (and a char array). When distcc runs it uses an instance of this struct to call the compiler specific functions. The function pointers point to the various dcc_<compilerName> functions. The char array holds options that the compiler uses to run the preprocessor.
It is recommend that you initially use the provided dummy function to be able to test the code as you write it without waiting until everything is written.
Compiler specific functions
Here are the compiler specific functions:
- Make sure that argv has an “action option”. This is meant to be used on the client side to run the preprocessor.
- Change the output filenames (e.g. the name of the objet files) in argv.
- Check the arguments and see if the job can be distributed.
- Strip all the local arguments out of argv. “local arguments” are usually arguments that get passed to the preprocessor.
- We don't want the preprocessor output going anywhere except stdout.
- Check whether a given filename is a source filename. This is generally done via a filename extension.
- check whether a file has been preprocessed. this is generally done via a filename extension
- check whether a file is a compiled object file. this is generally done via a filename extension
- Return the extension of a preprocessed extension file.
- Return a list of hosts to which it is possible to distribute. This is usually gotten from an environment variable.
Notes for new compiler porters
Distcc assumes that you'll need to pass your code through a preprocessor. This may not be the case for all languages. You can probably get away with just returning 0 and basically leaving those functions empty. You will also want to hold your host list in a different environment variable.