diff options
| author | Craig Silverstein <csilvers@khanacademy.org> | 2008-04-11 22:36:40 +0000 |
|---|---|---|
| committer | Craig Silverstein <csilvers@khanacademy.org> | 2008-04-11 22:36:40 +0000 |
| commit | 596cf4e2f019a766965ad0566495c56b7d295fe4 (patch) | |
| tree | 1726969de95d86fc5647af1eeb99ea0489ba91c4 /src/cpp.c | |
| parent | 0a38eace37b20a663b235fb20107829e22fbeb43 (diff) | |
| download | distcc-git-596cf4e2f019a766965ad0566495c56b7d295fe4.tar.gz | |
The first step of moving everything in the distcc directory to the top
level. I'm doing this in two stages, because I don't understand svn
enough to be confident to do it in one. This first stage just copies
all the files from distcc/FOO to FOO. Now there are two copies of
each file under distcc; the Makefile/etc uses the one in distcc and
ignores the one at the top level.
The next commit will delete everything under distcc, and rewrite the
Makefile/etc to use the top-level versions instead.
Diffstat (limited to 'src/cpp.c')
| -rw-r--r-- | src/cpp.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/cpp.c b/src/cpp.c new file mode 100644 index 0000000..f82c8a3 --- /dev/null +++ b/src/cpp.c @@ -0,0 +1,103 @@ +/* -*- c-file-style: "java"; indent-tabs-mode: nil; fill-column: 78 -*- + * + * distcc -- A simple distributed compiler system + * + * Copyright (C) 2002, 2003 by Martin Pool <mbp@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 + */ + +/** + * @file + * + * Run the preprocessor. Client-side only. + **/ + +#include "config.h" + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#include "distcc.h" +#include "trace.h" +#include "exitcode.h" +#include "util.h" +#include "implicit.h" +#include "exec.h" + + +/** + * If the input filename is a plain source file rather than a + * preprocessed source file, then preprocess it to a temporary file + * and return the name in @p cpp_fname. + * + * The preprocessor may still be running when we return; you have to + * wait for @p cpp_fid to exit before the output is complete. This + * allows us to overlap opening the TCP socket, which probably doesn't + * use many cycles, with running the preprocessor. + **/ +int dcc_cpp_maybe(char **argv, char *input_fname, char **cpp_fname, + pid_t *cpp_pid) +{ + char **cpp_argv; + int ret; + char *input_exten; + const char *output_exten; + + *cpp_pid = 0; + + if (dcc_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"); + + /* already preprocessed, great. */ + if (!(*cpp_fname = strdup(input_fname))) { + rs_log_error("couldn't duplicate string"); + return EXIT_OUT_OF_MEMORY; + } + return 0; + } + + input_exten = dcc_find_extension(input_fname); + output_exten = dcc_preproc_exten(input_exten); + if ((ret = dcc_make_tmpnam("distcc", output_exten, cpp_fname))) + return ret; + + /* We strip the -o option and allow cpp to write to stdout, which is + * caught in a file. Sun cc doesn't understand -E -o, and gcc screws up + * -MD -E -o. + * + * There is still a problem here with -MD -E -o, gcc writes dependencies + * to a file determined by the source filename. We could fix it by + * generating a -MF option, but that would break compilation with older + * versions of gcc. This is only a problem for people who have the source + * 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"))) + return ret; + + /* FIXME: cpp_argv is leaked */ + + return dcc_spawn_child(cpp_argv, cpp_pid, + "/dev/null", *cpp_fname, NULL); +} + + |
