[distcc] Multicompiler Support (non garbled message)

Tom Aratyn themystic.ca at gmail.com
Wed Oct 11 01:05:24 GMT 2006


Hello Everyone,

Sorry about the previous two messages and the mess up with message being 
missing. It seems like gmail sends really fancy messages. Let's hope 
this goes better...

We feel we have a patch that provides multicompiler support. What we 
mean by this is that if you want distcc to work with your compiler there 
is a series of functions you can write and distcc will work natively 
with your compiler (note: this is not necessarily easy, you need certain 
level of familiarity with your compiler). Our earlier patch had some 
major issues which we have solved.

We would like to invite everyone to help us double check our patch. 
We're offering binaries (linux and windows... mac coming soon!) at 
http://www.foobartastic.com/multicompiler-support-for-distcc/, svn 
access to the latest version of distcc with our patch (at 
svn://cdot.senecac.on.ca/distcc/branches/multiCompilerSupport/), we've 
also attached the patch here. If there are any issues please let us 
know, or if there is something we can do help getting this into the 
trunk of distcc for the next release we really want to help with that.

We will now go forward with adding cl support and would like to get 
feedback from anyone else who is trying to add support for another 
compiler.

Tom and Cesar

P.S. this screwup with the emails was my fault - Tom.
-------------- next part --------------
Index: trunk/test/testdistcc.py
===================================================================
--- trunk/test/testdistcc.py	(revision 4)
+++ trunk/test/testdistcc.py	(working copy)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.2
+#! /usr/bin/env python2.4
 
 # Copyright (C) 2002, 2003, 2004 by Martin Pool <mbp at samba.org>
 # 
@@ -524,7 +524,7 @@
    4 SSH (no-user) angry /usr/sbin/distccd
    4 TCP localhostbutnotreally 3632
 """
-        out, err = self.runcmd("DISTCC_HOSTS=\"%s\" h_hosts" % spec)
+        out, err = self.runcmd(("DISTCC_HOSTS=\"%s\" h_hosts " % spec)+ _gcc)
         assert out == expected, "expected %s\ngot %s" % (`expected`, `out`)
 
 
@@ -862,7 +862,6 @@
         else:
             self.runcmd("distcc false -c testtmp.i", 1)
 
-
 class BinTrue_Case(Compilation_Case):
     """Compiler that succeeds without reading input.
 
Index: trunk/Makefile.in
===================================================================
--- trunk/Makefile.in	(revision 4)
+++ trunk/Makefile.in	(working copy)
@@ -166,20 +166,21 @@
 	src/lock.o							\
 	src/netutil.o							\
 	src/pump.o							\
-	src/sendfile.o							\
+	src/sendfile.o	src/loadfile.o			\
 	src/safeguard.o src/snprintf.o src/timeval.o			\
-	lzo/minilzo.o
+	lzo/minilzo.o  							\
+	src/compiler.o src/hosts.o src/hostfile.o      \
+	src/strip.o
 
 distcc_obj = src/backoff.o						\
 	src/climasq.o src/clinet.o src/clirpc.o				\
 	src/compile.o src/cpp.o						\
 	src/distcc.o							\
-	src/hosts.o src/hostfile.o					\
-	src/implicit.o src/loadfile.o					\
+	src/implicit.o 					\
 	src/remote.o							\
-	src/ssh.o src/state.o src/strip.o				\
+	src/ssh.o src/state.o 				\
 	src/timefile.o src/traceenv.o					\
-	src/where.o							\
+	src/where.o 						\
 	$(common_obj)
 
 distccd_obj = src/access.o						\
@@ -205,12 +206,11 @@
 	src/renderer.o
 
 h_exten_obj = src/h_exten.o $(common_obj)
-h_issource_obj = src/h_issource.o $(common_obj) 
-h_scanargs_obj = src/h_scanargs.o $(common_obj) src/implicit.o
-h_hosts_obj = src/h_hosts.o $(common_obj) src/hostfile.o src/hosts.o	\
-	src/loadfile.o
+h_issource_obj = src/h_issource.o $(common_obj)
+h_scanargs_obj = src/h_scanargs.o $(common_obj) src/implicit.o 
+h_hosts_obj = src/h_hosts.o $(common_obj) src/implicit.o 
 h_argvtostr_obj = src/h_argvtostr.o $(common_obj)
-h_strip_obj = src/h_strip.o $(common_obj) src/strip.o
+h_strip_obj = src/h_strip.o $(common_obj)
 h_parsemask_obj = src/h_parsemask.o $(common_obj) src/access.o
 h_sa2str_obj = src/h_sa2str.o $(common_obj) src/srvnet.o src/access.o
 h_ccvers_obj = src/h_ccvers.o $(common_obj) 
@@ -239,7 +239,8 @@
 	src/srvnet.c src/srvrpc.c src/ssh.c src/strip.c			\
 	src/tempfile.c src/timefile.c                     		\
 	src/timeval.c src/traceenv.c					\
-	src/trace.c src/util.c src/where.c				
+	src/trace.c src/util.c src/where.c				\
+	src/compiler.c
 
 
 HEADERS = src/access.h							\
@@ -255,7 +256,8 @@
 	src/timefile.h src/timeval.h src/trace.h			\
 	src/types.h							\
 	src/util.h							\
-	src/exec.h src/lock.h src/where.h src/srvnet.h
+	src/exec.h src/lock.h src/where.h src/srvnet.h \
+	src/compiler.h
 
 man1_MEN = man/distcc.1 man/distccd.1 man/distccmon-text.1 
 man_HTML = man/distcc_1.html man/distccd_1.html man/distccmon_text_1.html
Index: trunk/src/h_hosts.c
===================================================================
--- trunk/src/h_hosts.c	(revision 4)
+++ trunk/src/h_hosts.c	(working copy)
@@ -58,26 +58,38 @@
 #include "util.h"
 #include "hosts.h"
 #include "exitcode.h"
+#include "implicit.h"
+#include "compiler.h"
 
+struct dcc_compilerFunctions dcc_compiler;
 const char *rs_program_name = "h_hosts";
 
-int main(int UNUSED(argc), char **argv)
+int main(int argc, char **argv)
 {
     struct dcc_hostdef *list, *e;
     int nhosts, i;
     int ret;
+    char **newargv = NULL;
 
     rs_add_logger(rs_logger_file, RS_LOG_DEBUG, NULL, STDERR_FILENO);
 
-    if (argv[1] && !strcmp(argv[1], "-v")) {
+    if (argc > 3) {
+        return 1;
+    }
+    else if (argc == 3 && !strcmp(argv[1], "-v")) {
         rs_trace_set_level(RS_LOG_DEBUG);
     }
     
-    if ((ret = dcc_get_hostlist(&list, &nhosts)) != 0) {
+    if ((ret = dcc_set_compiler(argv)))
+    	return ret;
+    
+    if ((ret = dcc_find_compiler(argv, &newargv)))
+    	return ret;
+    
+    if ((ret = dcc_compiler.get_hostlist(&list, &nhosts)) != 0) {
         rs_log_error("failed to parse \"%s\"", getenv("DISTCC_HOSTS"));
         exit(ret);
     }
-
     printf("%d\n", nhosts);
     for (i = 0, e = list; i < nhosts; i++, e = e->next) {
         if (!e) {
Index: trunk/src/h_strip.c
===================================================================
--- trunk/src/h_strip.c	(revision 4)
+++ trunk/src/h_strip.c	(working copy)
@@ -36,8 +36,10 @@
 #include "distcc.h"
 #include "trace.h"
 #include "util.h"
+#include "compiler.h"
 
 const char *rs_program_name = __FILE__;
+struct dcc_compilerFunctions dcc_compiler;
 
 
 /**
@@ -53,7 +55,11 @@
         return 1;
     }
 
-    if ((ret = dcc_strip_local_args(argv + 1, &new_args))) {
+    if ((ret = dcc_set_compiler(argv))){
+            return ret;
+    }
+
+    if ((ret = dcc_compiler.strip_local_args(argv + 1, &new_args))) {
         return ret;
     }
 
Index: trunk/src/arg.c
===================================================================
--- trunk/src/arg.c	(revision 4)
+++ trunk/src/arg.c	(working copy)
@@ -87,8 +87,8 @@
 #include "util.h"
 #include "exitcode.h"
 #include "snprintf.h"
+#include "compiler.h"
 
-
 static int dcc_argv_append(char *argv[], char *toadd)
 {
     int l = dcc_argv_len(argv);
@@ -120,7 +120,7 @@
  *
  * @returns 0 if it's ok to distribute this compilation, or an error code.
  **/
-int dcc_scan_args(char *argv[], char **input_file, char **output_file,
+int dcc_gcc_scan_args(char *argv[], char **input_file, char **output_file,
                   char ***ret_newargv)
 {
     int seen_opt_c = 0, seen_opt_s = 0;
@@ -207,7 +207,7 @@
                 goto GOT_OUTPUT;
             }
         } else {
-            if (dcc_is_source(a)) {
+            if (dcc_compiler.is_source(a)) {
                 rs_trace("found input file \"%s\"", a);
                 if (*input_file) {
                     rs_log_info("do we have two inputs?  i give up");
@@ -293,7 +293,7 @@
  * Used to change "-c" or "-S" to "-E", so that we get preprocessed
  * source.
  **/
-int dcc_set_action_opt(char **a, const char *new_c)
+int dcc_gcc_set_action_opt(char **a, const char *new_c)
 {
     int gotone = 0;
     
@@ -326,7 +326,7 @@
  * detected by dcc_scan_args(), it's also correctly identified here.
  * It might be better to make the code shared.
  **/
-int dcc_set_output(char **a, char *ofname)
+int dcc_gcc_set_output(char **a, char *ofname)
 {
     int i;
     
@@ -368,7 +368,7 @@
     int i;
 
     for (i =0; a[i]; i++)
-        if (dcc_is_source(a[i])) {
+        if (dcc_compiler.is_source(a[i])) {
             rs_trace("changed input from \"%s\" to \"%s\"", a[i], ifname);
             a[i] = ifname;
             dcc_trace_argv("command after", a);
Index: trunk/src/cpp.c
===================================================================
--- trunk/src/cpp.c	(revision 4)
+++ trunk/src/cpp.c	(working copy)
@@ -39,8 +39,8 @@
 #include "util.h"
 #include "implicit.h"
 #include "exec.h"
+#include "compiler.h"
 
-
 /**
  * If the input filename is a plain source file rather than a
  * preprocessed source file, then preprocess it to a temporary file
@@ -61,7 +61,7 @@
 
     *cpp_pid = 0;
     
-    if (dcc_is_preprocessed(input_fname)) {
+    if (dcc_compiler.is_preprocessed(input_fname)) {
         /* TODO: Perhaps also consider the option that says not to use cpp.
          * Would anyone do that? */
         rs_trace("input is already preprocessed");
@@ -75,7 +75,9 @@
     }
 
     input_exten = dcc_find_extension(input_fname);
-    output_exten = dcc_preproc_exten(input_exten);
+    
+    output_exten = dcc_compiler.preproc_exten(input_exten);
+
     if ((ret = dcc_make_tmpnam("distcc", output_exten, cpp_fname)))
         return ret;
 
@@ -90,8 +92,8 @@
      * and objects in different directories, and who don't specify -MF.  They
      * can fix it by specifying -MF.  */
     
-    if ((ret = dcc_strip_dasho(argv, &cpp_argv))
-        || (ret = dcc_set_action_opt(cpp_argv, "-E")))
+    if ((ret = dcc_compiler.strip_dasho(argv, &cpp_argv))
+        || (ret = dcc_compiler.set_action_opt(cpp_argv, "-E")))
         return ret;
 
     /* FIXME: cpp_argv is leaked */
Index: trunk/src/h_sa2str.c
===================================================================
--- trunk/src/h_sa2str.c	(revision 4)
+++ trunk/src/h_sa2str.c	(working copy)
@@ -52,8 +52,10 @@
 #include "access.h"
 #include "netutil.h"
 #include "snprintf.h"
+#include "compiler.h"
 
 const char *rs_program_name = "h_sa2str";
+struct dcc_compilerFunctions dcc_compiler;
 
 /* Try to print out a sockaddr */
 int main(void)
Index: trunk/src/hosts.c
===================================================================
--- trunk/src/hosts.c	(revision 4)
+++ trunk/src/hosts.c	(working copy)
@@ -127,7 +127,7 @@
  * taken from $DISTCC_DIR/hosts, if that exists.  Otherwise, they are taken
  * from ${sysconfdir}/distcc/hosts, if that exists.  Otherwise, we fail.
  **/
-int dcc_get_hostlist(struct dcc_hostdef **ret_list,
+int dcc_gcc_get_hostlist(struct dcc_hostdef **ret_list,
                      int *ret_nhosts)
 {
     char *env;
Index: trunk/src/strip.c
===================================================================
--- trunk/src/strip.c	(revision 4)
+++ trunk/src/strip.c	(working copy)
@@ -56,7 +56,7 @@
  * passed directly to cpp.  When given to gcc they have different
  * meanings.
  **/
-int dcc_strip_local_args(char **from, char ***out_argv)
+int dcc_gcc_strip_local_args(char **from, char ***out_argv)
 {
     char **to;
     int from_i, to_i;
@@ -136,7 +136,7 @@
  *
  * Structurally similar to dcc_strip_local_args()
  **/
-int dcc_strip_dasho(char **from, char ***out_argv)
+int dcc_gcc_strip_dasho(char **from, char ***out_argv)
 {
     char **to;
     int from_i, to_i;
Index: trunk/src/hosts.h
===================================================================
--- trunk/src/hosts.h	(revision 4)
+++ trunk/src/hosts.h	(working copy)
@@ -60,7 +60,7 @@
 
 
 /* hosts.c */
-int dcc_get_hostlist(struct dcc_hostdef **ret_list,
+int dcc_gcc_get_hostlist(struct dcc_hostdef **ret_list,
                      int *ret_nhosts);
 
 int dcc_free_hostdef(struct dcc_hostdef *host);
Index: trunk/src/where.c
===================================================================
--- trunk/src/where.c	(revision 4)
+++ trunk/src/where.c	(working copy)
@@ -75,6 +75,7 @@
 #include "lock.h"
 #include "where.h"
 #include "exitcode.h"
+#include "compiler.h"
 
 
 static int dcc_lock_one(struct dcc_hostdef *hostlist,
@@ -89,7 +90,7 @@
     int ret;
     int n_hosts;
     
-    if ((ret = dcc_get_hostlist(&hostlist, &n_hosts)) != 0) {
+    if ((ret = dcc_compiler.get_hostlist(&hostlist, &n_hosts)) != 0) {
         return EXIT_NO_HOSTS;
     }
 
Index: trunk/src/mon-text.c
===================================================================
--- trunk/src/mon-text.c	(revision 4)
+++ trunk/src/mon-text.c	(working copy)
@@ -106,7 +106,7 @@
         printf("\n");
 
         /* XXX: usleep() is probably not very portable */
-        usleep(delay * 1000000);
+        usleep((unsigned int)(delay * 1000000.0));
         
         dcc_task_state_free(list);
     } while (delay);
Index: trunk/src/where.h
===================================================================
--- trunk/src/where.h	(revision 4)
+++ trunk/src/where.h	(working copy)
@@ -21,7 +21,7 @@
  */
 
 /* where.c */
-int dcc_pick_host_from_list(struct dcc_hostdef **,
+int dcc_gcc_pick_host_from_list(struct dcc_hostdef **,
                             int *cpu_lock_fd);
 
 int dcc_lock_local(int *cpu_lock_fd);
Index: trunk/src/h_argvtostr.c
===================================================================
--- trunk/src/h_argvtostr.c	(revision 4)
+++ trunk/src/h_argvtostr.c	(working copy)
@@ -33,9 +33,10 @@
 #include "distcc.h"
 #include "trace.h"
 #include "util.h"
-
+#include "compiler.h"
 const char *rs_program_name = __FILE__;
 
+struct dcc_compilerFunctions dcc_compiler;
 
 /**
  * @file
Index: trunk/src/h_issource.c
===================================================================
--- trunk/src/h_issource.c	(revision 4)
+++ trunk/src/h_issource.c	(working copy)
@@ -36,24 +36,29 @@
 #include "distcc.h"
 #include "trace.h"
 #include "util.h"
+#include "compiler.h"
 
-
 const char *rs_program_name = __FILE__;
 
+struct dcc_compilerFunctions dcc_compiler;
 
 /**
  * Test harness: determine whether a file is source, and is preprocessed.
  **/
 int main(int argc, char *argv[])
 {
+    int result;
+
     if (argc != 2) {
-        rs_log_error("usage: %s FILENAME", argv[0]);
+        rs_log_error("usage: %s <compiler> FILENAME", argv[0]);
         return 1;
     }
+    if ((result = dcc_set_compiler(argv)))
+        return result;
 
     printf("%s %s\n",
-	   dcc_is_source(argv[1]) ? "source" : "not-source",
-	   dcc_is_preprocessed(argv[1]) ? "preprocessed" : "not-preprocessed");
+	   dcc_compiler.is_source(argv[1]) ? "source" : "not-source",
+	   dcc_compiler.is_preprocessed(argv[1]) ? "preprocessed" : "not-preprocessed");
     
     return 0;
 }
Index: trunk/src/daemon.c
===================================================================
--- trunk/src/daemon.c	(revision 4)
+++ trunk/src/daemon.c	(working copy)
@@ -75,11 +75,12 @@
 #include "srvnet.h"
 #include "daemon.h"
 #include "types.h"
+#include "compiler.h"
 
-
 /* for trace.c */
 char const *rs_program_name = "distccd";
 
+struct dcc_compilerFunctions dcc_compiler;
 
 static int dcc_inetd_server(void);
 static void dcc_setup_real_log(void);
Index: trunk/src/distcc.c
===================================================================
--- trunk/src/distcc.c	(revision 4)
+++ trunk/src/distcc.c	(working copy)
@@ -48,11 +48,12 @@
 #include "bulk.h"
 #include "implicit.h"
 #include "compile.h"
+#include "compiler.h"
 
-
 /* Name of this program, for trace.c */
 const char *rs_program_name = "distcc";
 
+struct dcc_compilerFunctions dcc_compiler;
 
 /**
  * @file
@@ -159,6 +160,10 @@
     dcc_set_trace_from_env();
 
     dcc_trace_version();
+    
+    if (ret = dcc_set_compiler(argv)){
+        goto out;
+    }
 
     compiler_name = (char *) dcc_find_basename(argv[0]);
 
Index: trunk/src/exitcode.h
===================================================================
--- trunk/src/exitcode.h	(revision 4)
+++ trunk/src/exitcode.h	(working copy)
@@ -54,7 +54,9 @@
     EXIT_NO_SUCH_FILE             = 115,
     EXIT_NO_HOSTS                 = 116,
     EXIT_GONE                     = 117, /**< No longer relevant */
-    EXIT_TIMEOUT                  = 118
+    EXIT_TIMEOUT                  = 118,
+    EXIT_NO_COMPILER_SETTING      = 119  /**< distcc was not able to set a 
+                                              compiler. */
 };
 
 
Index: trunk/src/implicit.c
===================================================================
--- trunk/src/implicit.c	(revision 4)
+++ trunk/src/implicit.c	(working copy)
@@ -40,9 +40,9 @@
 #include "exitcode.h"
 #include "util.h"
 #include "implicit.h"
+#include "compiler.h"
 
 
-
 /**
  * @file
  *
@@ -80,8 +80,8 @@
 int dcc_find_compiler(char **argv, char ***out_argv)
 {
     if (argv[1][0] == '-'
-        || dcc_is_source(argv[1])
-        || dcc_is_object(argv[1])) {
+        || dcc_compiler.is_source(argv[1])
+        || dcc_compiler.is_object(argv[1])) {
         dcc_copy_argv(argv, out_argv, 0);
 
         /* change "distcc -c foo.c" -> "cc -c foo.c" */
Index: trunk/src/distcc.h
===================================================================
--- trunk/src/distcc.h	(revision 4)
+++ trunk/src/distcc.h	(working copy)
@@ -208,10 +208,10 @@
                    double *rate);
 
 /* arg.c */
-int dcc_set_action_opt(char **, const char *);
-int dcc_set_output(char **, char *);
+int dcc_gcc_set_action_opt(char **, const char *);
+int dcc_gcc_set_output(char **, char *);
 int dcc_set_input(char **, char *);
-int dcc_scan_args(char *argv[], /*@out@*/ /*@relnull@*/ char **orig_o,
+int dcc_gcc_scan_args(char *argv[], /*@out@*/ /*@relnull@*/ char **orig_o,
                   char **orig_i, char ***ret_newargv);
 
 /* argutil.c */
@@ -236,24 +236,24 @@
 int dcc_add_cleanup(char *filename) WARN_UNUSED;
 
 /* strip.c */
-int dcc_strip_local_args(char **from, char ***out_argv);
-int dcc_strip_dasho(char **from, char ***out_argv);
+int dcc_gcc_strip_local_args(char **from, char ***out_argv);
+int dcc_gcc_strip_dasho(char **from, char ***out_argv);
 
 /* cpp.c */
 int dcc_cpp_maybe(char **argv, char *input_fname, char **cpp_fname,
 		  pid_t *cpp_pid);
 
 /* filename.c */
-int dcc_is_source(const char *sfile);
-int dcc_is_preprocessed(const char *sfile);
-int dcc_is_object(const char *filename);
+int dcc_gcc_is_source(const char *sfile);
+int dcc_gcc_is_preprocessed(const char *sfile);
+int dcc_gcc_is_object(const char *filename);
 int dcc_source_needs_local(const char *);
 
 char * dcc_find_extension(char *sfile);
 int dcc_output_from_source(const char *sfile, const char *out_extn,
                            char **ofile);
 
-const char * dcc_preproc_exten(const char *e);
+const char * dcc_gcc_preproc_exten(const char *e);
 const char * dcc_find_basename(const char *sfile);
 
 
Index: trunk/src/serve.c
===================================================================
--- trunk/src/serve.c	(revision 4)
+++ trunk/src/serve.c	(working copy)
@@ -83,6 +83,7 @@
 #include "srvnet.h"
 #include "hosts.h"
 #include "daemon.h"
+#include "compiler.h"
 
 
 /**
@@ -171,7 +172,7 @@
     rs_trace("input file %s", orig_input);
     input_exten = dcc_find_extension(orig_input);
     if (input_exten)
-        input_exten = dcc_preproc_exten(input_exten);
+        input_exten = dcc_compiler.preproc_exten(input_exten);
     if (!input_exten)           /* previous line might return NULL */
         input_exten = ".tmp";
     return dcc_make_tmpnam("distccd", input_exten, tmpnam_ret);
@@ -283,10 +284,14 @@
     tcp_cork_sock(out_fd, 1);
 
     if ((ret = dcc_r_request_header(in_fd, &protover))
-        || (ret = dcc_r_argv(in_fd, &argv))
-        || (ret = dcc_scan_args(argv, &orig_input, &orig_output, &argv)))
+        || (ret = dcc_r_argv(in_fd, &argv)))
         goto out_cleanup;
-    
+
+    if ((ret = dcc_set_compiler(argv)) ||
+        (ret = dcc_compiler.scan_args(argv, &orig_input, &orig_output, &argv)))
+        goto out_cleanup;
+
+   
     rs_trace("output file %s", orig_output);
 
     if ((ret = dcc_input_tmpnam(orig_input, &temp_i)))
@@ -298,15 +303,18 @@
 
     if ((ret = dcc_r_token_file(in_fd, "DOTI", temp_i, compr))
         || (ret = dcc_set_input(argv, temp_i))
-        || (ret = dcc_set_output(argv, temp_o)))
+        || (ret = dcc_compiler.set_output(argv, temp_o)))
         goto out_cleanup;
 
     if ((ret = dcc_check_compiler_masq(argv[0])))
         goto out_cleanup;
 
+    if ((ret = dcc_set_compiler(argv)))
+        goto out_cleanup;
+
     if ((compile_ret = dcc_spawn_child(argv, &cc_pid,
                                        "/dev/null", out_fname, err_fname))
-        || (compile_ret = dcc_collect_child("cc", cc_pid, &status))) {
+        || (compile_ret = dcc_collect_child(argv[0], cc_pid, &status))) {
         /* We didn't get around to finding a wait status from the actual compiler */
         status = W_EXITCODE(compile_ret, 0);
     }
Index: trunk/src/compile.c
===================================================================
--- trunk/src/compile.c	(revision 4)
+++ trunk/src/compile.c	(working copy)
@@ -44,6 +44,7 @@
 #include "lock.h"
 #include "timeval.h"
 #include "compile.h"
+#include "compiler.h"
 
 
 /**
@@ -124,7 +125,7 @@
 
     /* TODO: Perhaps tidy up these gotos. */
 
-    if (dcc_scan_args(argv, &input_fname, &output_fname, &argv) != 0) {
+    if (dcc_compiler.scan_args(argv, &input_fname, &output_fname, &argv) != 0) {
         /* we need to scan the arguments even if we already know it's
          * local, so that we can pick up distcc client options. */
         goto lock_local;
@@ -149,7 +150,7 @@
     if ((ret = dcc_cpp_maybe(argv, input_fname, &cpp_fname, &cpp_pid) != 0))
         goto fallback;
 
-    if ((ret = dcc_strip_local_args(argv, &argv_stripped)))
+    if ((ret = dcc_compiler.strip_local_args(argv, &argv_stripped)))
         goto fallback;
 
     /* FIXME: argv_stripped is leaked. */
Index: trunk/src/h_scanargs.c
===================================================================
--- trunk/src/h_scanargs.c	(revision 4)
+++ trunk/src/h_scanargs.c	(working copy)
@@ -1,25 +1,25 @@
 /* -*- c-file-style: "java"; indent-tabs-mode: nil -*- 
- *
- * distcc -- A simple distributed compiler system
- * $Header: /data/cvs/distcc/src/h_scanargs.c,v 1.9 2003/07/13 08:08:02 mbp Exp $ 
- *
- * Copyright (C) 2002 by Martin Pool <mbp at samba.org>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
+*
+* distcc -- A simple distributed compiler system
+* $Header: /data/cvs/distcc/src/h_scanargs.c,v 1.9 2003/07/13 08:08:02 mbp Exp $ 
+*
+* Copyright (C) 2002 by Martin Pool <mbp at samba.org>
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License as
+* published by the Free Software Foundation; either version 2 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* General Public License for more details.
+* 
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+* USA
+*/
 
 #include "config.h"
 
@@ -36,10 +36,11 @@
 #include "trace.h"
 #include "util.h"
 #include "implicit.h"
+#include "compiler.h"
 
+struct dcc_compilerFunctions dcc_compiler;
 const char *rs_program_name = __FILE__;
 
-
 /**
  * Test harness: make argument-parsing code accessible from the
  * command line so that it can be tested.
@@ -53,17 +54,21 @@
     rs_trace_set_level(RS_LOG_DEBUG);
 
     if (argc < 2) {
-	rs_log_error("usage: h_scanargs COMMAND ARG...\n");
-	return 1;
+    	rs_log_error("usage: h_scanargs COMMAND ARG...\n");
+	    return 1;
     }
 
+    if ((result = dcc_set_compiler(argv)))
+    	return result;
+
     result = dcc_find_compiler(argv, &newargv);
 
     if (result)
 	return result;
 
-    result = dcc_scan_args(newargv, &infname, &outfname, &outargv);
 
+   result = dcc_compiler.scan_args(newargv, &infname, &outfname, &outargv);
+
     printf("%s %s %s\n",
 	   result == 0 ? "distribute" : "local",
 	   infname ? infname : "(NULL)", outfname ? outfname : "(NULL)");
Index: trunk/src/filename.c
===================================================================
--- trunk/src/filename.c	(revision 4)
+++ trunk/src/filename.c	(working copy)
@@ -133,7 +133,7 @@
  * @returns preprocessed extension, (e.g. ".i"), or NULL if
  * unrecognized.
  **/
-const char * dcc_preproc_exten(const char *e)
+const char * dcc_gcc_preproc_exten(const char *e)
 {
     if (e[0] != '.')
         return NULL;
@@ -162,7 +162,7 @@
  * Does the extension of this file indicate that it is already
  * preprocessed?
  **/
-int dcc_is_preprocessed(const char *sfile)
+int dcc_gcc_is_preprocessed(const char *sfile)
 {
     const char *dot, *ext;
     dot = dcc_find_extension((char *) sfile);
@@ -191,7 +191,7 @@
 /**
  * Work out whether @p sfile is source based on extension
  **/
-int dcc_is_source(const char *sfile)
+int dcc_gcc_is_source(const char *sfile)
 {
     const char *dot, *ext;
     dot = dcc_find_extension((char *) sfile);
@@ -239,7 +239,7 @@
  * Decide whether @p filename is an object file, based on its
  * extension.
  **/
-int dcc_is_object(const char *filename)
+int dcc_gcc_is_object(const char *filename)
 {
     const char *dot;
     dot = dcc_find_extension((char *) filename);
Index: trunk/src/h_exten.c
===================================================================
--- trunk/src/h_exten.c	(revision 4)
+++ trunk/src/h_exten.c	(working copy)
@@ -36,10 +36,11 @@
 #include "distcc.h"
 #include "trace.h"
 #include "util.h"
+#include "compiler.h"
 
 
-
 const char *rs_program_name = __FILE__;
+struct dcc_compilerFunctions dcc_compiler;
 
 /**
  * Test harness that makes sure the filename extension manipulation
Index: trunk/src/h_parsemask.c
===================================================================
--- trunk/src/h_parsemask.c	(revision 4)
+++ trunk/src/h_parsemask.c	(working copy)
@@ -36,8 +36,10 @@
 #include "trace.h"
 #include "exitcode.h"
 #include "access.h"
+#include "compiler.h"
 
 const char * rs_program_name = "h_parsemask";
+struct dcc_compilerFunctions dcc_compiler;
 
 int main(int argc, char **argv)
 {
Index: trunk/src/compiler.c
===================================================================
--- trunk/src/compiler.c	(revision 0)
+++ trunk/src/compiler.c	(revision 56)
@@ -0,0 +1,43 @@
+#include <string.h>
+
+#include "distcc.h"
+#include "hosts.h"
+#include "compiler.h"
+#include "exitcode.h"
+#include "trace.h"
+
+int dcc_set_compiler (const char **argv){
+
+    const char * name;
+
+    if (!argv) {
+        return EXIT_NO_COMPILER_SETTING;
+    }
+    
+    if (0) {
+    }
+    /* If you wish to add a compiler please add an else if here in the following form:
+     * else if (strcmp(name, "foocc") == 0) {
+     *     //vtable assignments...
+     * } 
+     */
+    else {
+        /* Assume masquerade mode. The only compiler allowed to do this is gcc 
+         * to maintain backwards compatibility. */
+        
+        rs_log_info("Using gcc settings.");
+
+        dcc_compiler.scan_args = dcc_gcc_scan_args;
+        dcc_compiler.get_hostlist = dcc_gcc_get_hostlist;
+        dcc_compiler.preproc_exten = dcc_gcc_preproc_exten;
+        dcc_compiler.is_source = dcc_gcc_is_source;
+        dcc_compiler.strip_dasho = dcc_gcc_strip_dasho;
+        dcc_compiler.is_object = dcc_gcc_is_object;
+        dcc_compiler.strip_local_args = dcc_gcc_strip_local_args;
+        dcc_compiler.set_action_opt = dcc_gcc_set_action_opt;
+        dcc_compiler.set_output = dcc_gcc_set_output;
+        dcc_compiler.is_preprocessed = dcc_gcc_is_preprocessed;
+    }
+    return 0;
+}
+
Index: trunk/src/compiler.h
===================================================================
--- trunk/src/compiler.h	(revision 0)
+++ trunk/src/compiler.h	(revision 56)
@@ -0,0 +1,58 @@
+/* -*- c-file-style: "java"; indent-tabs-mode: nil -*-
+ * 
+ * distcc -- A simple distributed compiler system
+ *
+ * Copyright (C) 2006 by Tom Aratyn (themystic.ca at gmail.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+
+#ifndef _DCC_COMPILER_H__
+#define _DCC_COMPILER_H__
+
+
+/**
+ * This struct holds pointers to all compiler specific functions. 
+ */
+struct dcc_compilerFunctions {
+
+    int (*scan_args)(char *argv[], char **input_file, char **output_file,
+        char ***ret_newargv);
+
+    /* For comapatability reasons, please use dcc_parse_hosts_file() when 
+     * writting your own version of this
+     */
+    int (*get_hostlist)(struct dcc_hostdef **ret_list, int *ret_nhosts);
+    const char * (*preproc_exten)(const char *e);
+    int (*is_source)(const char *sfile);
+    int (*strip_dasho)(char **from, char ***out_argv);
+    int (*is_object)(const char *filename);
+    int (*strip_local_args)(char **from, char ***out_argv);
+    int (*set_action_opt)(char **a, const char *new_c);
+    int (*set_output)(char **a, char *ofname);
+    int (*is_preprocessed)(const char *sfile);
+};
+
+extern struct dcc_compilerFunctions dcc_compiler;
+
+/**
+ * This function checks which compiler is being used and sets the compiler
+ * specific functions inside of dcc_compiler.
+ */
+int dcc_set_compiler(const char ** argv);
+
+#endif


More information about the distcc mailing list