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