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