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