Print this page
make: unifdef for MAKE_IT (undefined)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/lib/vroot/report.cc
+++ new/usr/src/cmd/make/lib/vroot/report.cc
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <stdio.h>
27 27 #include <stdlib.h>
28 28 #include <string.h>
29 29 #include <sys/param.h>
30 30 #include <sys/wait.h>
31 31 #include <unistd.h>
32 32
33 33 #include <vroot/report.h>
34 34 #include <vroot/vroot.h>
35 35 #include <mksdmsi18n/mksdmsi18n.h>
36 36 #include <avo/intl.h> /* for NOCATGETS */
37 37 #include <mk/defs.h> /* for tmpdir */
38 38
39 39 static FILE *report_file;
40 40 static FILE *command_output_fp;
41 41 static char *target_being_reported_for;
42 42 static char *search_dir;
43 43 static char command_output_tmpfile[30];
44 44 static int is_path = 0;
45 45 static char sfile[MAXPATHLEN];
46 46 extern "C" {
47 47 static void (*warning_ptr) (char *, ...) = (void (*) (char *, ...)) NULL;
48 48 }
49 49
50 50 FILE *
51 51 get_report_file(void)
52 52 {
53 53 return(report_file);
54 54 }
55 55
56 56 char *
57 57 get_target_being_reported_for(void)
58 58 {
59 59 return(target_being_reported_for);
60 60 }
61 61
62 62 extern "C" {
63 63 static void
64 64 close_report_file(void)
65 65 {
66 66 (void)fputs("\n", report_file);
67 67 (void)fclose(report_file);
68 68 }
69 69 } // extern "C"
70 70
71 71 static void
72 72 clean_up(FILE *nse_depinfo_fp, FILE *merge_fp, char *nse_depinfo_file, char *merge_file, int unlinkf)
73 73 {
74 74 fclose(nse_depinfo_fp);
75 75 fclose(merge_fp);
76 76 fclose(command_output_fp);
77 77 unlink(command_output_tmpfile);
78 78 if (unlinkf)
79 79 unlink(merge_file);
80 80 else
81 81 rename(merge_file, nse_depinfo_file);
82 82 }
83 83
84 84
85 85 /*
86 86 * Update the file, if necessary. We don't want to rewrite
87 87 * the file if we don't have to because we don't want the time of the file
88 88 * to change in that case.
89 89 */
90 90
91 91 extern "C" {
92 92 static void
93 93 close_file(void)
94 94 {
95 95 char line[MAXPATHLEN+2];
96 96 char buf[MAXPATHLEN+2];
97 97 FILE *nse_depinfo_fp;
98 98 FILE *merge_fp;
99 99 char nse_depinfo_file[MAXPATHLEN];
100 100 char merge_file[MAXPATHLEN];
101 101 char lock_file[MAXPATHLEN];
102 102 int err;
103 103 int len;
104 104 int changed = 0;
105 105 int file_locked;
106 106
107 107 fprintf(command_output_fp, "\n");
108 108 fclose(command_output_fp);
109 109 if ((command_output_fp = fopen(command_output_tmpfile, "r")) == NULL) {
110 110 return;
111 111 }
112 112 sprintf(nse_depinfo_file, "%s/%s", search_dir, NSE_DEPINFO);
113 113 sprintf(merge_file, NOCATGETS("%s/.tmp%s.%d"), search_dir, NSE_DEPINFO, getpid());
114 114 sprintf(lock_file, "%s/%s", search_dir, NSE_DEPINFO_LOCK);
115 115 err = file_lock(nse_depinfo_file, lock_file, &file_locked, 0);
116 116 if (err) {
117 117 if (warning_ptr != (void (*) (char *, ...)) NULL) {
118 118 (*warning_ptr)(catgets(libmksdmsi18n_catd, 1, 147, "Couldn't write to %s"), nse_depinfo_file);
119 119 }
120 120 unlink(command_output_tmpfile);
121 121 return;
122 122 }
123 123 /* If .nse_depinfo file doesn't exist */
124 124 if ((nse_depinfo_fp = fopen(nse_depinfo_file, "r+")) == NULL) {
125 125 if (is_path) {
126 126 if ((nse_depinfo_fp =
127 127 fopen(nse_depinfo_file, "w")) == NULL) {
128 128 fprintf(stderr, catgets(libmksdmsi18n_catd, 1, 148, "Cannot open `%s' for writing\n"),
129 129 nse_depinfo_file);
130 130 unlink(command_output_tmpfile);
131 131
132 132 unlink(lock_file);
133 133 return;
134 134 }
135 135 while (fgets(line, MAXPATHLEN+2, command_output_fp)
136 136 != NULL) {
137 137 fprintf(nse_depinfo_fp, "%s", line);
138 138 }
139 139 fclose(command_output_fp);
140 140 }
141 141 fclose(nse_depinfo_fp);
142 142 if (file_locked) {
143 143 unlink(lock_file);
144 144 }
145 145 unlink(command_output_tmpfile);
146 146 return;
147 147 }
148 148 if ((merge_fp = fopen(merge_file, "w")) == NULL) {
149 149 fprintf(stderr, catgets(libmksdmsi18n_catd, 1, 149, "Cannot open %s for writing\n"), merge_file);
150 150 if (file_locked) {
151 151 unlink(lock_file);
152 152 }
153 153 unlink(command_output_tmpfile);
154 154 return;
155 155 }
156 156 len = strlen(sfile);
157 157 while (fgets(line, MAXPATHLEN+2, nse_depinfo_fp) != NULL) {
158 158 if (strncmp(line, sfile, len) == 0 && line[len] == ':') {
159 159 while (fgets(buf, MAXPATHLEN+2, command_output_fp)
160 160 != NULL) {
161 161 if (is_path) {
162 162 fprintf(merge_fp, "%s", buf);
163 163 if (strcmp(line, buf)) {
164 164 /* changed */
165 165 changed = 1;
166 166 }
167 167 }
168 168 if (buf[strlen(buf)-1] == '\n') {
169 169 break;
170 170 }
171 171 }
172 172 if (changed || !is_path) {
173 173 while (fgets(line, MAXPATHLEN, nse_depinfo_fp)
174 174 != NULL) {
175 175 fputs(line, merge_fp);
176 176 }
177 177 clean_up(nse_depinfo_fp, merge_fp,
178 178 nse_depinfo_file, merge_file, 0);
179 179 } else {
180 180 clean_up(nse_depinfo_fp, merge_fp,
181 181 nse_depinfo_file, merge_file, 1);
182 182 }
183 183 if (file_locked) {
184 184 unlink(lock_file);
185 185 }
186 186 unlink(command_output_tmpfile);
187 187 return;
188 188 } /* entry found */
189 189 fputs(line, merge_fp);
190 190 }
191 191 /* Entry never found. Add it if there is a search path */
192 192 if (is_path) {
193 193 while (fgets(line, MAXPATHLEN+2, command_output_fp) != NULL) {
194 194 fprintf(nse_depinfo_fp, "%s", line);
195 195 }
196 196 }
197 197 clean_up(nse_depinfo_fp, merge_fp, nse_depinfo_file, merge_file, 1);
198 198 if (file_locked) {
199 199 unlink(lock_file);
200 200 }
201 201 }
202 202
203 203 } // extern "C"
204 204
205 205 static void
206 206 report_dep(char *iflag, char *filename)
207 207 {
208 208
209 209 if (command_output_fp == NULL) {
210 210 sprintf(command_output_tmpfile,
211 211 NOCATGETS("%s/%s.%d.XXXXXX"), tmpdir, NSE_DEPINFO, getpid());
212 212 int fd = mkstemp(command_output_tmpfile);
213 213 if ((fd < 0) || (command_output_fp = fdopen(fd, "w")) == NULL) {
214 214 return;
215 215 }
216 216 if ((search_dir = getenv(NOCATGETS("NSE_DEP"))) == NULL) {
217 217 return;
218 218 }
219 219 atexit(close_file);
220 220 strcpy(sfile, filename);
221 221 if (iflag == NULL || *iflag == '\0') {
222 222 return;
223 223 }
224 224 fprintf(command_output_fp, "%s:", sfile);
225 225 }
226 226 fprintf(command_output_fp, " ");
227 227 fprintf(command_output_fp, iflag);
228 228 if (iflag != NULL) {
229 229 is_path = 1;
230 230 }
231 231 }
232 232
233 233 void
234 234 report_libdep(char *lib, char *flag)
235 235 {
236 236 char *ptr;
237 237 char filename[MAXPATHLEN];
238 238 char *p;
239 239
240 240 if ((p= getenv(SUNPRO_DEPENDENCIES)) == NULL) {
241 241 return;
242 242 }
243 243 ptr = strchr(p, ' ');
244 244 if(ptr) {
245 245 sprintf(filename, "%s-%s", ptr+1, flag);
246 246 is_path = 1;
247 247 report_dep(lib, filename);
248 248 }
249 249 }
250 250
251 251 void
252 252 report_search_path(char *iflag)
253 253 {
254 254 char curdir[MAXPATHLEN];
255 255 char *sdir;
256 256 char *newiflag;
257 257 char filename[MAXPATHLEN];
258 258 char *p, *ptr;
259 259
260 260 if ((sdir = getenv(NOCATGETS("NSE_DEP"))) == NULL) {
261 261 return;
262 262 }
263 263 if ((p= getenv(SUNPRO_DEPENDENCIES)) == NULL) {
264 264 return;
265 265 }
266 266 ptr = strchr(p, ' ');
267 267 if( ! ptr ) {
268 268 return;
269 269 }
270 270 sprintf(filename, NOCATGETS("%s-CPP"), ptr+1);
271 271 getcwd(curdir, sizeof(curdir));
272 272 if (strcmp(curdir, sdir) != 0 && strlen(iflag) > 2 &&
273 273 iflag[2] != '/') {
274 274 /* Makefile must have had an "cd xx; cc ..." */
275 275 /* Modify the -I path to be relative to the cd */
276 276 newiflag = (char *)malloc(strlen(iflag) + strlen(curdir) + 2);
277 277 sprintf(newiflag, "-%c%s/%s", iflag[1], curdir, &iflag[2]);
278 278 report_dep(newiflag, filename);
279 279 } else {
280 280 report_dep(iflag, filename);
281 281 }
282 282 }
283 283
284 284 void
285 285 report_dependency(const char *name)
286 286 {
287 287 register char *filename;
288 288 char buffer[MAXPATHLEN+1];
289 289 register char *p;
290 290 register char *p2;
291 291 char nse_depinfo_file[MAXPATHLEN];
292 292
293 293 if (report_file == NULL) {
294 294 if ((filename= getenv(SUNPRO_DEPENDENCIES)) == NULL) {
295 295 report_file = (FILE *)-1;
296 296 return;
297 297 }
298 298 if (strlen(filename) == 0) {
299 299 report_file = (FILE *)-1;
300 300 return;
301 301 }
302 302 (void)strcpy(buffer, name);
303 303 name = buffer;
304 304 p = strchr(filename, ' ');
305 305 if(p) {
306 306 *p= 0;
307 307 } else {
308 308 report_file = (FILE *)-1;
309 309 return;
310 310 }
311 311 if ((report_file= fopen(filename, "a")) == NULL) {
312 312 if ((report_file= fopen(filename, "w")) == NULL) {
313 313 report_file= (FILE *)-1;
314 314 return;
315 315 }
316 316 }
317 317 atexit(close_report_file);
318 318 if ((p2= strchr(p+1, ' ')) != NULL)
319 319 *p2= 0;
320 320 target_being_reported_for= (char *)malloc((unsigned)(strlen(p+1)+1));
321 321 (void)strcpy(target_being_reported_for, p+1);
322 322 (void)fputs(p+1, report_file);
323 323 (void)fputs(":", report_file);
↓ open down ↓ |
323 lines elided |
↑ open up ↑ |
324 324 *p= ' ';
325 325 if (p2 != NULL)
326 326 *p2= ' ';
327 327 }
328 328 if (report_file == (FILE *)-1)
329 329 return;
330 330 (void)fputs(name, report_file);
331 331 (void)fputs(" ", report_file);
332 332 }
333 333
334 -#ifdef MAKE_IT
335 -void
336 -make_it(filename)
337 - register char *filename;
338 -{
339 - register char *command;
340 - register char *argv[6];
341 - register int pid;
342 - union wait foo;
343 -
344 - if (getenv(SUNPRO_DEPENDENCIES) == NULL) return;
345 - command= alloca(strlen(filename)+32);
346 - (void)sprintf(command, NOCATGETS("make %s\n"), filename);
347 - switch (pid= fork()) {
348 - case 0: /* child */
349 - argv[0]= NOCATGETS("csh");
350 - argv[1]= NOCATGETS("-c");
351 - argv[2]= command;
352 - argv[3]= 0;
353 - (void)dup2(2, 1);
354 - execve(NOCATGETS("/bin/sh"), argv, environ);
355 - perror(NOCATGETS("execve error"));
356 - exit(1);
357 - case -1: /* error */
358 - perror(NOCATGETS("fork error"));
359 - default: /* parent */
360 - while (wait(&foo) != pid);};
361 -}
362 -#endif
363 334
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX