2
Copyright (C) Andrew Tridgell 2002
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2
* Copyright (C) Andrew Tridgell 2002
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the Free
6
* Software Foundation; either version 3 of the License, or (at your option)
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
* You should have received a copy of the GNU General Public License along with
15
* this program; if not, write to the Free Software Foundation, Inc., 51
16
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
#include "ccache.h"
21
#include <sys/types.h>
23
32
execute a compiler backend, capturing all output to the given paths
24
33
the full path to the compiler to run is in argv[0]
26
int execute(char **argv,
35
int execute(char **argv,
27
36
const char *path_stdout,
28
37
const char *path_stderr)
42
cc_log_executed_command(argv);
34
45
if (pid == -1) fatal("Failed to fork");
39
50
unlink(path_stdout);
40
51
fd = open(path_stdout, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0666);
85
96
path = getenv("PATH");
88
cc_log("no PATH variable!?\n");
99
cc_log("No PATH variable");
92
103
path = x_strdup(path);
94
105
/* search the path looking for the first compiler of the right name
96
107
for (tok=strtok(path,":"); tok; tok = strtok(NULL, ":")) {
106
117
if (S_ISLNK(st1.st_mode)) {
107
118
char *buf = x_realpath(fname);
109
char *p = str_basename(buf);
120
char *p = basename(buf);
110
121
if (strcmp(p, exclude_name) == 0) {
111
122
/* its a link to "ccache" ! */
142
void print_command(FILE *fp, char **argv)
145
for (i = 0; argv[i]; i++) {
146
fprintf(fp, "%s%s", (i == 0) ? "" : " ", argv[i]);
151
void print_executed_command(FILE *fp, char **argv)
153
fprintf(fp, "%s: executing ", MYNAME);
154
print_command(fp, argv);