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