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