annotate lib/swig/swigwin-2.0.11/CCache/ccache.c @ 2455:51d4f38aca6c

audio through OpenAL (begining)
author Ritor1
date Fri, 25 Jul 2014 17:49:20 +0600
parents b3009adc0e2f
children
rev   line source
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2 a re-implementation of the compilercache scripts in C
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
3
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
4 The idea is based on the shell-script compilercache by Erik Thiele <erikyyy@erikyyy.de>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
5
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
6 Copyright (C) Andrew Tridgell 2002
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
7 Copyright (C) Martin Pool 2003
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
8
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
9 This program is free software; you can redistribute it and/or modify
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10 it under the terms of the GNU General Public License as published by
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11 the Free Software Foundation; either version 2 of the License, or
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12 (at your option) any later version.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
14 This program is distributed in the hope that it will be useful,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
17 GNU General Public License for more details.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20 along with this program; if not, write to the Free Software
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24 #include "ccache.h"
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26 /* verbose mode */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 int ccache_verbose = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 /* the base cache directory */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30 char *cache_dir = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32 /* the directory for temporary files */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33 static char *temp_dir = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35 /* the debug logfile name, if set */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36 char *cache_logfile = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
38 /* the argument list after processing */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
39 static ARGS *stripped_args;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
40
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
41 /* the original argument list */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42 static ARGS *orig_args;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 /* the output filename being compiled to */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45 static char *output_file;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47 /* the source file */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48 static char *input_file;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50 /* the name of the file containing the cached object code */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51 static char *hashname;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53 /* the extension of the file after pre-processing */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54 static const char *i_extension;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56 /* the name of the temporary pre-processor file */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57 static char *i_tmpfile;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
58
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
59 /* are we compiling a .i or .ii file directly? */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
60 static int direct_i_file;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 /* the name of the cpp stderr file */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63 static char *cpp_stderr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
64
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
65 /* the name of the statistics file */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
66 char *stats_file = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
67
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
68 /* can we safely use the unification hashing backend? */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
69 static int enable_unify;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
70
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
71 /* should we strip -c when running the preprocessor only? */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
72 static int strip_c_option;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
73
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
74 /* customisation for using the SWIG compiler */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
75 static int swig;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
76
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
77 /* a list of supported file extensions, and the equivalent
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
78 extension for code that has been through the pre-processor
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
79 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
80 static struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
81 char *extension;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
82 char *i_extension;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
83 } extensions[] = {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
84 {"c", "i"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
85 {"C", "ii"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
86 {"m", "mi"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
87 {"cc", "ii"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
88 {"CC", "ii"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
89 {"cpp", "ii"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
90 {"CPP", "ii"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
91 {"cxx", "ii"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
92 {"CXX", "ii"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
93 {"c++", "ii"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
94 {"C++", "ii"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
95 {"i", "i"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
96 {"ii", "ii"},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
97 {NULL, NULL}};
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
98
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
99 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
100 something went badly wrong - just execute the real compiler
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
101 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
102 static void failed(void)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
103 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
104 char *e;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
105
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
106 /* delete intermediate pre-processor file if needed */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
107 if (i_tmpfile) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
108 if (!direct_i_file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
109 unlink(i_tmpfile);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
110 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
111 free(i_tmpfile);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
112 i_tmpfile = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
113 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
114
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
115 /* delete the cpp stderr file if necessary */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
116 if (cpp_stderr) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
117 unlink(cpp_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
118 free(cpp_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
119 cpp_stderr = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
120 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
121
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
122 /* strip any local args */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
123 args_strip(orig_args, "--ccache-");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
124
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
125 if ((e=getenv("CCACHE_PREFIX"))) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
126 char *p = find_executable(e, MYNAME);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
127 if (!p) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
128 cc_log("could not find executable (%s)\n", e);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
129 perror(e);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
130 exit(1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
131 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
132 args_add_prefix(orig_args, p);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
133 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
134
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
135 if (ccache_verbose) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
136 display_execute_args(orig_args->argv);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
137 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
138
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
139 if (swig) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
140 putenv("CCACHE_OUTFILES");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
141 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
142
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
143 #ifndef _WIN32
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
144 execv(orig_args->argv[0], orig_args->argv);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
145 cc_log("execv returned (%s)!\n", strerror(errno));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
146 perror(orig_args->argv[0]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
147 exit(1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
148 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
149 /* execv on Windows causes the 'non-regular' testcase to fail, so use Win32 API instead */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
150 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
151 PROCESS_INFORMATION pinfo;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
152 STARTUPINFO sinfo;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
153 BOOL ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
154 DWORD exitcode;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
155 char *args;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
156
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
157 ZeroMemory(&pinfo, sizeof(PROCESS_INFORMATION));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
158 ZeroMemory(&sinfo, sizeof(STARTUPINFO));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
159 sinfo.cb = sizeof(STARTUPINFO);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
160 args = argvtos(orig_args->argv);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
161 ret = CreateProcessA(orig_args->argv[0], args, NULL, NULL, TRUE, 0, NULL, NULL,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
162 &sinfo, &pinfo);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
163 if (!ret) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
164 exitcode = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
165 cc_log("CreateProcessA failed starting %s\n", orig_args->argv[0]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
166 perror_win32(orig_args->argv[0]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
167 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
168 WaitForSingleObject(pinfo.hProcess, INFINITE);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
169 GetExitCodeProcess(pinfo.hProcess, &exitcode);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
170 CloseHandle(pinfo.hProcess);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
171 CloseHandle(pinfo.hThread);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
172 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
173 free(args);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
174 exit(exitcode);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
175 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
176 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
177 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
178
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
179
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
180 /* return a string to be used to distinguish temporary files
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
181 this also tries to cope with NFS by adding the local hostname
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
182 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
183 static const char *tmp_string(void)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
184 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
185 static char *ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
186
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
187 if (!ret) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
188 char hostname[200];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
189 strcpy(hostname, "unknown");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
190 #if HAVE_GETHOSTNAME
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
191 gethostname(hostname, sizeof(hostname)-1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
192 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
193 hostname[sizeof(hostname)-1] = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
194 if (asprintf(&ret, "%s.%u", hostname, (unsigned)getpid()) == -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
195 fatal("could not allocate tmp_string");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
196 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
197 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
198
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
199 return ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
200 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
201
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
202 /* update cached file sizes and count helper function for to_cache() */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
203 static void to_cache_stats_helper(struct stat *pstat, char *cached_filename, char *tmp_outfiles, int *files_size, int *cached_files_count)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
204 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
205 #if ENABLE_ZLIB
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
206 /* do an extra stat on the cache file for the size statistics */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
207 if (stat(cached_filename, pstat) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
208 cc_log("failed to stat cache files - %s\n", strerror(errno));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
209 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
210 if (tmp_outfiles) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
211 unlink(tmp_outfiles);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
212 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
213 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
214 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
215 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
216 (void)cached_filename;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
217 (void)tmp_outfiles;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
218 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
219 (*files_size) += file_size(pstat);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
220 (*cached_files_count)++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
221 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
222
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
223 /* run the real compiler and put the result in cache */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
224 static void to_cache(ARGS *args)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
225 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
226 char *path_stderr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
227 char *tmp_stdout, *tmp_stderr, *tmp_outfiles;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
228 struct stat st1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
229 int status;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
230 int cached_files_count = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
231 int files_size = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
232
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
233 x_asprintf(&tmp_stdout, "%s/tmp.stdout.%s", temp_dir, tmp_string());
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
234 x_asprintf(&tmp_stderr, "%s/tmp.stderr.%s", temp_dir, tmp_string());
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
235 x_asprintf(&tmp_outfiles, "%s/tmp.outfiles.%s", temp_dir, tmp_string());
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
236
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
237 if (strip_c_option && !swig) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
238 args_add(stripped_args, "-c");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
239 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
240
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
241 if (output_file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
242 args_add(args, "-o");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
243 args_add(args, output_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
244 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
245
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
246 /* Turn off DEPENDENCIES_OUTPUT when running cc1, because
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
247 * otherwise it will emit a line like
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
248 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
249 * tmp.stdout.vexed.732.o: /home/mbp/.ccache/tmp.stdout.vexed.732.i
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
250 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
251 * unsetenv() is on BSD and Linux but not portable. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
252 putenv("DEPENDENCIES_OUTPUT");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
253
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
254 /* Give SWIG a filename for it to create and populate with a list of files that it generates */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
255 if (swig) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
256 char *ccache_outfiles;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
257 x_asprintf(&ccache_outfiles, "CCACHE_OUTFILES=%s", tmp_outfiles);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
258 unlink(tmp_outfiles);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
259 if (getenv("CCACHE_OUTFILES") || putenv(ccache_outfiles) == -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
260 cc_log("CCACHE_OUTFILES env variable already set or could not be set\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
261 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
262 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
263 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
264 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
265
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
266 if (getenv("CCACHE_CPP2")) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
267 args_add(args, input_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
268 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
269 if (swig) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
270 args_add(args, "-nopreprocess");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
271 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
272 args_add(args, i_tmpfile);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
273 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
274 status = execute(args->argv, tmp_stdout, tmp_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
275 args_pop(args, 3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
276
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
277 if (stat(tmp_stdout, &st1) != 0 || st1.st_size != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
278 cc_log("compiler produced stdout for %s\n", input_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
279 stats_update(STATS_STDOUT);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
280 unlink(tmp_stdout);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
281 unlink(tmp_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
282 unlink(tmp_outfiles);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
283 if (!swig) unlink(output_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
284 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
285 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
286 unlink(tmp_stdout);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
287
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
288 if (status != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
289 int fd;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
290 cc_log("compile of %s gave status = %d\n", input_file, status);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
291 stats_update(STATS_STATUS);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
292
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
293 fd = open(tmp_stderr, O_RDONLY | O_BINARY);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
294 if (fd != -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
295 if (cpp_stderr) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
296 /* we might have some stderr from cpp */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
297 int fd2 = open(cpp_stderr, O_RDONLY | O_BINARY);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
298 if (fd2 != -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
299 copy_fd(fd2, 2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
300 close(fd2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
301 unlink(cpp_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
302 cpp_stderr = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
303 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
304 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
305
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
306 /* we can use a quick method of
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
307 getting the failed output */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
308 copy_fd(fd, 2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
309 close(fd);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
310 unlink(tmp_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
311 if (i_tmpfile && !direct_i_file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
312 unlink(i_tmpfile);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
313 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
314 exit(status);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
315 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
316
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
317 unlink(tmp_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
318 unlink(tmp_outfiles);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
319 if (!swig) unlink(output_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
320 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
321 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
322 int hardlink = (getenv("CCACHE_NOCOMPRESS") != 0) && (getenv("CCACHE_HARDLINK") != 0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
323 if (swig) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
324 /* read the list of generated files and copy each of them into the cache */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
325 FILE *file;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
326 file = fopen(tmp_outfiles, "r");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
327 if (file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
328 char out_filename[FILENAME_MAX + 1];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
329 char out_filename_cache[FILENAME_MAX + 1];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
330 while (fgets(out_filename, FILENAME_MAX, file)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
331 char *linefeed = strchr(out_filename, '\n');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
332 if (linefeed) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
333 char *potential_cr = linefeed - 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
334 if (potential_cr >= out_filename && *potential_cr == '\r')
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
335 *potential_cr = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
336 *linefeed = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
337
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
338 if (cached_files_count == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
339 strcpy(out_filename_cache, hashname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
340 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
341 sprintf(out_filename_cache, "%s.%d", hashname, cached_files_count);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
342 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
343
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
344 if (commit_to_cache(out_filename, out_filename_cache, hardlink) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
345 fclose(file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
346 unlink(tmp_outfiles);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
347 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
348 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
349 to_cache_stats_helper(&st1, out_filename_cache, tmp_outfiles, &files_size, &cached_files_count);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
350 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
351 cached_files_count = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
352 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
353 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
354 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
355 fclose(file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
356 if (cached_files_count == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
357 cc_log("failed to copy output files to cache - internal error\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
358 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
359 unlink(tmp_outfiles);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
360 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
361 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
362
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
363 /* also copy the (uncompressed) file containing the list of generated files into the cache */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
364 sprintf(out_filename_cache, "%s.outfiles", hashname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
365 if (stat(tmp_outfiles, &st1) != 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
366 safe_rename(tmp_outfiles, out_filename_cache) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
367 cc_log("failed to copy outfiles file to cache - %s\n", strerror(errno));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
368 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
369 unlink(tmp_outfiles);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
370 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
371 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
372 to_cache_stats_helper(&st1, out_filename_cache, tmp_outfiles, &files_size, &cached_files_count);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
373 unlink(tmp_outfiles);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
374 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
375 cc_log("failed to open temp outfiles file - %s\n", strerror(errno));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
376 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
377 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
378 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
379 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
380 if (commit_to_cache(output_file, hashname, hardlink) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
381 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
382 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
383 to_cache_stats_helper(&st1, hashname, 0, &files_size, &cached_files_count);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
384 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
385 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
386
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
387 x_asprintf(&path_stderr, "%s.stderr", hashname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
388
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
389 if (stat(tmp_stderr, &st1) != 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
390 move_file(tmp_stderr, path_stderr) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
391 cc_log("failed to rename tmp files - %s\n", strerror(errno));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
392 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
393 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
394 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
395
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
396 to_cache_stats_helper(&st1, path_stderr, 0, &files_size, &cached_files_count);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
397
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
398 cc_log("Placed %d files for %s into cache\n", cached_files_count, input_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
399 stats_tocache(files_size, cached_files_count);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
400
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
401 free(tmp_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
402 free(tmp_stdout);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
403 free(tmp_outfiles);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
404 free(path_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
405 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
406
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
407 /* find the hash for a command. The hash includes all argument lists,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
408 plus the output from running the compiler with -E */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
409 static void find_hash(ARGS *args)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
410 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
411 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
412 char *path_stdout, *path_stderr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
413 char *hash_dir;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
414 char *s;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
415 struct stat st;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
416 int status;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
417 int nlevels = 2;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
418 char *input_base;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
419 char *tmp;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
420
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
421 if ((s = getenv("CCACHE_NLEVELS"))) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
422 nlevels = atoi(s);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
423 if (nlevels < 1) nlevels = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
424 if (nlevels > 8) nlevels = 8;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
425 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
426
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
427 hash_start();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
428
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
429 /* when we are doing the unifying tricks we need to include
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
430 the input file name in the hash to get the warnings right */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
431 if (enable_unify || swig) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
432 hash_string(input_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
433 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
434
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
435 if (swig) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
436 if (output_file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
437 hash_string(output_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
438 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
439 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
440 /* we have to hash the extension, as a .i file isn't treated the same
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
441 by the compiler as a .ii file */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
442 hash_string(i_extension);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
443 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
444
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
445 /* first the arguments */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
446 for (i=1;i<args->argc;i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
447 /* some arguments don't contribute to the hash. The
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
448 theory is that these arguments will change the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
449 output of -E if they are going to have any effect
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
450 at all, or they only affect linking */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
451 if (i < args->argc-1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
452 if (strcmp(args->argv[i], "-I") == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
453 strcmp(args->argv[i], "-include") == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
454 strcmp(args->argv[i], "-L") == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
455 strcmp(args->argv[i], "-D") == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
456 strcmp(args->argv[i], "-idirafter") == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
457 strcmp(args->argv[i], "-isystem") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
458 i++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
459 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
460 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
461 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
462 if (strncmp(args->argv[i], "-I", 2) == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
463 strncmp(args->argv[i], "-L", 2) == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
464 strncmp(args->argv[i], "-D", 2) == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
465 strncmp(args->argv[i], "-idirafter", 10) == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
466 strncmp(args->argv[i], "-isystem", 8) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
467 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
468 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
469
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
470 if (strncmp(args->argv[i], "--specs=", 8) == 0 &&
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
471 stat(args->argv[i]+8, &st) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
472 /* if given a explicit specs file, then hash that file, but
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
473 don't include the path to it in the hash */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
474 hash_file(args->argv[i]+8);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
475 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
476 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
477
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
478 /* all other arguments are included in the hash */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
479 hash_string(args->argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
480 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
481
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
482 /* the compiler driver size and date. This is a simple minded way
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
483 to try and detect compiler upgrades. It is not 100% reliable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
484 if (stat(args->argv[0], &st) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
485 cc_log("Couldn't stat the compiler!? (argv[0]='%s')\n", args->argv[0]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
486 stats_update(STATS_COMPILER);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
487 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
488 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
489
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
490 /* also include the hash of the compiler name - as some compilers
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
491 use hard links and behave differently depending on the real name */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
492 if (st.st_nlink > 1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
493 hash_string(str_basename(args->argv[0]));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
494 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
495
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
496 hash_int(st.st_size);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
497 hash_int(st.st_mtime);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
498
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
499 /* possibly hash the current working directory */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
500 if (getenv("CCACHE_HASHDIR")) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
501 char *cwd = gnu_getcwd();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
502 if (cwd) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
503 hash_string(cwd);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
504 free(cwd);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
505 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
506 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
507
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
508 /* ~/hello.c -> tmp.hello.123.i
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
509 limit the basename to 10
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
510 characters in order to cope with filesystem with small
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
511 maximum filename length limits */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
512 input_base = str_basename(input_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
513 tmp = strchr(input_base, '.');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
514 if (tmp != NULL) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
515 *tmp = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
516 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
517 if (strlen(input_base) > 10) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
518 input_base[10] = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
519 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
520
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
521 /* now the run */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
522 x_asprintf(&path_stdout, "%s/%s.tmp.%s.%s", temp_dir,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
523 input_base, tmp_string(),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
524 i_extension);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
525 x_asprintf(&path_stderr, "%s/tmp.cpp_stderr.%s", temp_dir, tmp_string());
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
526
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
527 if (!direct_i_file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
528 /* run cpp on the input file to obtain the .i */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
529 args_add(args, "-E");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
530 args_add(args, input_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
531 status = execute(args->argv, path_stdout, path_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
532 args_pop(args, 2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
533 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
534 /* we are compiling a .i or .ii file - that means we
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
535 can skip the cpp stage and directly form the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
536 correct i_tmpfile */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
537 path_stdout = x_strdup(input_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
538 if (create_empty_file(path_stderr) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
539 cc_log("failed to create empty stderr file\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
540 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
541 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
542 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
543 status = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
544 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
545
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
546 if (status != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
547 if (!direct_i_file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
548 unlink(path_stdout);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
549 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
550 unlink(path_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
551 cc_log("the preprocessor gave %d\n", status);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
552 stats_update(STATS_PREPROCESSOR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
553 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
554 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
555
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
556 /* if the compilation is with -g then we have to include the whole of the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
557 preprocessor output, which means we are sensitive to line number
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
558 information. Otherwise we can discard line number info, which makes
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
559 us less sensitive to reformatting changes
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
560
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
561 Note! I have now disabled the unification code by default
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
562 as it gives the wrong line numbers for warnings. Pity.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
563 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
564 if (!enable_unify) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
565 hash_file(path_stdout);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
566 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
567 if (unify_hash(path_stdout) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
568 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
569 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
570 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
571 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
572 hash_file(path_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
573
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
574 i_tmpfile = path_stdout;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
575
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
576 if (!getenv("CCACHE_CPP2")) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
577 /* if we are using the CPP trick then we need to remember this stderr
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
578 data and output it just before the main stderr from the compiler
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
579 pass */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
580 cpp_stderr = path_stderr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
581 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
582 unlink(path_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
583 free(path_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
584 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
585
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
586 /* we use a N level subdir for the cache path to reduce the impact
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
587 on filesystems which are slow for large directories
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
588 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
589 s = hash_result();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
590 x_asprintf(&hash_dir, "%s/%c", cache_dir, s[0]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
591 x_asprintf(&stats_file, "%s/stats", hash_dir);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
592 for (i=1; i<nlevels; i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
593 char *p;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
594 if (create_dir(hash_dir) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
595 cc_log("failed to create %s\n", hash_dir);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
596 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
597 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
598 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
599 x_asprintf(&p, "%s/%c", hash_dir, s[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
600 free(hash_dir);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
601 hash_dir = p;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
602 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
603 if (create_dir(hash_dir) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
604 cc_log("failed to create %s\n", hash_dir);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
605 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
606 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
607 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
608 x_asprintf(&hashname, "%s/%s", hash_dir, s+nlevels);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
609 free(hash_dir);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
610 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
611
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
612 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
613 try to return the compile result from cache. If we can return from
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
614 cache then this function exits with the correct status code,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
615 otherwise it returns */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
616 static void from_cache(int first)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
617 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
618 int fd_stderr, fd_cpp_stderr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
619 char *stderr_file;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
620 struct stat st;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
621
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
622 x_asprintf(&stderr_file, "%s.stderr", hashname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
623 fd_stderr = open(stderr_file, O_RDONLY | O_BINARY);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
624 if (fd_stderr == -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
625 /* it isn't in cache ... */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
626 free(stderr_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
627 return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
628 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
629
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
630 /* make sure the output is there too */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
631 if (stat(hashname, &st) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
632 close(fd_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
633 unlink(stderr_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
634 free(stderr_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
635 return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
636 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
637
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
638 /* the user might be disabling cache hits */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
639 #ifndef ENABLE_ZLIB
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
640 /* if the cache file is compressed we must recache */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
641 if ((first && getenv("CCACHE_RECACHE")) ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
642 test_if_compressed(hashname) == 1)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
643 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
644 if (first && getenv("CCACHE_RECACHE"))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
645 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
646 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
647 close(fd_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
648 unlink(stderr_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
649 free(stderr_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
650 return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
651 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
652
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
653 if (first) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
654 int hardlink;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
655 int passfail = -1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
656
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
657 /* update timestamps for LRU cleanup
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
658 also gives output_file a sensible mtime when hard-linking (for make) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
659 x_utimes(stderr_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
660
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
661 hardlink = (getenv("CCACHE_HARDLINK") != 0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
662
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
663 if (swig) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
664 /* read the list of generated files and copy each of them out of the cache */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
665 FILE *file;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
666 char *outfiles;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
667 x_asprintf(&outfiles, "%s.outfiles", hashname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
668 file = fopen(outfiles, "r");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
669 if (file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
670 char out_filename[FILENAME_MAX + 1];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
671 char out_filename_cache[FILENAME_MAX + 1];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
672 int retrieved_files_count = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
673 x_utimes(outfiles);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
674 while (fgets(out_filename, FILENAME_MAX, file)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
675 char *linefeed = strchr(out_filename, '\n');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
676 if (linefeed) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
677 char *potential_cr = linefeed - 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
678 if (potential_cr >= out_filename && *potential_cr == '\r')
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
679 *potential_cr = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
680 *linefeed = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
681
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
682 if (retrieved_files_count == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
683 strcpy(out_filename_cache, hashname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
684 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
685 sprintf(out_filename_cache, "%s.%d", hashname, retrieved_files_count);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
686 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
687
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
688 passfail = retrieve_from_cache(out_filename_cache, out_filename, hardlink);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
689 if (passfail == -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
690 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
691 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
692
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
693 retrieved_files_count++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
694 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
695 cc_log("failed to copy output files from cache - internal error\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
696 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
697 passfail = -1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
698 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
699 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
700 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
701 if (retrieved_files_count == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
702 cc_log("failed to copy output files from cache - internal error\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
703 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
704 passfail = -1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
705 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
706 fclose(file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
707 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
708 cc_log("failed to open cached outfiles file - %s\n", strerror(errno));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
709 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
710 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
711 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
712 passfail = retrieve_from_cache(hashname, output_file, hardlink);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
713 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
714
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
715 if (passfail == -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
716 close(fd_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
717 unlink(stderr_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
718 free(stderr_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
719 return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
720 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
721 free(stderr_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
722 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
723
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
724 /* get rid of the intermediate preprocessor file */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
725 if (i_tmpfile) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
726 if (!direct_i_file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
727 unlink(i_tmpfile);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
728 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
729 free(i_tmpfile);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
730 i_tmpfile = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
731 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
732
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
733 /* send the cpp stderr, if applicable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
734 fd_cpp_stderr = open(cpp_stderr, O_RDONLY | O_BINARY);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
735 if (fd_cpp_stderr != -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
736 copy_fd(fd_cpp_stderr, 2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
737 close(fd_cpp_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
738 unlink(cpp_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
739 free(cpp_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
740 cpp_stderr = NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
741 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
742
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
743 /* send the stderr */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
744 copy_fd(fd_stderr, 2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
745 close(fd_stderr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
746
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
747 /* and exit with the right status code */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
748 if (first) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
749 cc_log("got cached result for %s\n", input_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
750 stats_update(STATS_CACHED);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
751 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
752
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
753 exit(0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
754 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
755
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
756 /* find the real compiler. We just search the PATH to find a executable of the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
757 same name that isn't a link to ourselves */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
758 static void find_compiler(int argc, char **argv)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
759 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
760 char *base;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
761 char *path;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
762
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
763 orig_args = args_init(argc, argv);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
764
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
765 base = str_basename(argv[0]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
766
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
767 /* we might be being invoked like "ccache gcc -c foo.c" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
768 if (strcmp(base, MYNAME) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
769 args_remove_first(orig_args);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
770 free(base);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
771 if (strchr(argv[1],'/')
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
772 #ifdef _WIN32
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
773 || strchr(argv[1],'\\')
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
774 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
775 ) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
776 /* a full path was given */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
777 return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
778 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
779 base = str_basename(argv[1]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
780 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
781
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
782 /* support user override of the compiler */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
783 if ((path=getenv("CCACHE_CC"))) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
784 base = x_strdup(path);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
785 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
786
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
787 orig_args->argv[0] = find_executable(base, MYNAME);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
788
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
789 /* can't find the compiler! */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
790 if (!orig_args->argv[0]) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
791 stats_update(STATS_COMPILER);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
792 cc_log("could not find compiler (%s)\n", base);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
793 perror(base);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
794 exit(1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
795 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
796 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
797
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
798
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
799 /* check a filename for C/C++ extension. Return the pre-processor
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
800 extension */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
801 static const char *check_extension(const char *fname, int *direct_i)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
802 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
803 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
804 const char *p;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
805
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
806 if (direct_i) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
807 *direct_i = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
808 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
809
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
810 if (swig) return "ii"; /* any file extension is acceptable as input for SWIG */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
811
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
812 p = strrchr(fname, '.');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
813 if (!p) return NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
814 p++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
815 for (i=0; extensions[i].extension; i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
816 if (strcmp(p, extensions[i].extension) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
817 if (direct_i && strcmp(p, extensions[i].i_extension) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
818 *direct_i = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
819 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
820 p = getenv("CCACHE_EXTENSION");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
821 if (p) return p;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
822 return extensions[i].i_extension;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
823 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
824 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
825 return NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
826 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
827
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
828
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
829 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
830 process the compiler options to form the correct set of options
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
831 for obtaining the preprocessor output
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
832 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
833 static void process_args(int argc, char **argv)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
834 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
835 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
836 int found_c_opt = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
837 int found_S_opt = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
838 struct stat st;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
839 char *e;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
840 /* is gcc being asked to output dependencies? */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
841 int generating_dependencies = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
842 /* is the dependency makefile name overridden with -MF? */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
843 int dependency_filename_specified = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
844 /* is the dependency makefile target name specified with -MQ or -MF? */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
845 int dependency_target_specified = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
846
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
847
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
848 stripped_args = args_init(0, NULL);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
849
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
850 args_add(stripped_args, argv[0]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
851
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
852 /* -c not required for SWIG */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
853 if (swig) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
854 found_c_opt = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
855 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
856
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
857 for (i=1; i<argc; i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
858 /* some options will never work ... */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
859 if (strcmp(argv[i], "-E") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
860 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
861 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
862
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
863 /* these are too hard */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
864 if (strcmp(argv[i], "-fbranch-probabilities")==0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
865 strcmp(argv[i], "-fprofile-arcs") == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
866 strcmp(argv[i], "-ftest-coverage") == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
867 strcmp(argv[i], "--coverage") == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
868 strcmp(argv[i], "-M") == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
869 strcmp(argv[i], "-MM") == 0 ||
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
870 strcmp(argv[i], "-x") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
871 cc_log("argument %s is unsupported\n", argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
872 stats_update(STATS_UNSUPPORTED);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
873 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
874 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
875 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
876
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
877 /* we must have -c */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
878 if (strcmp(argv[i], "-c") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
879 if (!strip_c_option) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
880 args_add(stripped_args, argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
881 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
882 found_c_opt = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
883 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
884 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
885
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
886 /* -S changes the default extension */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
887 if (strcmp(argv[i], "-S") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
888 args_add(stripped_args, argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
889 found_S_opt = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
890 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
891 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
892
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
893 /* we need to work out where the output was meant to go */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
894 if (strcmp(argv[i], "-o") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
895 if (i == argc-1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
896 cc_log("missing argument to %s\n", argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
897 stats_update(STATS_ARGS);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
898 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
899 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
900 output_file = argv[i+1];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
901 i++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
902 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
903 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
904
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
905 /* alternate form of -o, with no space */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
906 if (!swig) { /* some of SWIG's arguments begin with -o */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
907 if (strncmp(argv[i], "-o", 2) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
908 output_file = &argv[i][2];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
909 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
910 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
911 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
912
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
913 /* debugging is handled specially, so that we know if we
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
914 can strip line number info
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
915 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
916 if (strncmp(argv[i], "-g", 2) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
917 args_add(stripped_args, argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
918 if (strcmp(argv[i], "-g0") != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
919 enable_unify = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
920 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
921 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
922 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
923
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
924 /* The user knows best: just swallow the next arg */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
925 if (strcmp(argv[i], "--ccache-skip") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
926 i++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
927 if (i == argc) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
928 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
929 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
930 args_add(stripped_args, argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
931 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
932 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
933
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
934 /* These options require special handling, because they
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
935 behave differently with gcc -E, when the output
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
936 file is not specified. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
937
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
938 if (strcmp(argv[i], "-MD") == 0 || strcmp(argv[i], "-MMD") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
939 generating_dependencies = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
940 } else if (strcmp(argv[i], "-MF") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
941 dependency_filename_specified = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
942 } else if (strcmp(argv[i], "-MQ") == 0 || strcmp(argv[i], "-MT") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
943 dependency_target_specified = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
944 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
945
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
946 /* the input file is already preprocessed */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
947 if (swig && strcmp(argv[i], "-nopreprocess") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
948 direct_i_file = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
949 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
950 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
951
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
952 /* options that take an argument */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
953 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
954 const char *opts[] = {"-I", "-include", "-imacros", "-iprefix",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
955 "-iwithprefix", "-iwithprefixbefore",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
956 "-L", "-D", "-U", "-x", "-MF",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
957 "-MT", "-MQ", "-isystem", "-aux-info",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
958 "--param", "-A", "-Xlinker", "-u",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
959 "-idirafter",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
960 NULL};
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
961 int j;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
962 for (j=0;opts[j];j++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
963 if (strcmp(argv[i], opts[j]) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
964 if (i == argc-1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
965 cc_log("missing argument to %s\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
966 argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
967 stats_update(STATS_ARGS);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
968 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
969 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
970
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
971 args_add(stripped_args, argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
972 args_add(stripped_args, argv[i+1]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
973 i++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
974 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
975 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
976 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
977 if (opts[j]) continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
978 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
979
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
980 /* other options */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
981 if (argv[i][0] == '-') {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
982 args_add(stripped_args, argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
983 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
984 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
985
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
986 /* if an argument isn't a plain file then assume its
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
987 an option, not an input file. This allows us to
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
988 cope better with unusual compiler options */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
989 if (stat(argv[i], &st) != 0 || !S_ISREG(st.st_mode)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
990 args_add(stripped_args, argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
991 continue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
992 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
993
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
994 if (input_file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
995 if (check_extension(argv[i], NULL)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
996 cc_log("multiple input files (%s and %s)\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
997 input_file, argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
998 stats_update(STATS_MULTIPLE);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
999 } else if (!found_c_opt) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1000 cc_log("called for link with %s\n", argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1001 if (strstr(argv[i], "conftest.")) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1002 stats_update(STATS_CONFTEST);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1003 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1004 stats_update(STATS_LINK);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1005 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1006 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1007 cc_log("non C/C++ file %s\n", argv[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1008 stats_update(STATS_NOTC);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1009 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1010 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1011 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1012
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1013 input_file = argv[i];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1014 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1015
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1016 if (!input_file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1017 cc_log("No input file found\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1018 stats_update(STATS_NOINPUT);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1019 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1020 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1021
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1022 if (swig) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1023 i_extension = check_extension(input_file, NULL);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1024 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1025 i_extension = check_extension(input_file, &direct_i_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1026 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1027 if (i_extension == NULL) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1028 cc_log("Not a C/C++ file - %s\n", input_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1029 stats_update(STATS_NOTC);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1030 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1031 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1032
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1033 if (!found_c_opt) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1034 cc_log("No -c option found for %s\n", input_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1035 /* I find that having a separate statistic for autoconf tests is useful,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1036 as they are the dominant form of "called for link" in many cases */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1037 if (strstr(input_file, "conftest.")) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1038 stats_update(STATS_CONFTEST);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1039 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1040 stats_update(STATS_LINK);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1041 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1042 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1043 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1044
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1045
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1046 /* don't try to second guess the compilers heuristics for stdout handling */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1047 if (output_file && strcmp(output_file, "-") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1048 stats_update(STATS_OUTSTDOUT);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1049 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1050 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1051
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1052 if (!swig && !output_file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1053 char *p;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1054 output_file = x_strdup(input_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1055 if ((p = strrchr(output_file, '/'))) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1056 output_file = p+1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1057 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1058 p = strrchr(output_file, '.');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1059 if (!p || !p[1]) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1060 cc_log("badly formed output_file %s\n", output_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1061 stats_update(STATS_ARGS);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1062 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1063 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1064 p[1] = found_S_opt ? 's' : 'o';
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1065 p[2] = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1066 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1067
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1068 /* If dependencies are generated, configure the preprocessor */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1069
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1070 if (generating_dependencies && output_file) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1071 if (!dependency_filename_specified) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1072 char *default_depfile_name = x_strdup(output_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1073 char *p = strrchr(default_depfile_name, '.');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1074
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1075 if (p) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1076 if (strlen(p) < 2) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1077 cc_log("badly formed dependency file %s\n", output_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1078 stats_update(STATS_ARGS);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1079 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1080 return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1081 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1082 *p = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1083 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1084 else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1085 int len = p - default_depfile_name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1086
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1087 p = x_malloc(len + 3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1088 strncpy(default_depfile_name, p, len - 1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1089 free(default_depfile_name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1090 default_depfile_name = p;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1091 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1092
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1093 strcat(default_depfile_name, ".d");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1094 args_add(stripped_args, "-MF");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1095 args_add(stripped_args, default_depfile_name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1096 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1097
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1098 if (!dependency_target_specified) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1099 args_add(stripped_args, "-MT");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1100 args_add(stripped_args, output_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1101 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1102 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1103
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1104 /* cope with -o /dev/null */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1105 if (output_file && strcmp(output_file,"/dev/null") != 0 && stat(output_file, &st) == 0 && !S_ISREG(st.st_mode)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1106 cc_log("Not a regular file %s\n", output_file);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1107 stats_update(STATS_DEVICE);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1108 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1109 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1110
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1111 if ((e=getenv("CCACHE_PREFIX"))) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1112 char *p = find_executable(e, MYNAME);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1113 if (!p) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1114 cc_log("could not find executable (%s)\n", e);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1115 stats_update(STATS_ENVIRONMMENT);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1116 perror(e);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1117 exit(1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1118 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1119 args_add_prefix(stripped_args, p);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1120 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1121 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1122
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1123 static void detect_swig()
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1124 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1125 char *basename = str_basename(orig_args->argv[0]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1126 if (strstr(basename, "swig") || getenv("CCACHE_SWIG")) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1127 swig = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1128 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1129 free(basename);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1130 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1131
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1132 /* the main ccache driver function */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1133 static void ccache(int argc, char *argv[])
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1134 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1135 /* find the real compiler */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1136 find_compiler(argc, argv);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1137
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1138 /* use the real compiler if HOME is not set */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1139 if (!cache_dir) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1140 cc_log("Unable to determine home directory\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1141 cc_log("ccache is disabled\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1142 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1143 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1144
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1145 /* we might be disabled */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1146 if (getenv("CCACHE_DISABLE")) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1147 cc_log("ccache is disabled\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1148 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1149 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1150
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1151 if (getenv("CCACHE_STRIPC")) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1152 strip_c_option = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1153 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1154
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1155 if (getenv("CCACHE_UNIFY")) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1156 enable_unify = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1157 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1158
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1159 detect_swig();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1160
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1161 /* process argument list, returning a new set of arguments for pre-processing */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1162 process_args(orig_args->argc, orig_args->argv);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1163
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1164 /* run with -E to find the hash */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1165 find_hash(stripped_args);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1166
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1167 /* if we can return from cache at this point then do */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1168 from_cache(1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1169
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1170 if (getenv("CCACHE_READONLY")) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1171 cc_log("read-only set - doing real compile\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1172 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1173 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1174
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1175 /* run real compiler, sending output to cache */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1176 to_cache(stripped_args);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1177
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1178 /* return from cache */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1179 from_cache(0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1180
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1181 /* oh oh! */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1182 cc_log("secondary from_cache failed!\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1183 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1184 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1185 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1186
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1187
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1188 static void usage(void)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1189 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1190 printf("%s, a compiler cache including support for SWIG. Version %s\n", MYNAME, CCACHE_VERSION);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1191 printf("Copyright Andrew Tridgell, 2002\n\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1192
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1193 printf("Usage:\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1194 printf("\t" MYNAME " [options]\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1195 printf("\t" MYNAME " compiler [compile options]\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1196 printf("\tcompiler [compile options] (via symbolic link)\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1197 printf("\nOptions:\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1198
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1199 printf("-s show statistics summary\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1200 printf("-z zero statistics\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1201 printf("-c run a cache cleanup\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1202 printf("-C clear the cache completely\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1203 printf("-F <maxfiles> set maximum files in cache\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1204 printf("-M <maxsize> set maximum size of cache (use G, M or K)\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1205 printf("-h this help page\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1206 printf("-V print version number\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1207 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1208
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1209 static void check_cache_dir(void)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1210 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1211 if (!cache_dir) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1212 fatal("Unable to determine home directory");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1213 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1214 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1215
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1216 /* the main program when not doing a compile */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1217 static int ccache_main(int argc, char *argv[])
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1218 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1219 int c;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1220 size_t v;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1221
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1222 while ((c = getopt(argc, argv, "hszcCF:M:V")) != -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1223 switch (c) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1224 case 'V':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1225 printf("%s version %s\n", MYNAME, CCACHE_VERSION);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1226 printf("Copyright Andrew Tridgell 2002\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1227 printf("Released under the GNU GPL v2 or later\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1228 exit(0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1229
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1230 case 'h':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1231 usage();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1232 exit(0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1233
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1234 case 's':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1235 check_cache_dir();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1236 stats_summary();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1237 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1238
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1239 case 'c':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1240 check_cache_dir();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1241 cleanup_all(cache_dir);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1242 printf("Cleaned cache\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1243 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1244
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1245 case 'C':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1246 check_cache_dir();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1247 wipe_all(cache_dir);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1248 printf("Cleared cache\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1249 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1250
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1251 case 'z':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1252 check_cache_dir();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1253 stats_zero();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1254 printf("Statistics cleared\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1255 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1256
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1257 case 'F':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1258 check_cache_dir();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1259 v = atoi(optarg);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1260 if (stats_set_limits(v, -1) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1261 printf("Set cache file limit to %u\n", (unsigned)v);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1262 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1263 printf("Could not set cache file limit.\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1264 exit(1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1265 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1266 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1267
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1268 case 'M':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1269 check_cache_dir();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1270 v = value_units(optarg);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1271 if (stats_set_limits(-1, v) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1272 printf("Set cache size limit to %uk\n", (unsigned)v);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1273 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1274 printf("Could not set cache size limit.\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1275 exit(1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1276 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1277 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1278
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1279 default:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1280 usage();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1281 exit(1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1282 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1283 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1284
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1285 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1286 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1287
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1288
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1289 /* Make a copy of stderr that will not be cached, so things like
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1290 distcc can send networking errors to it. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1291 static void setup_uncached_err(void)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1292 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1293 char *buf;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1294 int uncached_fd;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1295
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1296 uncached_fd = dup(2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1297 if (uncached_fd == -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1298 cc_log("dup(2) failed\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1299 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1300 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1301 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1302
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1303 /* leak a pointer to the environment */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1304 x_asprintf(&buf, "UNCACHED_ERR_FD=%d", uncached_fd);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1305
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1306 if (putenv(buf) == -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1307 cc_log("putenv failed\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1308 stats_update(STATS_ERROR);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1309 failed();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1310 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1311 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1312
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1313
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1314 int main(int argc, char *argv[])
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1315 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1316 char *p;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1317
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1318 cache_dir = getenv("CCACHE_DIR");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1319 if (!cache_dir) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1320 const char *home_directory = get_home_directory();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1321 if (home_directory) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1322 x_asprintf(&cache_dir, "%s/.ccache", home_directory);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1323 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1324 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1325
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1326 cache_logfile = getenv("CCACHE_LOGFILE");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1327
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1328 if (getenv("CCACHE_VERBOSE")) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1329 ccache_verbose = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1330 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1331
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1332 setup_uncached_err();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1333
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1334
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1335 /* the user might have set CCACHE_UMASK */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1336 p = getenv("CCACHE_UMASK");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1337 if (p) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1338 mode_t mask;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1339 errno = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1340 mask = strtol(p, NULL, 8);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1341 if (errno == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1342 umask(mask);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1343 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1344 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1345
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1346
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1347 /* check if we are being invoked as "ccache" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1348 if (strlen(argv[0]) >= strlen(MYNAME) &&
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1349 strcmp(argv[0] + strlen(argv[0]) - strlen(MYNAME), MYNAME) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1350 if (argc < 2) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1351 usage();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1352 exit(1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1353 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1354 /* if the first argument isn't an option, then assume we are
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1355 being passed a compiler name and options */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1356 if (argv[1][0] == '-') {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1357 return ccache_main(argc, argv);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1358 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1359 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1360
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1361 /* make sure the cache dir exists */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1362 if (cache_dir && (create_dir(cache_dir) != 0)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1363 fprintf(stderr,"ccache: failed to create %s (%s)\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1364 cache_dir, strerror(errno));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1365 exit(1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1366 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1367
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1368 temp_dir = getenv("CCACHE_TEMPDIR");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1369 if (!temp_dir) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1370 x_asprintf(&temp_dir, "%s/temp", cache_dir);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1371 /* make sure temp dir exists if not supplied by user */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1372 if (temp_dir && create_dir(temp_dir) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1373 fprintf(stderr,"ccache: failed to create %s (%s)\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1374 temp_dir, strerror(errno));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1375 exit(1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1376 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1377 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1378
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1379 if (!getenv("CCACHE_READONLY")) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1380 if (create_cachedirtag(cache_dir) != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1381 fprintf(stderr,"ccache: failed to create %s/CACHEDIR.TAG (%s)\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1382 cache_dir, strerror(errno));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1383 exit(1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1384 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1385 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1386
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1387 ccache(argc, argv);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1388 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1389 }