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