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