Print this page
make: unifdef SUN5_0 (defined)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/bin/misc.cc
+++ new/usr/src/cmd/make/bin/misc.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 2005 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 /*
27 27 * misc.cc
28 28 *
29 29 * This file contains various unclassified routines. Some main groups:
30 30 * getname
31 31 * Memory allocation
32 32 * String handling
33 33 * Property handling
34 34 * Error message handling
35 35 * Make internal state dumping
36 36 * main routine support
37 37 */
38 38
39 39 /*
40 40 * Included files
41 41 */
42 42 #include <errno.h>
43 43 #include <mk/defs.h>
44 44 #include <mksh/macro.h> /* SETVAR() */
45 45 #include <mksh/misc.h> /* enable_interrupt() */
46 46 #include <stdarg.h> /* va_list, va_start(), va_end() */
47 47 #include <vroot/report.h> /* SUNPRO_DEPENDENCIES */
48 48
49 49 #if defined(HP_UX) || defined(linux)
50 50 #include <unistd.h>
51 51 #endif
52 52
53 53 #ifdef TEAMWARE_MAKE_CMN
54 54 #define MAXJOBS_ADJUST_RFE4694000
55 55
56 56 #ifdef MAXJOBS_ADJUST_RFE4694000
57 57 extern void job_adjust_fini();
58 58 #endif /* MAXJOBS_ADJUST_RFE4694000 */
59 59 #endif /* TEAMWARE_MAKE_CMN */
60 60
61 61 #if defined(linux)
62 62 #include <time.h> /* localtime() */
63 63 #endif
64 64
65 65 /*
66 66 * Defined macros
67 67 */
68 68
69 69 /*
70 70 * typedefs & structs
71 71 */
72 72
73 73 /*
74 74 * Static variables
75 75 */
76 76
77 77 /*
78 78 * File table of contents
79 79 */
80 80 static void print_rule(register Name target);
81 81 static void print_target_n_deps(register Name target);
82 82
83 83 /*****************************************
84 84 *
85 85 * getname
86 86 */
87 87
88 88 /*****************************************
89 89 *
90 90 * Memory allocation
91 91 */
92 92
93 93 /*
94 94 * free_chain()
95 95 *
96 96 * frees a chain of Name_vector's
97 97 *
98 98 * Parameters:
99 99 * ptr Pointer to the first element in the chain
100 100 * to be freed.
101 101 *
102 102 * Global variables used:
103 103 */
104 104 void
105 105 free_chain(Name_vector ptr)
106 106 {
107 107 if (ptr != NULL) {
108 108 if (ptr->next != NULL) {
109 109 free_chain(ptr->next);
110 110 }
111 111 free((char *) ptr);
112 112 }
113 113 }
114 114
115 115 /*****************************************
116 116 *
117 117 * String manipulation
118 118 */
119 119
120 120 /*****************************************
121 121 *
122 122 * Nameblock property handling
123 123 */
124 124
125 125 /*****************************************
126 126 *
127 127 * Error message handling
128 128 */
129 129
130 130 /*
131 131 * fatal(format, args...)
132 132 *
133 133 * Print a message and die
134 134 *
135 135 * Parameters:
136 136 * format printf type format string
137 137 * args Arguments to match the format
138 138 *
139 139 * Global variables used:
140 140 * fatal_in_progress Indicates if this is a recursive call
141 141 * parallel_process_cnt Do we need to wait for anything?
142 142 * report_pwd Should we report the current path?
143 143 */
144 144 /*VARARGS*/
145 145 void
146 146 fatal(char * message, ...)
147 147 {
148 148 va_list args;
149 149
150 150 va_start(args, message);
151 151 (void) fflush(stdout);
152 152 #ifdef DISTRIBUTED
153 153 (void) fprintf(stderr, catgets(catd, 1, 262, "dmake: Fatal error: "));
154 154 #else
155 155 (void) fprintf(stderr, catgets(catd, 1, 263, "make: Fatal error: "));
156 156 #endif
↓ open down ↓ |
156 lines elided |
↑ open up ↑ |
157 157 (void) vfprintf(stderr, message, args);
158 158 (void) fprintf(stderr, "\n");
159 159 va_end(args);
160 160 if (report_pwd) {
161 161 (void) fprintf(stderr,
162 162 catgets(catd, 1, 156, "Current working directory %s\n"),
163 163 get_current_path());
164 164 }
165 165 (void) fflush(stderr);
166 166 if (fatal_in_progress) {
167 -#if defined(SUN5_0) || defined(HP_UX) || defined(linux)
168 167 exit_status = 1;
169 -#endif
170 168 exit(1);
171 169 }
172 170 fatal_in_progress = true;
173 171 #ifdef TEAMWARE_MAKE_CMN
174 172 /* Let all parallel children finish */
175 173 if ((dmake_mode_type == parallel_mode) &&
176 174 (parallel_process_cnt > 0)) {
177 175 (void) fprintf(stderr,
178 176 catgets(catd, 1, 157, "Waiting for %d %s to finish\n"),
179 177 parallel_process_cnt,
180 178 parallel_process_cnt == 1 ?
181 179 catgets(catd, 1, 158, "job") : catgets(catd, 1, 159, "jobs"));
182 180 (void) fflush(stderr);
183 181 }
184 182
185 183 while (parallel_process_cnt > 0) {
186 184 #ifdef DISTRIBUTED
187 185 if (dmake_mode_type == distributed_mode) {
188 186 (void) await_dist(false);
189 187 } else {
190 188 await_parallel(true);
191 189 }
192 190 #else
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
193 191 await_parallel(true);
194 192 #endif
195 193 finish_children(false);
196 194 }
197 195 #endif
198 196
199 197 #if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
200 198 job_adjust_fini();
201 199 #endif
202 200
203 -#if defined(SUN5_0) || defined(HP_UX) || defined(linux)
204 201 exit_status = 1;
205 -#endif
206 202 exit(1);
207 203 }
208 204
209 205 /*
210 206 * warning(format, args...)
211 207 *
212 208 * Print a message and continue.
213 209 *
214 210 * Parameters:
215 211 * format printf type format string
216 212 * args Arguments to match the format
217 213 *
218 214 * Global variables used:
219 215 * report_pwd Should we report the current path?
220 216 */
221 217 /*VARARGS*/
222 218 void
223 219 warning(char * message, ...)
224 220 {
225 221 va_list args;
226 222
227 223 va_start(args, message);
228 224 (void) fflush(stdout);
229 225 #ifdef DISTRIBUTED
230 226 (void) fprintf(stderr, catgets(catd, 1, 264, "dmake: Warning: "));
231 227 #else
232 228 (void) fprintf(stderr, catgets(catd, 1, 265, "make: Warning: "));
233 229 #endif
234 230 (void) vfprintf(stderr, message, args);
235 231 (void) fprintf(stderr, "\n");
236 232 va_end(args);
237 233 if (report_pwd) {
238 234 (void) fprintf(stderr,
239 235 catgets(catd, 1, 161, "Current working directory %s\n"),
240 236 get_current_path());
241 237 }
242 238 (void) fflush(stderr);
243 239 }
244 240
245 241 /*
246 242 * time_to_string(time)
247 243 *
248 244 * Take a numeric time value and produce
249 245 * a proper string representation.
250 246 *
251 247 * Return value:
252 248 * The string representation of the time
253 249 *
254 250 * Parameters:
255 251 * time The time we need to translate
256 252 *
257 253 * Global variables used:
258 254 */
259 255 char *
260 256 time_to_string(const timestruc_t &time)
261 257 {
262 258 struct tm *tm;
263 259 char buf[128];
264 260
265 261 if (time == file_doesnt_exist) {
266 262 return catgets(catd, 1, 163, "File does not exist");
267 263 }
268 264 if (time == file_max_time) {
269 265 return catgets(catd, 1, 164, "Younger than any file");
270 266 }
271 267 tm = localtime(&time.tv_sec);
272 268 strftime(buf, sizeof (buf), NOCATGETS("%c %Z"), tm);
273 269 buf[127] = (int) nul_char;
274 270 return strdup(buf);
275 271 }
276 272
277 273 /*
278 274 * get_current_path()
279 275 *
280 276 * Stuff current_path with the current path if it isnt there already.
281 277 *
282 278 * Parameters:
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
283 279 *
284 280 * Global variables used:
285 281 */
286 282 char *
287 283 get_current_path(void)
288 284 {
289 285 char pwd[(MAXPATHLEN * MB_LEN_MAX)];
290 286 static char *current_path;
291 287
292 288 if (current_path == NULL) {
293 -#if defined(SUN5_0) || defined(HP_UX) || defined(linux)
294 289 getcwd(pwd, sizeof(pwd));
295 -#else
296 - (void) getwd(pwd);
297 -#endif
298 290 if (pwd[0] == (int) nul_char) {
299 291 pwd[0] = (int) slash_char;
300 292 pwd[1] = (int) nul_char;
301 293 #ifdef DISTRIBUTED
302 294 current_path = strdup(pwd);
303 295 } else if (IS_EQUALN(pwd, NOCATGETS("/tmp_mnt"), 8)) {
304 296 current_path = strdup(pwd + 8);
305 297 } else {
306 298 current_path = strdup(pwd);
307 299 }
308 300 #else
309 301 }
310 302 current_path = strdup(pwd);
311 303 #endif
312 304 }
313 305 return current_path;
314 306 }
315 307
316 308 /*****************************************
317 309 *
318 310 * Make internal state dumping
319 311 *
320 312 * This is a set of routines for dumping the internal make state
321 313 * Used for the -p option
322 314 */
323 315
324 316 /*
325 317 * dump_make_state()
326 318 *
327 319 * Dump make's internal state to stdout
328 320 *
329 321 * Parameters:
330 322 *
331 323 * Global variables used:
332 324 * svr4 Was ".SVR4" seen in makefile?
333 325 * svr4_name The Name ".SVR4", printed
334 326 * posix Was ".POSIX" seen in makefile?
335 327 * posix_name The Name ".POSIX", printed
336 328 * default_rule Points to the .DEFAULT rule
337 329 * default_rule_name The Name ".DEFAULT", printed
338 330 * default_target_to_build The first target to print
339 331 * dot_keep_state The Name ".KEEP_STATE", printed
340 332 * dot_keep_state_file The Name ".KEEP_STATE_FILE", printed
341 333 * hashtab The make hash table for Name blocks
342 334 * ignore_errors Was ".IGNORE" seen in makefile?
343 335 * ignore_name The Name ".IGNORE", printed
344 336 * keep_state Was ".KEEP_STATE" seen in makefile?
345 337 * percent_list The list of % rules
346 338 * precious The Name ".PRECIOUS", printed
347 339 * sccs_get_name The Name ".SCCS_GET", printed
348 340 * sccs_get_posix_name The Name ".SCCS_GET_POSIX", printed
349 341 * get_name The Name ".GET", printed
350 342 * get_posix_name The Name ".GET_POSIX", printed
351 343 * sccs_get_rule Points to the ".SCCS_GET" rule
352 344 * silent Was ".SILENT" seen in makefile?
353 345 * silent_name The Name ".SILENT", printed
354 346 * suffixes The suffix list from ".SUFFIXES"
355 347 * suffixes_name The Name ".SUFFIX", printed
356 348 */
357 349 void
358 350 dump_make_state(void)
359 351 {
360 352 Name_set::iterator p, e;
361 353 register Property prop;
362 354 register Dependency dep;
363 355 register Cmd_line rule;
364 356 Percent percent, percent_depe;
365 357
366 358 /* Default target */
367 359 if (default_target_to_build != NULL) {
368 360 print_rule(default_target_to_build);
369 361 }
370 362 (void) printf("\n");
371 363
372 364 /* .POSIX */
373 365 if (posix) {
374 366 (void) printf("%s:\n", posix_name->string_mb);
375 367 }
376 368
377 369 /* .DEFAULT */
378 370 if (default_rule != NULL) {
379 371 (void) printf("%s:\n", default_rule_name->string_mb);
380 372 for (rule = default_rule; rule != NULL; rule = rule->next) {
381 373 (void) printf("\t%s\n", rule->command_line->string_mb);
382 374 }
383 375 }
384 376
385 377 /* .IGNORE */
386 378 if (ignore_errors) {
387 379 (void) printf("%s:\n", ignore_name->string_mb);
388 380 }
389 381
390 382 /* .KEEP_STATE: */
391 383 if (keep_state) {
392 384 (void) printf("%s:\n\n", dot_keep_state->string_mb);
393 385 }
394 386
395 387 /* .PRECIOUS */
396 388 (void) printf("%s:", precious->string_mb);
397 389 for (p = hashtab.begin(), e = hashtab.end(); p != e; p++) {
398 390 if ((p->stat.is_precious) || (all_precious)) {
399 391 (void) printf(" %s", p->string_mb);
400 392 }
401 393 }
402 394 (void) printf("\n");
403 395
404 396 /* .SCCS_GET */
405 397 if (sccs_get_rule != NULL) {
406 398 (void) printf("%s:\n", sccs_get_name->string_mb);
407 399 for (rule = sccs_get_rule; rule != NULL; rule = rule->next) {
408 400 (void) printf("\t%s\n", rule->command_line->string_mb);
409 401 }
410 402 }
411 403
412 404 /* .SILENT */
413 405 if (silent) {
414 406 (void) printf("%s:\n", silent_name->string_mb);
415 407 }
416 408
417 409 /* .SUFFIXES: */
418 410 (void) printf("%s:", suffixes_name->string_mb);
419 411 for (dep = suffixes; dep != NULL; dep = dep->next) {
420 412 (void) printf(" %s", dep->name->string_mb);
421 413 build_suffix_list(dep->name);
422 414 }
423 415 (void) printf("\n\n");
424 416
425 417 /* % rules */
426 418 for (percent = percent_list;
427 419 percent != NULL;
428 420 percent = percent->next) {
429 421 (void) printf("%s:",
430 422 percent->name->string_mb);
431 423
432 424 for (percent_depe = percent->dependencies;
433 425 percent_depe != NULL;
434 426 percent_depe = percent_depe->next) {
435 427 (void) printf(" %s", percent_depe->name->string_mb);
436 428 }
437 429
438 430 (void) printf("\n");
439 431
440 432 for (rule = percent->command_template;
441 433 rule != NULL;
442 434 rule = rule->next) {
443 435 (void) printf("\t%s\n", rule->command_line->string_mb);
444 436 }
445 437 }
446 438
447 439 /* Suffix rules */
448 440 for (p = hashtab.begin(), e = hashtab.end(); p != e; p++) {
449 441 Wstring wcb(p);
450 442 if (wcb.get_string()[0] == (int) period_char) {
451 443 print_rule(p);
452 444 }
453 445 }
454 446
455 447 /* Macro assignments */
456 448 for (p = hashtab.begin(), e = hashtab.end(); p != e; p++) {
457 449 if (((prop = get_prop(p->prop, macro_prop)) != NULL) &&
458 450 (prop->body.macro.value != NULL)) {
459 451 (void) printf("%s", p->string_mb);
460 452 print_value(prop->body.macro.value,
461 453 (Daemon) prop->body.macro.daemon);
462 454 }
463 455 }
464 456 (void) printf("\n");
465 457
466 458 /* Conditional macro assignments */
467 459 for (p = hashtab.begin(), e = hashtab.end(); p != e; p++) {
468 460 for (prop = get_prop(p->prop, conditional_prop);
469 461 prop != NULL;
470 462 prop = get_prop(prop->next, conditional_prop)) {
471 463 (void) printf("%s := %s",
472 464 p->string_mb,
473 465 prop->body.conditional.name->
474 466 string_mb);
475 467 if (prop->body.conditional.append) {
476 468 printf(" +");
477 469 }
478 470 else {
479 471 printf(" ");
480 472 }
481 473 print_value(prop->body.conditional.value,
482 474 no_daemon);
483 475 }
484 476 }
485 477 (void) printf("\n");
486 478
487 479 /* All other dependencies */
488 480 for (p = hashtab.begin(), e = hashtab.end(); p != e; p++) {
489 481 if (p->colons != no_colon) {
490 482 print_rule(p);
491 483 }
492 484 }
493 485 (void) printf("\n");
494 486 }
495 487
496 488 /*
497 489 * print_rule(target)
498 490 *
499 491 * Print the rule for one target
500 492 *
501 493 * Parameters:
502 494 * target Target we print rule for
503 495 *
504 496 * Global variables used:
505 497 */
506 498 static void
507 499 print_rule(register Name target)
508 500 {
509 501 register Cmd_line rule;
510 502 register Property line;
511 503 register Dependency dependency;
512 504
513 505 if (target->dependency_printed ||
514 506 ((line = get_prop(target->prop, line_prop)) == NULL) ||
515 507 ((line->body.line.command_template == NULL) &&
516 508 (line->body.line.dependencies == NULL))) {
517 509 return;
518 510 }
519 511 target->dependency_printed = true;
520 512
521 513 (void) printf("%s:", target->string_mb);
522 514
523 515 for (dependency = line->body.line.dependencies;
524 516 dependency != NULL;
525 517 dependency = dependency->next) {
526 518 (void) printf(" %s", dependency->name->string_mb);
527 519 }
528 520
529 521 (void) printf("\n");
530 522
531 523 for (rule = line->body.line.command_template;
532 524 rule != NULL;
533 525 rule = rule->next) {
534 526 (void) printf("\t%s\n", rule->command_line->string_mb);
535 527 }
536 528 }
537 529
538 530 void
539 531 dump_target_list(void)
540 532 {
541 533 Name_set::iterator p, e;
542 534 Wstring str;
543 535
544 536 for (p = hashtab.begin(), e = hashtab.end(); p != e; p++) {
545 537 str.init(p);
546 538 wchar_t * wcb = str.get_string();
547 539 if ((p->colons != no_colon) &&
548 540 ((wcb[0] != (int) period_char) ||
549 541 ((wcb[0] == (int) period_char) &&
550 542 (wschr(wcb, (int) slash_char))))) {
551 543 print_target_n_deps(p);
552 544 }
553 545 }
554 546 }
555 547
556 548 static void
557 549 print_target_n_deps(register Name target)
558 550 {
559 551 register Cmd_line rule;
560 552 register Property line;
561 553 register Dependency dependency;
562 554
563 555 if (target->dependency_printed) {
564 556 return;
565 557 }
566 558 target->dependency_printed = true;
567 559
568 560 (void) printf("%s\n", target->string_mb);
569 561
570 562 if ((line = get_prop(target->prop, line_prop)) == NULL) {
571 563 return;
572 564 }
573 565 for (dependency = line->body.line.dependencies;
574 566 dependency != NULL;
575 567 dependency = dependency->next) {
576 568 if (!dependency->automatic) {
577 569 print_target_n_deps(dependency->name);
578 570 }
579 571 }
580 572 }
581 573
582 574 /*****************************************
583 575 *
584 576 * main() support
585 577 */
586 578
587 579 /*
588 580 * load_cached_names()
589 581 *
590 582 * Load the vector of cached names
591 583 *
592 584 * Parameters:
593 585 *
594 586 * Global variables used:
595 587 * Many many pointers to Name blocks.
596 588 */
597 589 void
598 590 load_cached_names(void)
599 591 {
600 592 char *cp;
601 593 Name dollar;
602 594
603 595 /* Load the cached_names struct */
604 596 MBSTOWCS(wcs_buffer, NOCATGETS(".BUILT_LAST_MAKE_RUN"));
605 597 built_last_make_run = GETNAME(wcs_buffer, FIND_LENGTH);
606 598 MBSTOWCS(wcs_buffer, NOCATGETS("@"));
607 599 c_at = GETNAME(wcs_buffer, FIND_LENGTH);
608 600 MBSTOWCS(wcs_buffer, NOCATGETS(" *conditionals* "));
609 601 conditionals = GETNAME(wcs_buffer, FIND_LENGTH);
610 602 /*
611 603 * A version of make was released with NSE 1.0 that used
612 604 * VERSION-1.1 but this version is identical to VERSION-1.0.
613 605 * The version mismatch code makes a special case for this
614 606 * situation. If the version number is changed from 1.0
615 607 * it should go to 1.2.
616 608 */
617 609 MBSTOWCS(wcs_buffer, NOCATGETS("VERSION-1.0"));
618 610 current_make_version = GETNAME(wcs_buffer, FIND_LENGTH);
619 611 MBSTOWCS(wcs_buffer, NOCATGETS(".SVR4"));
620 612 svr4_name = GETNAME(wcs_buffer, FIND_LENGTH);
621 613 MBSTOWCS(wcs_buffer, NOCATGETS(".POSIX"));
622 614 posix_name = GETNAME(wcs_buffer, FIND_LENGTH);
623 615 MBSTOWCS(wcs_buffer, NOCATGETS(".DEFAULT"));
624 616 default_rule_name = GETNAME(wcs_buffer, FIND_LENGTH);
625 617 #ifdef NSE
626 618 MBSTOWCS(wcs_buffer, NOCATGETS(".DERIVED_SRC"));
627 619 derived_src= GETNAME(wcs_buffer, FIND_LENGTH);
628 620 #endif
629 621 MBSTOWCS(wcs_buffer, NOCATGETS("$"));
630 622 dollar = GETNAME(wcs_buffer, FIND_LENGTH);
631 623 MBSTOWCS(wcs_buffer, NOCATGETS(".DONE"));
632 624 done = GETNAME(wcs_buffer, FIND_LENGTH);
633 625 MBSTOWCS(wcs_buffer, NOCATGETS("."));
634 626 dot = GETNAME(wcs_buffer, FIND_LENGTH);
635 627 MBSTOWCS(wcs_buffer, NOCATGETS(".KEEP_STATE"));
636 628 dot_keep_state = GETNAME(wcs_buffer, FIND_LENGTH);
637 629 MBSTOWCS(wcs_buffer, NOCATGETS(".KEEP_STATE_FILE"));
638 630 dot_keep_state_file = GETNAME(wcs_buffer, FIND_LENGTH);
639 631 MBSTOWCS(wcs_buffer, NOCATGETS(""));
640 632 empty_name = GETNAME(wcs_buffer, FIND_LENGTH);
641 633 MBSTOWCS(wcs_buffer, NOCATGETS(" FORCE"));
642 634 force = GETNAME(wcs_buffer, FIND_LENGTH);
643 635 MBSTOWCS(wcs_buffer, NOCATGETS("HOST_ARCH"));
644 636 host_arch = GETNAME(wcs_buffer, FIND_LENGTH);
645 637 MBSTOWCS(wcs_buffer, NOCATGETS("HOST_MACH"));
646 638 host_mach = GETNAME(wcs_buffer, FIND_LENGTH);
647 639 MBSTOWCS(wcs_buffer, NOCATGETS(".IGNORE"));
648 640 ignore_name = GETNAME(wcs_buffer, FIND_LENGTH);
649 641 MBSTOWCS(wcs_buffer, NOCATGETS(".INIT"));
650 642 init = GETNAME(wcs_buffer, FIND_LENGTH);
651 643 MBSTOWCS(wcs_buffer, NOCATGETS(".LOCAL"));
652 644 localhost_name = GETNAME(wcs_buffer, FIND_LENGTH);
653 645 MBSTOWCS(wcs_buffer, NOCATGETS(".make.state"));
654 646 make_state = GETNAME(wcs_buffer, FIND_LENGTH);
655 647 MBSTOWCS(wcs_buffer, NOCATGETS("MAKEFLAGS"));
656 648 makeflags = GETNAME(wcs_buffer, FIND_LENGTH);
657 649 MBSTOWCS(wcs_buffer, NOCATGETS(".MAKE_VERSION"));
658 650 make_version = GETNAME(wcs_buffer, FIND_LENGTH);
659 651 MBSTOWCS(wcs_buffer, NOCATGETS(".NO_PARALLEL"));
660 652 no_parallel_name = GETNAME(wcs_buffer, FIND_LENGTH);
661 653 MBSTOWCS(wcs_buffer, NOCATGETS(".NOT_AUTO"));
662 654 not_auto = GETNAME(wcs_buffer, FIND_LENGTH);
663 655 MBSTOWCS(wcs_buffer, NOCATGETS(".PARALLEL"));
664 656 parallel_name = GETNAME(wcs_buffer, FIND_LENGTH);
665 657 MBSTOWCS(wcs_buffer, NOCATGETS("PATH"));
666 658 path_name = GETNAME(wcs_buffer, FIND_LENGTH);
667 659 MBSTOWCS(wcs_buffer, NOCATGETS("+"));
668 660 plus = GETNAME(wcs_buffer, FIND_LENGTH);
669 661 MBSTOWCS(wcs_buffer, NOCATGETS(".PRECIOUS"));
670 662 precious = GETNAME(wcs_buffer, FIND_LENGTH);
671 663 MBSTOWCS(wcs_buffer, NOCATGETS("?"));
672 664 query = GETNAME(wcs_buffer, FIND_LENGTH);
673 665 MBSTOWCS(wcs_buffer, NOCATGETS("^"));
674 666 hat = GETNAME(wcs_buffer, FIND_LENGTH);
675 667 MBSTOWCS(wcs_buffer, NOCATGETS(".RECURSIVE"));
676 668 recursive_name = GETNAME(wcs_buffer, FIND_LENGTH);
677 669 MBSTOWCS(wcs_buffer, NOCATGETS(".SCCS_GET"));
678 670 sccs_get_name = GETNAME(wcs_buffer, FIND_LENGTH);
679 671 MBSTOWCS(wcs_buffer, NOCATGETS(".SCCS_GET_POSIX"));
680 672 sccs_get_posix_name = GETNAME(wcs_buffer, FIND_LENGTH);
681 673 MBSTOWCS(wcs_buffer, NOCATGETS(".GET"));
682 674 get_name = GETNAME(wcs_buffer, FIND_LENGTH);
683 675 MBSTOWCS(wcs_buffer, NOCATGETS(".GET_POSIX"));
684 676 get_posix_name = GETNAME(wcs_buffer, FIND_LENGTH);
685 677 MBSTOWCS(wcs_buffer, NOCATGETS("SHELL"));
686 678 shell_name = GETNAME(wcs_buffer, FIND_LENGTH);
687 679 MBSTOWCS(wcs_buffer, NOCATGETS(".SILENT"));
688 680 silent_name = GETNAME(wcs_buffer, FIND_LENGTH);
689 681 MBSTOWCS(wcs_buffer, NOCATGETS(".SUFFIXES"));
690 682 suffixes_name = GETNAME(wcs_buffer, FIND_LENGTH);
691 683 MBSTOWCS(wcs_buffer, SUNPRO_DEPENDENCIES);
692 684 sunpro_dependencies = GETNAME(wcs_buffer, FIND_LENGTH);
693 685 MBSTOWCS(wcs_buffer, NOCATGETS("TARGET_ARCH"));
694 686 target_arch = GETNAME(wcs_buffer, FIND_LENGTH);
695 687 MBSTOWCS(wcs_buffer, NOCATGETS("TARGET_MACH"));
696 688 target_mach = GETNAME(wcs_buffer, FIND_LENGTH);
697 689 MBSTOWCS(wcs_buffer, NOCATGETS("VIRTUAL_ROOT"));
698 690 virtual_root = GETNAME(wcs_buffer, FIND_LENGTH);
699 691 MBSTOWCS(wcs_buffer, NOCATGETS("VPATH"));
700 692 vpath_name = GETNAME(wcs_buffer, FIND_LENGTH);
701 693 MBSTOWCS(wcs_buffer, NOCATGETS(".WAIT"));
702 694 wait_name = GETNAME(wcs_buffer, FIND_LENGTH);
703 695
704 696 wait_name->state = build_ok;
705 697
706 698 /* Mark special targets so that the reader treats them properly */
707 699 svr4_name->special_reader = svr4_special;
708 700 posix_name->special_reader = posix_special;
709 701 built_last_make_run->special_reader = built_last_make_run_special;
710 702 default_rule_name->special_reader = default_special;
711 703 #ifdef NSE
712 704 derived_src->special_reader= derived_src_special;
713 705 #endif
714 706 dot_keep_state->special_reader = keep_state_special;
715 707 dot_keep_state_file->special_reader = keep_state_file_special;
716 708 ignore_name->special_reader = ignore_special;
717 709 make_version->special_reader = make_version_special;
718 710 no_parallel_name->special_reader = no_parallel_special;
719 711 parallel_name->special_reader = parallel_special;
720 712 localhost_name->special_reader = localhost_special;
721 713 precious->special_reader = precious_special;
722 714 sccs_get_name->special_reader = sccs_get_special;
723 715 sccs_get_posix_name->special_reader = sccs_get_posix_special;
724 716 get_name->special_reader = get_special;
725 717 get_posix_name->special_reader = get_posix_special;
726 718 silent_name->special_reader = silent_special;
↓ open down ↓ |
419 lines elided |
↑ open up ↑ |
727 719 suffixes_name->special_reader = suffixes_special;
728 720
729 721 /* The value of $$ is $ */
730 722 (void) SETVAR(dollar, dollar, false);
731 723 dollar->dollar = false;
732 724
733 725 /* Set the value of $(SHELL) */
734 726 #ifdef HP_UX
735 727 MBSTOWCS(wcs_buffer, NOCATGETS("/bin/posix/sh"));
736 728 #else
737 - #if defined(SUN5_0)
738 729 if (posix) {
739 730 MBSTOWCS(wcs_buffer, NOCATGETS("/usr/xpg4/bin/sh"));
740 731 } else {
741 732 MBSTOWCS(wcs_buffer, NOCATGETS("/bin/sh"));
742 733 }
743 - #else /* ^SUN5_0 */
744 - MBSTOWCS(wcs_buffer, NOCATGETS("/bin/sh"));
745 - #endif /* ^SUN5_0 */
746 734 #endif
747 735 (void) SETVAR(shell_name, GETNAME(wcs_buffer, FIND_LENGTH), false);
748 736
749 737 /*
750 738 * Use " FORCE" to simulate a FRC dependency for :: type
751 739 * targets with no dependencies.
752 740 */
753 741 (void) append_prop(force, line_prop);
754 742 force->stat.time = file_max_time;
755 743
756 744 /* Make sure VPATH is defined before current dir is read */
757 745 if ((cp = getenv(vpath_name->string_mb)) != NULL) {
758 746 MBSTOWCS(wcs_buffer, cp);
759 747 (void) SETVAR(vpath_name,
760 748 GETNAME(wcs_buffer, FIND_LENGTH),
761 749 false);
762 750 }
763 751
764 752 /* Check if there is NO PATH variable. If not we construct one. */
765 753 if (getenv(path_name->string_mb) == NULL) {
766 754 vroot_path = NULL;
767 755 add_dir_to_path(NOCATGETS("."), &vroot_path, -1);
768 756 add_dir_to_path(NOCATGETS("/bin"), &vroot_path, -1);
769 757 add_dir_to_path(NOCATGETS("/usr/bin"), &vroot_path, -1);
770 758 }
771 759 }
772 760
773 761 /*
774 762 * iterate on list of conditional macros in np, and place them in
775 763 * a String_rec starting with, and separated by the '$' character.
776 764 */
777 765 void
778 766 cond_macros_into_string(Name np, String_rec *buffer)
779 767 {
780 768 Macro_list macro_list;
781 769
782 770 /*
783 771 * Put the version number at the start of the string
784 772 */
785 773 MBSTOWCS(wcs_buffer, DEPINFO_FMT_VERSION);
786 774 append_string(wcs_buffer, buffer, FIND_LENGTH);
787 775 /*
788 776 * Add the rest of the conditional macros to the buffer
789 777 */
790 778 if (np->depends_on_conditional){
791 779 for (macro_list = np->conditional_macro_list;
792 780 macro_list != NULL; macro_list = macro_list->next){
793 781 append_string(macro_list->macro_name, buffer,
794 782 FIND_LENGTH);
795 783 append_char((int) equal_char, buffer);
796 784 append_string(macro_list->value, buffer, FIND_LENGTH);
797 785 append_char((int) dollar_char, buffer);
798 786 }
799 787 }
800 788 }
801 789 /*
802 790 * Copyright (c) 1987-1992 Sun Microsystems, Inc. All Rights Reserved.
803 791 * Sun considers its source code as an unpublished, proprietary
804 792 * trade secret, and it is available only under strict license
805 793 * provisions. This copyright notice is placed here only to protect
806 794 * Sun in the event the source is deemed a published work. Dissassembly,
807 795 * decompilation, or other means of reducing the object code to human
808 796 * readable form is prohibited by the license agreement under which
809 797 * this code is provided to the user or company in possession of this
810 798 * copy.
811 799 * RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
812 800 * Government is subject to restrictions as set forth in subparagraph
813 801 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
814 802 * clause at DFARS 52.227-7013 and in similar clauses in the FAR and
815 803 * NASA FAR Supplement.
816 804 *
817 805 * 1.3 91/09/30
818 806 */
819 807
820 808
821 809 /* Some includes are commented because of the includes at the beginning */
822 810 /* #include <signal.h> */
823 811 #include <sys/types.h>
824 812 #include <sys/stat.h>
825 813 #include <sys/param.h>
826 814 /* #include <string.h> */
827 815 #include <unistd.h>
828 816 #include <stdlib.h>
829 817 /* #include <stdio.h> */
830 818 /* #include <avo/find_dir.h> */
831 819 /* #ifndef TEAMWARE_MAKE_CMN
832 820 #include <avo/find_dir.h>
833 821 #endif */
834 822
835 823 /* Routines to find the base directory name from which the various components
836 824 * -executables, *crt* libraries etc will be accessed
837 825 */
838 826
839 827 /* This routine checks to see if a given filename is an executable or not.
840 828 Logically similar to the csh statement : if ( -x $i && ! -d $i )
841 829 */
842 830
843 831 static int
844 832 check_if_exec(char *file)
845 833 {
846 834 struct stat stb;
847 835 if (stat(file, &stb) < 0) {
848 836 return ( -1);
849 837 }
850 838 if (S_ISDIR(stb.st_mode)) {
851 839 return (-1);
852 840 }
853 841 if (!(stb.st_mode & S_IEXEC)) {
854 842 return ( -1);
855 843 }
856 844 return (0);
857 845 }
858 846
859 847 /* resolve - check for specified file in specified directory
860 848 * sets up dir, following symlinks.
861 849 * returns zero for success, or
862 850 * -1 for error (with errno set properly)
863 851 */
864 852 static int
865 853 resolve (const char *indir, /* search directory */
866 854 const char *cmd, /* search for name */
867 855 char *dir, /* directory buffer */
868 856 char **run) /* resultion name ptr ptr */
869 857 {
870 858 char *p;
871 859 int rv = -1;
872 860 int sll;
873 861 char symlink[MAXPATHLEN + 1];
874 862
875 863 do {
876 864 errno = ENAMETOOLONG;
877 865 if ((strlen (indir) + strlen (cmd) + 2) > (size_t) MAXPATHLEN)
878 866 break;
879 867
880 868 sprintf(dir, "%s/%s", indir, cmd);
881 869 if (check_if_exec(dir) != 0) /* check if dir is an executable */
882 870 {
883 871 break; /* Not an executable program */
884 872 }
885 873
886 874 /* follow symbolic links */
887 875 while ((sll = readlink (dir, symlink, MAXPATHLEN)) >= 0) {
888 876 symlink[sll] = 0;
889 877 if (*symlink == '/')
890 878 strcpy (dir, symlink);
891 879 else
892 880 sprintf (strrchr (dir, '/'), "/%s", symlink);
893 881 }
894 882 if (errno != EINVAL)
895 883 break;
896 884
897 885 p = strrchr (dir, '/');
898 886 *p++ = 0;
899 887 if (run) /* user wants resolution name */
900 888 *run = p;
901 889 rv = 0; /* complete, with success! */
902 890
903 891 } while (0);
904 892
905 893 return rv;
906 894 }
907 895
908 896 /*
909 897 *find_run_directory - find executable file in PATH
910 898 *
911 899 * PARAMETERS:
912 900 * cmd filename as typed by user (argv[0])
913 901 * cwd buffer from which is read the working directory
914 902 * if first character is '/' or into which is
915 903 * copied working directory name otherwise
916 904 * dir buffer into which is copied program's directory
917 905 * pgm where to return pointer to tail of cmd (may be NULL
918 906 * if not wanted)
919 907 * run where to return pointer to tail of final resolved
920 908 * name ( dir/run is the program) (may be NULL
921 909 * if not wanted)
922 910 * path user's path from environment
923 911 *
924 912 * Note: run and pgm will agree except when symbolic links have
925 913 * renamed files
926 914 *
927 915 * RETURNS:
928 916 * returns zero for success,
929 917 * -1 for error (with errno set properly).
930 918 *
931 919 * EXAMPLE:
932 920 * find_run_directory (argv[0], ".", &charray1, (char **) 0, (char **) 0,
933 921 * getenv(NOGETTEXT("PATH")));
934 922 */
935 923 extern int
936 924 find_run_directory (char *cmd,
937 925 char *cwd,
938 926 char *dir,
939 927 char **pgm,
940 928 char **run,
941 929 char *path)
942 930 {
943 931 int rv = 0;
944 932 char *f, *s;
945 933 int i;
946 934 char tmp_path[MAXPATHLEN];
947 935
948 936 if (!cmd || !*cmd || !cwd || !dir) {
949 937 errno = EINVAL; /* stupid arguments! */
950 938 return -1;
951 939 }
952 940
953 941 if (*cwd != '/')
954 942 if (!(getcwd (cwd, MAXPATHLEN)))
955 943 return -1; /* can not get working directory */
956 944
957 945 f = strrchr (cmd, '/');
958 946 if (pgm) /* user wants program name */
959 947 *pgm = f ? f + 1 : cmd;
960 948
961 949 /* get program directory */
962 950 rv = -1;
963 951 if (*cmd == '/') /* absname given */
964 952 rv = resolve ("", cmd + 1, dir, run);
965 953 else if (f) /* relname given */
966 954 rv = resolve (cwd, cmd, dir, run);
967 955 else { /* from searchpath */
968 956 if (!path || !*path) { /* if missing or null path */
969 957 tmp_path[0] = '.'; /* assume sanity */
970 958 tmp_path[1] = '\0';
971 959 } else {
972 960 strcpy(tmp_path, path);
973 961 }
974 962 f = tmp_path;
975 963 rv = -1;
976 964 errno = ENOENT; /* errno gets this if path empty */
977 965 while (*f && (rv < 0)) {
978 966 s = f;
979 967 while (*f && (*f != ':'))
980 968 ++f;
981 969 if (*f)
982 970 *f++ = 0;
983 971 if (*s == '/')
984 972 rv = resolve (s, cmd, dir, run);
985 973 else {
986 974 char abuf[MAXPATHLEN];
987 975
988 976 sprintf (abuf, "%s/%s", cwd, s);
989 977 rv = resolve (abuf, cmd, dir, run);
990 978 }
991 979 }
992 980 }
993 981
994 982 /* Remove any trailing /. */
995 983 i = strlen(dir);
996 984 if ( dir[i-2] == '/' && dir[i-1] == '.') {
997 985 dir[i-2] = '\0';
998 986 }
999 987
1000 988 return rv;
1001 989 }
1002 990
↓ open down ↓ |
247 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX