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