Print this page
make: unifdef for two bugfixes conditioned for unknown reasons (defined)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/bin/main.cc
+++ new/usr/src/cmd/make/bin/main.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 2006 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 /*
27 27 * main.cc
28 28 *
29 29 * make program main routine plus some helper routines
30 30 */
31 31
32 32 /*
33 33 * Included files
34 34 */
35 35 #include <bsd/bsd.h> /* bsd_signal() */
36 36
37 37
38 38 #include <locale.h> /* setlocale() */
39 39 #include <libgen.h>
40 40 #include <mk/defs.h>
41 41 #include <mksh/macro.h> /* getvar() */
42 42 #include <mksh/misc.h> /* getmem(), setup_char_semantics() */
43 43
44 44 #include <pwd.h> /* getpwnam() */
45 45 #include <setjmp.h>
46 46 #include <signal.h>
47 47 #include <stdlib.h>
48 48 #include <sys/errno.h> /* ENOENT */
49 49 #include <sys/stat.h> /* fstat() */
50 50 #include <fcntl.h> /* open() */
51 51
52 52 # include <sys/systeminfo.h> /* sysinfo() */
53 53
54 54 #include <sys/types.h> /* stat() */
↓ open down ↓ |
54 lines elided |
↑ open up ↑ |
55 55 #include <sys/wait.h> /* wait() */
56 56 #include <unistd.h> /* execv(), unlink(), access() */
57 57 #include <vroot/report.h> /* report_dependency(), get_report_file() */
58 58
59 59 // From read2.cc
60 60 extern Name normalize_name(register wchar_t *name_string, register int length);
61 61
62 62 // From parallel.cc
63 63 #define MAXJOBS_ADJUST_RFE4694000
64 64
65 -#ifdef MAXJOBS_ADJUST_RFE4694000
66 65 extern void job_adjust_fini();
67 -#endif /* MAXJOBS_ADJUST_RFE4694000 */
68 66
69 67
70 68 /*
71 69 * Defined macros
72 70 */
73 71 #define LD_SUPPORT_ENV_VAR "SGS_SUPPORT_32"
74 72 #define LD_SUPPORT_ENV_VAR_32 "SGS_SUPPORT_32"
75 73 #define LD_SUPPORT_ENV_VAR_64 "SGS_SUPPORT_64"
76 74 #define LD_SUPPORT_MAKE_LIB "libmakestate.so.1"
77 75 #ifdef __i386
78 76 #define LD_SUPPORT_MAKE_ARCH "i386"
79 77 #elif __sparc
80 78 #define LD_SUPPORT_MAKE_ARCH "sparc"
81 79 #else
82 80 #error "Unsupported architecture"
83 81 #endif
84 82
85 83 /*
86 84 * typedefs & structs
87 85 */
88 86
89 87 /*
90 88 * Static variables
91 89 */
92 90 static char *argv_zero_string;
93 91 static Boolean build_failed_ever_seen;
94 92 static Boolean continue_after_error_ever_seen; /* `-k' */
95 93 static Boolean dmake_group_specified; /* `-g' */
96 94 static Boolean dmake_max_jobs_specified; /* `-j' */
97 95 static Boolean dmake_mode_specified; /* `-m' */
98 96 static Boolean dmake_add_mode_specified; /* `-x' */
99 97 static Boolean dmake_output_mode_specified; /* `-x DMAKE_OUTPUT_MODE=' */
100 98 static Boolean dmake_compat_mode_specified; /* `-x SUN_MAKE_COMPAT_MODE=' */
101 99 static Boolean dmake_odir_specified; /* `-o' */
102 100 static Boolean dmake_rcfile_specified; /* `-c' */
103 101 static Boolean env_wins; /* `-e' */
104 102 static Boolean ignore_default_mk; /* `-r' */
105 103 static Boolean list_all_targets; /* `-T' */
106 104 static int mf_argc;
107 105 static char **mf_argv;
108 106 static Dependency_rec not_auto_depen_struct;
109 107 static Dependency not_auto_depen = ¬_auto_depen_struct;
110 108 static Boolean pmake_cap_r_specified; /* `-R' */
111 109 static Boolean pmake_machinesfile_specified; /* `-M' */
112 110 static Boolean stop_after_error_ever_seen; /* `-S' */
113 111 static Boolean trace_status; /* `-p' */
114 112
115 113 #ifdef DMAKE_STATISTICS
116 114 static Boolean getname_stat = false;
117 115 #endif
118 116
119 117 static time_t start_time;
120 118 static int g_argc;
121 119 static char **g_argv;
122 120
123 121 /*
124 122 * File table of contents
125 123 */
126 124 extern "C" void cleanup_after_exit(void);
127 125
128 126 extern "C" {
129 127 extern void dmake_exit_callback(void);
130 128 extern void dmake_message_callback(char *);
131 129 }
132 130
133 131 extern Name normalize_name(register wchar_t *name_string, register int length);
134 132
135 133 extern int main(int, char * []);
136 134
137 135 static void append_makeflags_string(Name, String);
138 136 static void doalarm(int);
139 137 static void enter_argv_values(int , char **, ASCII_Dyn_Array *);
140 138 static void make_targets(int, char **, Boolean);
141 139 static int parse_command_option(char);
142 140 static void read_command_options(int, char **);
143 141 static void read_environment(Boolean);
144 142 static void read_files_and_state(int, char **);
145 143 static Boolean read_makefile(Name, Boolean, Boolean, Boolean);
146 144 static void report_recursion(Name);
147 145 static void set_sgs_support(void);
148 146 static void setup_for_projectdir(void);
149 147 static void setup_makeflags_argv(void);
150 148 static void report_dir_enter_leave(Boolean entering);
151 149
152 150 extern void expand_value(Name, register String , Boolean);
153 151
154 152 static const char verstring[] = "illumos make";
155 153
156 154 jmp_buf jmpbuffer;
157 155
158 156 /*
159 157 * main(argc, argv)
160 158 *
161 159 * Parameters:
162 160 * argc You know what this is
163 161 * argv You know what this is
164 162 *
165 163 * Static variables used:
166 164 * list_all_targets make -T seen
167 165 * trace_status make -p seen
168 166 *
169 167 * Global variables used:
170 168 * debug_level Should we trace make actions?
171 169 * keep_state Set if .KEEP_STATE seen
172 170 * makeflags The Name "MAKEFLAGS", used to get macro
173 171 * remote_command_name Name of remote invocation cmd ("on")
174 172 * running_list List of parallel running processes
175 173 * stdout_stderr_same true if stdout and stderr are the same
176 174 * auto_dependencies The Name "SUNPRO_DEPENDENCIES"
177 175 * temp_file_directory Set to the dir where we create tmp file
178 176 * trace_reader Set to reflect tracing status
179 177 * working_on_targets Set when building user targets
180 178 */
181 179 int
182 180 main(int argc, char *argv[])
183 181 {
184 182 /*
185 183 * cp is a -> to the value of the MAKEFLAGS env var,
186 184 * which has to be regular chars.
187 185 */
188 186 register char *cp;
189 187 char make_state_dir[MAXPATHLEN];
190 188 Boolean parallel_flag = false;
191 189 char *prognameptr;
192 190 char *slash_ptr;
193 191 mode_t um;
194 192 int i;
195 193 struct itimerval value;
196 194 char def_dmakerc_path[MAXPATHLEN];
197 195 Name dmake_name, dmake_name2;
198 196 Name dmake_value, dmake_value2;
199 197 Property prop, prop2;
200 198 struct stat statbuf;
201 199 int statval;
202 200
203 201 struct stat out_stat, err_stat;
204 202 hostid = gethostid();
205 203 bsd_signals();
206 204
207 205 (void) setlocale(LC_ALL, "");
208 206
209 207
210 208 #ifdef DMAKE_STATISTICS
211 209 if (getenv("DMAKE_STATISTICS")) {
212 210 getname_stat = true;
213 211 }
214 212 #endif
215 213
216 214 #ifndef TEXT_DOMAIN
217 215 #define TEXT_DOMAIN "SYS_TEST"
218 216 #endif
219 217 textdomain(TEXT_DOMAIN);
220 218
221 219 g_argc = argc;
222 220 g_argv = (char **) malloc((g_argc + 1) * sizeof(char *));
223 221 for (i = 0; i < argc; i++) {
224 222 g_argv[i] = argv[i];
225 223 }
226 224 g_argv[i] = NULL;
227 225
228 226 /*
229 227 * Set argv_zero_string to some form of argv[0] for
230 228 * recursive MAKE builds.
231 229 */
232 230
233 231 if (*argv[0] == (int) slash_char) {
234 232 /* argv[0] starts with a slash */
235 233 argv_zero_string = strdup(argv[0]);
236 234 } else if (strchr(argv[0], (int) slash_char) == NULL) {
237 235 /* argv[0] contains no slashes */
238 236 argv_zero_string = strdup(argv[0]);
239 237 } else {
240 238 /*
241 239 * argv[0] contains at least one slash,
242 240 * but doesn't start with a slash
243 241 */
244 242 char *tmp_current_path;
245 243 char *tmp_string;
246 244
247 245 tmp_current_path = get_current_path();
248 246 tmp_string = getmem(strlen(tmp_current_path) + 1 +
249 247 strlen(argv[0]) + 1);
250 248 (void) sprintf(tmp_string,
251 249 "%s/%s",
252 250 tmp_current_path,
253 251 argv[0]);
254 252 argv_zero_string = strdup(tmp_string);
255 253 retmem_mb(tmp_string);
256 254 }
257 255
258 256 /*
259 257 * The following flags are reset if we don't have the
260 258 * (.nse_depinfo or .make.state) files locked and only set
261 259 * AFTER the file has been locked. This ensures that if the user
262 260 * interrupts the program while file_lock() is waiting to lock
263 261 * the file, the interrupt handler doesn't remove a lock
264 262 * that doesn't belong to us.
265 263 */
266 264 make_state_lockfile = NULL;
267 265 make_state_locked = false;
268 266
269 267
270 268 /*
271 269 * look for last slash char in the path to look at the binary
272 270 * name. This is to resolve the hard link and invoke make
273 271 * in svr4 mode.
274 272 */
275 273
276 274 /* Sun OS make standart */
277 275 svr4 = false;
278 276 posix = false;
279 277 if(!strcmp(argv_zero_string, "/usr/xpg4/bin/make")) {
280 278 svr4 = false;
281 279 posix = true;
282 280 } else {
283 281 prognameptr = strrchr(argv[0], '/');
284 282 if(prognameptr) {
285 283 prognameptr++;
286 284 } else {
287 285 prognameptr = argv[0];
288 286 }
289 287 if(!strcmp(prognameptr, "svr4.make")) {
290 288 svr4 = true;
291 289 posix = false;
292 290 }
293 291 }
294 292 if (getenv(USE_SVR4_MAKE) || getenv("USE_SVID")){
295 293 svr4 = true;
296 294 posix = false;
297 295 }
298 296
299 297 /*
300 298 * Find the dmake_compat_mode: posix, sun, svr4, or gnu_style, .
301 299 */
302 300 char * dmake_compat_mode_var = getenv("SUN_MAKE_COMPAT_MODE");
303 301 if (dmake_compat_mode_var != NULL) {
304 302 if (0 == strcasecmp(dmake_compat_mode_var, "GNU")) {
305 303 gnu_style = true;
306 304 }
307 305 //svr4 = false;
308 306 //posix = false;
309 307 }
310 308
311 309 /*
312 310 * Temporary directory set up.
313 311 */
314 312 char * tmpdir_var = getenv("TMPDIR");
315 313 if (tmpdir_var != NULL && *tmpdir_var == '/' && strlen(tmpdir_var) < MAXPATHLEN) {
316 314 strcpy(mbs_buffer, tmpdir_var);
317 315 for (tmpdir_var = mbs_buffer+strlen(mbs_buffer);
318 316 *(--tmpdir_var) == '/' && tmpdir_var > mbs_buffer;
319 317 *tmpdir_var = '\0');
320 318 if (strlen(mbs_buffer) + 32 < MAXPATHLEN) { /* 32 = strlen("/dmake.stdout.%d.%d.XXXXXX") */
321 319 sprintf(mbs_buffer2, "%s/dmake.tst.%d.XXXXXX",
322 320 mbs_buffer, getpid());
323 321 int fd = mkstemp(mbs_buffer2);
324 322 if (fd >= 0) {
325 323 close(fd);
326 324 unlink(mbs_buffer2);
327 325 tmpdir = strdup(mbs_buffer);
328 326 }
329 327 }
330 328 }
331 329
332 330 /* find out if stdout and stderr point to the same place */
333 331 if (fstat(1, &out_stat) < 0) {
334 332 fatal(gettext("fstat of standard out failed: %s"), errmsg(errno));
335 333 }
336 334 if (fstat(2, &err_stat) < 0) {
337 335 fatal(gettext("fstat of standard error failed: %s"), errmsg(errno));
338 336 }
339 337 if ((out_stat.st_dev == err_stat.st_dev) &&
340 338 (out_stat.st_ino == err_stat.st_ino)) {
341 339 stdout_stderr_same = true;
342 340 } else {
343 341 stdout_stderr_same = false;
344 342 }
345 343 /* Make the vroot package scan the path using shell semantics */
346 344 set_path_style(0);
347 345
348 346 setup_char_semantics();
349 347
350 348 setup_for_projectdir();
351 349
352 350 /*
353 351 * If running with .KEEP_STATE, curdir will be set with
354 352 * the connected directory.
355 353 */
356 354 (void) atexit(cleanup_after_exit);
357 355
358 356 load_cached_names();
359 357
360 358 /*
361 359 * Set command line flags
362 360 */
363 361 setup_makeflags_argv();
364 362 read_command_options(mf_argc, mf_argv);
365 363 read_command_options(argc, argv);
366 364 if (debug_level > 0) {
367 365 cp = getenv(makeflags->string_mb);
368 366 (void) printf(gettext("MAKEFLAGS value: %s\n"), cp == NULL ? "" : cp);
369 367 }
370 368
371 369 setup_interrupt(handle_interrupt);
372 370
373 371 read_files_and_state(argc, argv);
374 372
375 373 /*
376 374 * Find the dmake_output_mode: TXT1, TXT2 or HTML1.
377 375 */
378 376 MBSTOWCS(wcs_buffer, "DMAKE_OUTPUT_MODE");
379 377 dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
380 378 prop2 = get_prop(dmake_name2->prop, macro_prop);
381 379 if (prop2 == NULL) {
382 380 /* DMAKE_OUTPUT_MODE not defined, default to TXT1 mode */
383 381 output_mode = txt1_mode;
384 382 } else {
385 383 dmake_value2 = prop2->body.macro.value;
386 384 if ((dmake_value2 == NULL) ||
387 385 (IS_EQUAL(dmake_value2->string_mb, "TXT1"))) {
388 386 output_mode = txt1_mode;
389 387 } else if (IS_EQUAL(dmake_value2->string_mb, "TXT2")) {
390 388 output_mode = txt2_mode;
391 389 } else if (IS_EQUAL(dmake_value2->string_mb, "HTML1")) {
392 390 output_mode = html1_mode;
393 391 } else {
394 392 warning(gettext("Unsupported value `%s' for DMAKE_OUTPUT_MODE after -x flag (ignored)"),
395 393 dmake_value2->string_mb);
396 394 }
397 395 }
398 396 /*
399 397 * Find the dmake_mode: parallel, or serial.
400 398 */
401 399 if ((!pmake_cap_r_specified) &&
402 400 (!pmake_machinesfile_specified)) {
403 401 char *s = strdup(argv[0]);
404 402
405 403 MBSTOWCS(wcs_buffer, "DMAKE_MODE");
406 404 dmake_name2 = GETNAME(wcs_buffer, FIND_LENGTH);
407 405 prop2 = get_prop(dmake_name2->prop, macro_prop);
408 406 // If we're invoked as 'make' run serially, regardless of DMAKE_MODE
409 407 // If we're invoked as 'make' but passed -j, run parallel
410 408 // If we're invoked as 'dmake', without DMAKE_MODE, default parallel
411 409 // If we're invoked as 'dmake' and DMAKE_MODE is set, honour it.
412 410 if ((strcmp(basename(s), "make") == 0) &&
413 411 !dmake_max_jobs_specified) {
414 412 dmake_mode_type = serial_mode;
415 413 no_parallel = true;
416 414 } else if (prop2 == NULL) {
417 415 /* DMAKE_MODE not defined, default based on our name */
418 416 char *s = strdup(argv[0]);
419 417
420 418 if (strcmp(basename(s), "dmake") == 0) {
421 419 dmake_mode_type = parallel_mode;
422 420 no_parallel = false;
423 421 }
424 422 } else {
425 423 dmake_value2 = prop2->body.macro.value;
426 424 if (IS_EQUAL(dmake_value2->string_mb, "parallel")) {
427 425 dmake_mode_type = parallel_mode;
428 426 no_parallel = false;
429 427 } else if (IS_EQUAL(dmake_value2->string_mb, "serial")) {
430 428 dmake_mode_type = serial_mode;
431 429 no_parallel = true;
432 430 } else {
433 431 fatal(gettext("Unknown dmake mode argument `%s' after -m flag"), dmake_value2->string_mb);
434 432 }
435 433 }
436 434 free(s);
437 435 }
438 436
439 437 parallel_flag = true;
440 438 putenv(strdup("DMAKE_CHILD=TRUE"));
441 439
442 440 //
443 441 // If dmake is running with -t option, set dmake_mode_type to serial.
444 442 // This is done because doname() calls touch_command() that runs serially.
445 443 // If we do not do that, maketool will have problems.
446 444 //
447 445 if(touch) {
448 446 dmake_mode_type = serial_mode;
449 447 no_parallel = true;
450 448 }
451 449
452 450 /*
453 451 * Check whether stdout and stderr are physically same.
454 452 * This is in order to decide whether we need to redirect
455 453 * stderr separately from stdout.
456 454 * This check is performed only if __DMAKE_SEPARATE_STDERR
457 455 * is not set. This variable may be used in order to preserve
458 456 * the 'old' behaviour.
459 457 */
460 458 out_err_same = true;
461 459 char * dmake_sep_var = getenv("__DMAKE_SEPARATE_STDERR");
462 460 if (dmake_sep_var == NULL || (0 != strcasecmp(dmake_sep_var, "NO"))) {
463 461 struct stat stdout_stat;
464 462 struct stat stderr_stat;
465 463 if( (fstat(1, &stdout_stat) == 0)
466 464 && (fstat(2, &stderr_stat) == 0) )
467 465 {
468 466 if( (stdout_stat.st_dev != stderr_stat.st_dev)
469 467 || (stdout_stat.st_ino != stderr_stat.st_ino) )
470 468 {
471 469 out_err_same = false;
472 470 }
473 471 }
474 472 }
475 473
476 474
477 475 /*
478 476 * Enable interrupt handler for alarms
479 477 */
480 478 (void) bsd_signal(SIGALRM, (SIG_PF)doalarm);
481 479
482 480 /*
483 481 * Check if make should report
484 482 */
485 483 if (getenv(sunpro_dependencies->string_mb) != NULL) {
486 484 FILE *report_file;
487 485
488 486 report_dependency("");
489 487 report_file = get_report_file();
490 488 if ((report_file != NULL) && (report_file != (FILE*)-1)) {
491 489 (void) fprintf(report_file, "\n");
492 490 }
493 491 }
494 492
495 493 /*
496 494 * Make sure SUNPRO_DEPENDENCIES is exported (or not) properly.
497 495 */
498 496 if (keep_state) {
499 497 maybe_append_prop(sunpro_dependencies, macro_prop)->
500 498 body.macro.exported = true;
501 499 } else {
502 500 maybe_append_prop(sunpro_dependencies, macro_prop)->
503 501 body.macro.exported = false;
504 502 }
505 503
506 504 working_on_targets = true;
507 505 if (trace_status) {
508 506 dump_make_state();
509 507 fclose(stdout);
510 508 fclose(stderr);
511 509 exit_status = 0;
512 510 exit(0);
513 511 }
514 512 if (list_all_targets) {
515 513 dump_target_list();
516 514 fclose(stdout);
517 515 fclose(stderr);
518 516 exit_status = 0;
519 517 exit(0);
520 518 }
521 519 trace_reader = false;
522 520
523 521 /*
524 522 * Set temp_file_directory to the directory the .make.state
525 523 * file is written to.
526 524 */
527 525 if ((slash_ptr = strrchr(make_state->string_mb, (int) slash_char)) == NULL) {
528 526 temp_file_directory = strdup(get_current_path());
529 527 } else {
530 528 *slash_ptr = (int) nul_char;
531 529 (void) strcpy(make_state_dir, make_state->string_mb);
532 530 *slash_ptr = (int) slash_char;
533 531 /* when there is only one slash and it's the first
534 532 ** character, make_state_dir should point to '/'.
535 533 */
536 534 if(make_state_dir[0] == '\0') {
537 535 make_state_dir[0] = '/';
538 536 make_state_dir[1] = '\0';
539 537 }
540 538 if (make_state_dir[0] == (int) slash_char) {
541 539 temp_file_directory = strdup(make_state_dir);
542 540 } else {
543 541 char tmp_current_path2[MAXPATHLEN];
544 542
545 543 (void) sprintf(tmp_current_path2,
546 544 "%s/%s",
547 545 get_current_path(),
548 546 make_state_dir);
549 547 temp_file_directory = strdup(tmp_current_path2);
550 548 }
551 549 }
552 550
553 551
554 552 report_dir_enter_leave(true);
555 553
556 554 make_targets(argc, argv, parallel_flag);
557 555
558 556 report_dir_enter_leave(false);
559 557
560 558 if (build_failed_ever_seen) {
561 559 if (posix) {
562 560 exit_status = 1;
563 561 }
564 562 exit(1);
565 563 }
566 564 exit_status = 0;
567 565 exit(0);
568 566 /* NOTREACHED */
569 567 }
570 568
571 569 /*
572 570 * cleanup_after_exit()
573 571 *
574 572 * Called from exit(), performs cleanup actions.
575 573 *
576 574 * Parameters:
577 575 * status The argument exit() was called with
578 576 * arg Address of an argument vector to
579 577 * cleanup_after_exit()
580 578 *
581 579 * Global variables used:
582 580 * command_changed Set if we think .make.state should be rewritten
583 581 * current_line Is set we set commands_changed
584 582 * do_not_exec_rule
585 583 * True if -n flag on
586 584 * done The Name ".DONE", rule we run
587 585 * keep_state Set if .KEEP_STATE seen
588 586 * parallel True if building in parallel
589 587 * quest If -q is on we do not run .DONE
590 588 * report_dependencies
591 589 * True if -P flag on
592 590 * running_list List of parallel running processes
593 591 * temp_file_name The temp file is removed, if any
594 592 */
595 593 extern "C" void
596 594 cleanup_after_exit(void)
597 595 {
598 596 Running rp;
599 597
600 598 extern long getname_bytes_count;
601 599 extern long getname_names_count;
602 600 extern long getname_struct_count;
603 601 extern long freename_bytes_count;
604 602 extern long freename_names_count;
605 603 extern long freename_struct_count;
606 604 extern long other_alloc;
607 605
608 606 extern long env_alloc_num;
609 607 extern long env_alloc_bytes;
610 608
611 609
612 610 #ifdef DMAKE_STATISTICS
613 611 if(getname_stat) {
614 612 printf(">>> Getname statistics:\n");
615 613 printf(" Allocated:\n");
616 614 printf(" Names: %ld\n", getname_names_count);
617 615 printf(" Strings: %ld Kb (%ld bytes)\n", getname_bytes_count/1000, getname_bytes_count);
618 616 printf(" Structs: %ld Kb (%ld bytes)\n", getname_struct_count/1000, getname_struct_count);
619 617 printf(" Total bytes: %ld Kb (%ld bytes)\n", getname_struct_count/1000 + getname_bytes_count/1000, getname_struct_count + getname_bytes_count);
620 618
621 619 printf("\n Unallocated: %ld\n", freename_names_count);
622 620 printf(" Names: %ld\n", freename_names_count);
623 621 printf(" Strings: %ld Kb (%ld bytes)\n", freename_bytes_count/1000, freename_bytes_count);
624 622 printf(" Structs: %ld Kb (%ld bytes)\n", freename_struct_count/1000, freename_struct_count);
625 623 printf(" Total bytes: %ld Kb (%ld bytes)\n", freename_struct_count/1000 + freename_bytes_count/1000, freename_struct_count + freename_bytes_count);
626 624
627 625 printf("\n Total used: %ld Kb (%ld bytes)\n", (getname_struct_count/1000 + getname_bytes_count/1000) - (freename_struct_count/1000 + freename_bytes_count/1000), (getname_struct_count + getname_bytes_count) - (freename_struct_count + freename_bytes_count));
628 626
629 627 printf("\n>>> Other:\n");
630 628 printf(
631 629 " Env (%ld): %ld Kb (%ld bytes)\n",
632 630 env_alloc_num,
633 631 env_alloc_bytes/1000,
634 632 env_alloc_bytes
635 633 );
636 634
637 635 }
638 636 #endif
639 637
640 638 parallel = false;
641 639 /* If we used the SVR4_MAKE, don't build .DONE or .FAILED */
642 640 if (!getenv(USE_SVR4_MAKE)){
643 641 /* Build the target .DONE or .FAILED if we caught an error */
644 642 if (!quest && !list_all_targets) {
645 643 Name failed_name;
646 644
647 645 MBSTOWCS(wcs_buffer, ".FAILED");
648 646 failed_name = GETNAME(wcs_buffer, FIND_LENGTH);
649 647 if ((exit_status != 0) && (failed_name->prop != NULL)) {
650 648 /*
651 649 * [tolik] switch DMake to serial mode
652 650 */
653 651 dmake_mode_type = serial_mode;
654 652 no_parallel = true;
655 653 (void) doname(failed_name, false, true);
656 654 } else {
657 655 if (!trace_status) {
658 656 /*
659 657 * Switch DMake to serial mode
660 658 */
661 659 dmake_mode_type = serial_mode;
662 660 no_parallel = true;
663 661 (void) doname(done, false, true);
664 662 }
665 663 }
666 664 }
667 665 }
668 666 /*
669 667 * Remove the temp file utilities report dependencies thru if it
670 668 * is still around
671 669 */
672 670 if (temp_file_name != NULL) {
673 671 (void) unlink(temp_file_name->string_mb);
674 672 }
675 673 /*
676 674 * Do not save the current command in .make.state if make
677 675 * was interrupted.
678 676 */
679 677 if (current_line != NULL) {
680 678 command_changed = true;
681 679 current_line->body.line.command_used = NULL;
682 680 }
683 681 /*
684 682 * For each parallel build process running, remove the temp files
685 683 * and zap the command line so it won't be put in .make.state
686 684 */
687 685 for (rp = running_list; rp != NULL; rp = rp->next) {
688 686 if (rp->temp_file != NULL) {
689 687 (void) unlink(rp->temp_file->string_mb);
690 688 }
691 689 if (rp->stdout_file != NULL) {
692 690 (void) unlink(rp->stdout_file);
693 691 retmem_mb(rp->stdout_file);
694 692 rp->stdout_file = NULL;
695 693 }
696 694 if (rp->stderr_file != NULL) {
697 695 (void) unlink(rp->stderr_file);
698 696 retmem_mb(rp->stderr_file);
699 697 rp->stderr_file = NULL;
700 698 }
701 699 command_changed = true;
702 700 /*
703 701 line = get_prop(rp->target->prop, line_prop);
704 702 if (line != NULL) {
705 703 line->body.line.command_used = NULL;
706 704 }
707 705 */
↓ open down ↓ |
630 lines elided |
↑ open up ↑ |
708 706 }
709 707 /* Remove the statefile lock file if the file has been locked */
710 708 if ((make_state_lockfile != NULL) && (make_state_locked)) {
711 709 (void) unlink(make_state_lockfile);
712 710 make_state_lockfile = NULL;
713 711 make_state_locked = false;
714 712 }
715 713 /* Write .make.state */
716 714 write_state_file(1, (Boolean) 1);
717 715
718 -#if defined (TEAMWARE_MAKE_CMN) && defined (MAXJOBS_ADJUST_RFE4694000)
719 716 job_adjust_fini();
720 -#endif
721 717 }
722 718
723 719 /*
724 720 * handle_interrupt()
725 721 *
726 722 * This is where C-C traps are caught.
727 723 *
728 724 * Parameters:
729 725 *
730 726 * Global variables used (except DMake 1.0):
731 727 * current_target Sometimes the current target is removed
732 728 * do_not_exec_rule But not if -n is on
733 729 * quest or -q
734 730 * running_list List of parallel running processes
735 731 * touch Current target is not removed if -t on
736 732 */
737 733 void
738 734 handle_interrupt(int)
739 735 {
740 736 Property member;
741 737 Running rp;
742 738
743 739 (void) fflush(stdout);
744 740 if (childPid > 0) {
745 741 kill(childPid, SIGTERM);
746 742 childPid = -1;
747 743 }
748 744 for (rp = running_list; rp != NULL; rp = rp->next) {
749 745 if (rp->state != build_running) {
750 746 continue;
751 747 }
752 748 if (rp->pid > 0) {
753 749 kill(rp->pid, SIGTERM);
754 750 rp->pid = -1;
755 751 }
756 752 }
757 753 if (getpid() == getpgrp()) {
758 754 bsd_signal(SIGTERM, SIG_IGN);
759 755 kill (-getpid(), SIGTERM);
760 756 }
761 757 /* Clean up all parallel children already finished */
762 758 finish_children(false);
763 759
764 760 /* Make sure the processes running under us terminate first */
765 761
766 762 while (wait((int *) NULL) != -1);
767 763 /* Delete the current targets unless they are precious */
768 764 if ((current_target != NULL) &&
769 765 current_target->is_member &&
770 766 ((member = get_prop(current_target->prop, member_prop)) != NULL)) {
771 767 current_target = member->body.member.library;
772 768 }
773 769 if (!do_not_exec_rule &&
774 770 !touch &&
775 771 !quest &&
776 772 (current_target != NULL) &&
777 773 !(current_target->stat.is_precious || all_precious)) {
778 774
779 775 /* BID_1030811 */
780 776 /* azv 16 Oct 95 */
781 777 current_target->stat.time = file_no_time;
782 778
783 779 if (exists(current_target) != file_doesnt_exist) {
784 780 (void) fprintf(stderr,
785 781 "\n*** %s ",
786 782 current_target->string_mb);
787 783 if (current_target->stat.is_dir) {
788 784 (void) fprintf(stderr,
789 785 gettext("not removed.\n"),
790 786 current_target->string_mb);
791 787 } else if (unlink(current_target->string_mb) == 0) {
792 788 (void) fprintf(stderr,
793 789 gettext("removed.\n"),
794 790 current_target->string_mb);
795 791 } else {
796 792 (void) fprintf(stderr,
797 793 gettext("could not be removed: %s.\n"),
798 794 current_target->string_mb,
799 795 errmsg(errno));
800 796 }
801 797 }
802 798 }
803 799 for (rp = running_list; rp != NULL; rp = rp->next) {
804 800 if (rp->state != build_running) {
805 801 continue;
806 802 }
807 803 if (rp->target->is_member &&
808 804 ((member = get_prop(rp->target->prop, member_prop)) !=
809 805 NULL)) {
810 806 rp->target = member->body.member.library;
811 807 }
812 808 if (!do_not_exec_rule &&
813 809 !touch &&
814 810 !quest &&
815 811 !(rp->target->stat.is_precious || all_precious)) {
816 812
817 813 rp->target->stat.time = file_no_time;
818 814 if (exists(rp->target) != file_doesnt_exist) {
819 815 (void) fprintf(stderr,
820 816 "\n*** %s ",
821 817 rp->target->string_mb);
822 818 if (rp->target->stat.is_dir) {
823 819 (void) fprintf(stderr,
824 820 gettext("not removed.\n"),
825 821 rp->target->string_mb);
826 822 } else if (unlink(rp->target->string_mb) == 0) {
827 823 (void) fprintf(stderr,
828 824 gettext("removed.\n"),
829 825 rp->target->string_mb);
830 826 } else {
831 827 (void) fprintf(stderr,
832 828 gettext("could not be removed: %s.\n"),
833 829 rp->target->string_mb,
834 830 errmsg(errno));
835 831 }
836 832 }
837 833 }
838 834 }
839 835
840 836
841 837 /* Have we locked .make.state or .nse_depinfo? */
842 838 if ((make_state_lockfile != NULL) && (make_state_locked)) {
843 839 unlink(make_state_lockfile);
844 840 make_state_lockfile = NULL;
845 841 make_state_locked = false;
846 842 }
847 843 /*
848 844 * Re-read .make.state file (it might be changed by recursive make)
849 845 */
850 846 check_state(NULL);
851 847
852 848 report_dir_enter_leave(false);
853 849
854 850 exit_status = 2;
855 851 exit(2);
856 852 }
857 853
858 854 /*
859 855 * doalarm(sig, ...)
860 856 *
861 857 * Handle the alarm interrupt but do nothing. Side effect is to
862 858 * cause return from wait3.
863 859 *
864 860 * Parameters:
865 861 * sig
866 862 *
867 863 * Global variables used:
868 864 */
869 865 /*ARGSUSED*/
870 866 static void
871 867 doalarm(int)
872 868 {
873 869 return;
874 870 }
875 871
876 872
877 873 /*
878 874 * read_command_options(argc, argv)
879 875 *
880 876 * Scan the cmd line options and process the ones that start with "-"
881 877 *
882 878 * Return value:
883 879 * -M argument, if any
884 880 *
885 881 * Parameters:
886 882 * argc You know what this is
887 883 * argv You know what this is
888 884 *
889 885 * Global variables used:
890 886 */
891 887 static void
892 888 read_command_options(register int argc, register char **argv)
893 889 {
894 890 register int ch;
895 891 int current_optind = 1;
896 892 int last_optind_with_double_hyphen = 0;
897 893 int last_optind;
898 894 int last_current_optind;
899 895 register int i;
900 896 register int j;
901 897 register int k;
902 898 register int makefile_next = 0; /*
903 899 * flag to note options:
904 900 * -c, f, g, j, m, o
905 901 */
906 902 const char *tptr;
907 903 const char *CMD_OPTS;
908 904
909 905 extern char *optarg;
910 906 extern int optind, opterr, optopt;
911 907
912 908 #define SUNPRO_CMD_OPTS "-~Bbc:Ddef:g:ij:K:kM:m:NnO:o:PpqRrSsTtuVvwx:"
913 909
914 910 # define SVR4_CMD_OPTS "-c:ef:g:ij:km:nO:o:pqrsTtVv"
915 911
916 912 /*
917 913 * Added V in SVR4_CMD_OPTS also, which is going to be a hidden
918 914 * option, just to make sure that the getopt doesn't fail when some
919 915 * users leave their USE_SVR4_MAKE set and try to use the makefiles
920 916 * that are designed to issue commands like $(MAKE) -V. Anyway it
921 917 * sets the same flag but ensures that getopt doesn't fail.
922 918 */
923 919
924 920 opterr = 0;
925 921 optind = 1;
926 922 while (1) {
927 923 last_optind=optind; /* Save optind and current_optind values */
928 924 last_current_optind=current_optind; /* in case we have to repeat this round. */
929 925 if (svr4) {
930 926 CMD_OPTS=SVR4_CMD_OPTS;
931 927 ch = getopt(argc, argv, SVR4_CMD_OPTS);
932 928 } else {
933 929 CMD_OPTS=SUNPRO_CMD_OPTS;
934 930 ch = getopt(argc, argv, SUNPRO_CMD_OPTS);
935 931 }
936 932 if (ch == EOF) {
937 933 if(optind < argc) {
938 934 /*
939 935 * Fixing bug 4102537:
940 936 * Strange behaviour of command make using -- option.
941 937 * Not all argv have been processed
942 938 * Skip non-flag argv and continue processing.
943 939 */
944 940 optind++;
945 941 current_optind++;
946 942 continue;
947 943 } else {
948 944 break;
949 945 }
950 946
951 947 }
952 948 if (ch == '?') {
953 949 if (optopt == '-') {
954 950 /* Bug 5060758: getopt() changed behavior (s10_60),
955 951 * and now we have to deal with cases when options
956 952 * with double hyphen appear here, from -$(MAKEFLAGS)
957 953 */
958 954 i = current_optind;
959 955 if (argv[i][0] == '-') {
960 956 if (argv[i][1] == '-') {
961 957 if (argv[i][2] != '\0') {
962 958 /* Check if this option is allowed */
963 959 tptr = strchr(CMD_OPTS, argv[i][2]);
964 960 if (tptr) {
965 961 if (last_optind_with_double_hyphen != current_optind) {
966 962 /* This is first time we are trying to fix "--"
967 963 * problem with this option. If we come here second
968 964 * time, we will go to fatal error.
969 965 */
970 966 last_optind_with_double_hyphen = current_optind;
971 967
972 968 /* Eliminate first hyphen character */
973 969 for (j=0; argv[i][j] != '\0'; j++) {
974 970 argv[i][j] = argv[i][j+1];
975 971 }
976 972
977 973 /* Repeat the processing of this argument */
978 974 optind=last_optind;
979 975 current_optind=last_current_optind;
980 976 continue;
981 977 }
982 978 }
983 979 }
984 980 }
985 981 }
986 982 }
987 983 }
988 984
989 985 if (ch == '?') {
990 986 if (svr4) {
991 987 fprintf(stderr,
992 988 gettext("Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
993 989 fprintf(stderr,
994 990 gettext(" [ -j dmake_max_jobs ][ -m dmake_mode ][ -o dmake_odir ]...\n"));
995 991 fprintf(stderr,
996 992 gettext(" [ -e ][ -i ][ -k ][ -n ][ -p ][ -q ][ -r ][ -s ][ -t ][ -v ]\n"));
997 993 tptr = strchr(SVR4_CMD_OPTS, optopt);
998 994 } else {
999 995 fprintf(stderr,
1000 996 gettext("Usage : dmake [ -f makefile ][ -c dmake_rcfile ][ -g dmake_group ]\n"));
1001 997 fprintf(stderr,
1002 998 gettext(" [ -j dmake_max_jobs ][ -K statefile ][ -m dmake_mode ][ -x MODE_NAME=VALUE ][ -o dmake_odir ]...\n"));
1003 999 fprintf(stderr,
1004 1000 gettext(" [ -d ][ -dd ][ -D ][ -DD ][ -e ][ -i ][ -k ][ -n ][ -p ][ -P ][ -u ][ -w ]\n"));
1005 1001 fprintf(stderr,
1006 1002 gettext(" [ -q ][ -r ][ -s ][ -S ][ -t ][ -v ][ -V ][ target... ][ macro=value... ][ \"macro +=value\"... ]\n"));
1007 1003 tptr = strchr(SUNPRO_CMD_OPTS, optopt);
1008 1004 }
1009 1005 if (!tptr) {
1010 1006 fatal(gettext("Unknown option `-%c'"), optopt);
1011 1007 } else {
1012 1008 fatal(gettext("Missing argument after `-%c'"), optopt);
1013 1009 }
1014 1010 }
1015 1011
1016 1012
1017 1013
1018 1014 makefile_next |= parse_command_option(ch);
1019 1015 /*
1020 1016 * If we're done processing all of the options of
1021 1017 * ONE argument string...
1022 1018 */
1023 1019 if (current_optind < optind) {
1024 1020 i = current_optind;
1025 1021 k = 0;
1026 1022 /* If there's an argument for an option... */
1027 1023 if ((optind - current_optind) > 1) {
1028 1024 k = i + 1;
1029 1025 }
1030 1026 switch (makefile_next) {
1031 1027 case 0:
1032 1028 argv[i] = NULL;
1033 1029 /* This shouldn't happen */
1034 1030 if (k) {
1035 1031 argv[k] = NULL;
1036 1032 }
1037 1033 break;
1038 1034 case 1: /* -f seen */
1039 1035 argv[i] = (char *)"-f";
1040 1036 break;
1041 1037 case 2: /* -c seen */
1042 1038 argv[i] = (char *)"-c";
1043 1039 break;
1044 1040 case 4: /* -g seen */
1045 1041 argv[i] = (char *)"-g";
1046 1042 break;
1047 1043 case 8: /* -j seen */
1048 1044 argv[i] = (char *)"-j";
1049 1045 break;
1050 1046 case 16: /* -M seen */
1051 1047 argv[i] = (char *)"-M";
1052 1048 break;
1053 1049 case 32: /* -m seen */
1054 1050 argv[i] = (char *)"-m";
1055 1051 break;
1056 1052 case 128: /* -O seen */
1057 1053 argv[i] = (char *)"-O";
1058 1054 break;
1059 1055 case 256: /* -K seen */
1060 1056 argv[i] = (char *)"-K";
1061 1057 break;
1062 1058 case 512: /* -o seen */
1063 1059 argv[i] = (char *)"-o";
1064 1060 break;
1065 1061 case 1024: /* -x seen */
1066 1062 argv[i] = (char *)"-x";
1067 1063 break;
1068 1064 default: /* > 1 of -c, f, g, j, K, M, m, O, o, x seen */
1069 1065 fatal(gettext("Illegal command line. More than one option requiring\nan argument given in the same argument group"));
1070 1066 }
1071 1067
1072 1068 makefile_next = 0;
1073 1069 current_optind = optind;
1074 1070 }
1075 1071 }
1076 1072 }
1077 1073
1078 1074 static void
1079 1075 quote_str(char *str, char *qstr)
1080 1076 {
1081 1077 char *to;
1082 1078 char *from;
1083 1079
1084 1080 to = qstr;
1085 1081 for (from = str; *from; from++) {
1086 1082 switch (*from) {
1087 1083 case ';': /* End of command */
1088 1084 case '(': /* Start group */
1089 1085 case ')': /* End group */
1090 1086 case '{': /* Start group */
1091 1087 case '}': /* End group */
1092 1088 case '[': /* Reg expr - any of a set of chars */
1093 1089 case ']': /* End of set of chars */
1094 1090 case '|': /* Pipe or logical-or */
1095 1091 case '^': /* Old-fashioned pipe */
1096 1092 case '&': /* Background or logical-and */
1097 1093 case '<': /* Redirect stdin */
1098 1094 case '>': /* Redirect stdout */
1099 1095 case '*': /* Reg expr - any sequence of chars */
1100 1096 case '?': /* Reg expr - any single char */
1101 1097 case '$': /* Variable substitution */
1102 1098 case '\'': /* Singe quote - turn off all magic */
1103 1099 case '"': /* Double quote - span whitespace */
1104 1100 case '`': /* Backquote - run a command */
1105 1101 case '#': /* Comment */
1106 1102 case ' ': /* Space (for MACRO=value1 value2 */
1107 1103 case '\\': /* Escape char - turn off magic of next char */
1108 1104 *to++ = '\\';
1109 1105 break;
1110 1106
1111 1107 default:
1112 1108 break;
1113 1109 }
1114 1110 *to++ = *from;
1115 1111 }
1116 1112 *to = '\0';
1117 1113 }
1118 1114
1119 1115 static void
1120 1116 unquote_str(char *str, char *qstr)
1121 1117 {
1122 1118 char *to;
1123 1119 char *from;
1124 1120
1125 1121 to = qstr;
1126 1122 for (from = str; *from; from++) {
1127 1123 if (*from == '\\') {
1128 1124 from++;
1129 1125 }
1130 1126 *to++ = *from;
1131 1127 }
1132 1128 *to = '\0';
1133 1129 }
1134 1130
1135 1131 /*
1136 1132 * Convert the MAKEFLAGS string value into a vector of char *, similar
1137 1133 * to argv.
1138 1134 */
1139 1135 static void
1140 1136 setup_makeflags_argv()
1141 1137 {
1142 1138 char *cp;
1143 1139 char *cp1;
1144 1140 char *cp2;
1145 1141 char *cp3;
1146 1142 char *cp_orig;
1147 1143 Boolean add_hyphen;
1148 1144 int i;
1149 1145 char tmp_char;
1150 1146
1151 1147 mf_argc = 1;
1152 1148 cp = getenv(makeflags->string_mb);
1153 1149 cp_orig = cp;
1154 1150
1155 1151 if (cp) {
1156 1152 /*
↓ open down ↓ |
426 lines elided |
↑ open up ↑ |
1157 1153 * If new MAKEFLAGS format, no need to add hyphen.
1158 1154 * If old MAKEFLAGS format, add hyphen before flags.
1159 1155 */
1160 1156
1161 1157 if ((strchr(cp, (int) hyphen_char) != NULL) ||
1162 1158 (strchr(cp, (int) equal_char) != NULL)) {
1163 1159
1164 1160 /* New MAKEFLAGS format */
1165 1161
1166 1162 add_hyphen = false;
1167 -#ifdef ADDFIX5060758
1163 +
1168 1164 /* Check if MAKEFLAGS value begins with multiple
1169 1165 * hyphen characters, and remove all duplicates.
1170 1166 * Usually it happens when the next command is
1171 1167 * used: $(MAKE) -$(MAKEFLAGS)
1172 - * This is a workaround for BugID 5060758.
1168 + *
1169 + * This was a workaround for BugID 5060758, but
1170 + * appears to have survived as a fix in make.
1173 1171 */
1174 1172 while (*cp) {
1175 1173 if (*cp != (int) hyphen_char) {
1176 1174 break;
1177 1175 }
1178 1176 cp++;
1179 1177 if (*cp == (int) hyphen_char) {
1180 1178 /* There are two hyphens. Skip one */
1181 1179 cp_orig = cp;
1182 1180 cp++;
1183 1181 }
1184 1182 if (!(*cp)) {
1185 1183 /* There are hyphens only. Skip all */
1186 1184 cp_orig = cp;
1187 1185 break;
1188 1186 }
1189 1187 }
1190 -#endif
1191 1188 } else {
1192 1189
1193 1190 /* Old MAKEFLAGS format */
1194 1191
1195 1192 add_hyphen = true;
1196 1193 }
1197 1194 }
1198 1195
1199 1196 /* Find the number of arguments in MAKEFLAGS */
1200 1197 while (cp && *cp) {
1201 1198 /* Skip white spaces */
1202 1199 while (cp && *cp && isspace(*cp)) {
1203 1200 cp++;
1204 1201 }
1205 1202 if (cp && *cp) {
1206 1203 /* Increment arg count */
1207 1204 mf_argc++;
1208 1205 /* Go to next white space */
1209 1206 while (cp && *cp && !isspace(*cp)) {
1210 1207 if(*cp == (int) backslash_char) {
1211 1208 cp++;
1212 1209 }
1213 1210 cp++;
1214 1211 }
1215 1212 }
1216 1213 }
1217 1214 /* Allocate memory for the new MAKEFLAGS argv */
1218 1215 mf_argv = (char **) malloc((mf_argc + 1) * sizeof(char *));
1219 1216 mf_argv[0] = (char *)"MAKEFLAGS";
1220 1217 /*
1221 1218 * Convert the MAKEFLAGS string value into a vector of char *,
1222 1219 * similar to argv.
1223 1220 */
1224 1221 cp = cp_orig;
1225 1222 for (i = 1; i < mf_argc; i++) {
1226 1223 /* Skip white spaces */
1227 1224 while (cp && *cp && isspace(*cp)) {
1228 1225 cp++;
1229 1226 }
1230 1227 if (cp && *cp) {
1231 1228 cp_orig = cp;
1232 1229 /* Go to next white space */
1233 1230 while (cp && *cp && !isspace(*cp)) {
1234 1231 if(*cp == (int) backslash_char) {
1235 1232 cp++;
1236 1233 }
1237 1234 cp++;
1238 1235 }
1239 1236 tmp_char = *cp;
1240 1237 *cp = (int) nul_char;
1241 1238 if (add_hyphen) {
1242 1239 mf_argv[i] = getmem(2 + strlen(cp_orig));
1243 1240 mf_argv[i][0] = '\0';
1244 1241 (void) strcat(mf_argv[i], "-");
1245 1242 // (void) strcat(mf_argv[i], cp_orig);
1246 1243 unquote_str(cp_orig, mf_argv[i]+1);
1247 1244 } else {
1248 1245 mf_argv[i] = getmem(2 + strlen(cp_orig));
1249 1246 //mf_argv[i] = strdup(cp_orig);
1250 1247 unquote_str(cp_orig, mf_argv[i]);
1251 1248 }
1252 1249 *cp = tmp_char;
1253 1250 }
1254 1251 }
1255 1252 mf_argv[i] = NULL;
1256 1253 }
1257 1254
1258 1255 /*
1259 1256 * parse_command_option(ch)
1260 1257 *
1261 1258 * Parse make command line options.
1262 1259 *
1263 1260 * Return value:
1264 1261 * Indicates if any -f -c or -M were seen
1265 1262 *
1266 1263 * Parameters:
1267 1264 * ch The character to parse
1268 1265 *
1269 1266 * Static variables used:
1270 1267 * dmake_group_specified Set for make -g
1271 1268 * dmake_max_jobs_specified Set for make -j
1272 1269 * dmake_mode_specified Set for make -m
1273 1270 * dmake_add_mode_specified Set for make -x
1274 1271 * dmake_compat_mode_specified Set for make -x SUN_MAKE_COMPAT_MODE=
1275 1272 * dmake_output_mode_specified Set for make -x DMAKE_OUTPUT_MODE=
1276 1273 * dmake_odir_specified Set for make -o
1277 1274 * dmake_rcfile_specified Set for make -c
1278 1275 * env_wins Set for make -e
1279 1276 * ignore_default_mk Set for make -r
1280 1277 * trace_status Set for make -p
1281 1278 *
1282 1279 * Global variables used:
1283 1280 * .make.state path & name set for make -K
1284 1281 * continue_after_error Set for make -k
1285 1282 * debug_level Set for make -d
1286 1283 * do_not_exec_rule Set for make -n
1287 1284 * filter_stderr Set for make -X
1288 1285 * ignore_errors_all Set for make -i
1289 1286 * no_parallel Set for make -R
1290 1287 * quest Set for make -q
1291 1288 * read_trace_level Set for make -D
1292 1289 * report_dependencies Set for make -P
1293 1290 * silent_all Set for make -s
1294 1291 * touch Set for make -t
1295 1292 */
1296 1293 static int
1297 1294 parse_command_option(register char ch)
1298 1295 {
1299 1296 static int invert_next = 0;
1300 1297 int invert_this = invert_next;
1301 1298
1302 1299 invert_next = 0;
1303 1300 switch (ch) {
1304 1301 case '-': /* Ignore "--" */
1305 1302 return 0;
1306 1303 case '~': /* Invert next option */
1307 1304 invert_next = 1;
1308 1305 return 0;
1309 1306 case 'B': /* Obsolete */
1310 1307 return 0;
1311 1308 case 'b': /* Obsolete */
1312 1309 return 0;
1313 1310 case 'c': /* Read alternative dmakerc file */
1314 1311 if (invert_this) {
1315 1312 dmake_rcfile_specified = false;
1316 1313 } else {
1317 1314 dmake_rcfile_specified = true;
1318 1315 }
1319 1316 return 2;
1320 1317 case 'D': /* Show lines read */
1321 1318 if (invert_this) {
1322 1319 read_trace_level--;
1323 1320 } else {
1324 1321 read_trace_level++;
1325 1322 }
1326 1323 return 0;
1327 1324 case 'd': /* Debug flag */
1328 1325 if (invert_this) {
1329 1326 debug_level--;
1330 1327 } else {
1331 1328 debug_level++;
1332 1329 }
1333 1330 return 0;
1334 1331 case 'e': /* Environment override flag */
1335 1332 if (invert_this) {
1336 1333 env_wins = false;
1337 1334 } else {
1338 1335 env_wins = true;
1339 1336 }
1340 1337 return 0;
1341 1338 case 'f': /* Read alternative makefile(s) */
1342 1339 return 1;
1343 1340 case 'g': /* Use alternative DMake group */
1344 1341 if (invert_this) {
1345 1342 dmake_group_specified = false;
1346 1343 } else {
1347 1344 dmake_group_specified = true;
1348 1345 }
1349 1346 return 4;
1350 1347 case 'i': /* Ignore errors */
1351 1348 if (invert_this) {
1352 1349 ignore_errors_all = false;
1353 1350 } else {
1354 1351 ignore_errors_all = true;
1355 1352 }
1356 1353 return 0;
1357 1354 case 'j': /* Use alternative DMake max jobs */
1358 1355 if (invert_this) {
1359 1356 dmake_max_jobs_specified = false;
1360 1357 } else {
1361 1358 dmake_mode_type = parallel_mode;
1362 1359 no_parallel = false;
1363 1360 dmake_max_jobs_specified = true;
1364 1361 }
1365 1362 return 8;
1366 1363 case 'K': /* Read alternative .make.state */
1367 1364 return 256;
1368 1365 case 'k': /* Keep making even after errors */
1369 1366 if (invert_this) {
1370 1367 continue_after_error = false;
1371 1368 } else {
1372 1369 continue_after_error = true;
1373 1370 continue_after_error_ever_seen = true;
1374 1371 }
1375 1372 return 0;
1376 1373 case 'M': /* Read alternative make.machines file */
1377 1374 if (invert_this) {
1378 1375 pmake_machinesfile_specified = false;
1379 1376 } else {
1380 1377 pmake_machinesfile_specified = true;
1381 1378 dmake_mode_type = parallel_mode;
1382 1379 no_parallel = false;
1383 1380 }
1384 1381 return 16;
1385 1382 case 'm': /* Use alternative DMake build mode */
1386 1383 if (invert_this) {
1387 1384 dmake_mode_specified = false;
1388 1385 } else {
1389 1386 dmake_mode_specified = true;
1390 1387 }
1391 1388 return 32;
1392 1389 case 'x': /* Use alternative DMake mode */
1393 1390 if (invert_this) {
1394 1391 dmake_add_mode_specified = false;
1395 1392 } else {
1396 1393 dmake_add_mode_specified = true;
1397 1394 }
1398 1395 return 1024;
1399 1396 case 'N': /* Reverse -n */
1400 1397 if (invert_this) {
1401 1398 do_not_exec_rule = true;
1402 1399 } else {
1403 1400 do_not_exec_rule = false;
1404 1401 }
1405 1402 return 0;
1406 1403 case 'n': /* Print, not exec commands */
1407 1404 if (invert_this) {
1408 1405 do_not_exec_rule = false;
1409 1406 } else {
1410 1407 do_not_exec_rule = true;
1411 1408 }
1412 1409 return 0;
1413 1410 case 'O': /* Integrate with maketool, obsolete */
1414 1411 return 0;
1415 1412 case 'o': /* Use alternative dmake output dir */
1416 1413 if (invert_this) {
1417 1414 dmake_odir_specified = false;
1418 1415 } else {
1419 1416 dmake_odir_specified = true;
1420 1417 }
1421 1418 return 512;
1422 1419 case 'P': /* Print for selected targets */
1423 1420 if (invert_this) {
1424 1421 report_dependencies_level--;
1425 1422 } else {
1426 1423 report_dependencies_level++;
1427 1424 }
1428 1425 return 0;
1429 1426 case 'p': /* Print description */
1430 1427 if (invert_this) {
1431 1428 trace_status = false;
1432 1429 do_not_exec_rule = false;
1433 1430 } else {
1434 1431 trace_status = true;
1435 1432 do_not_exec_rule = true;
1436 1433 }
1437 1434 return 0;
1438 1435 case 'q': /* Question flag */
1439 1436 if (invert_this) {
1440 1437 quest = false;
1441 1438 } else {
1442 1439 quest = true;
1443 1440 }
1444 1441 return 0;
1445 1442 case 'R': /* Don't run in parallel */
1446 1443 if (invert_this) {
1447 1444 pmake_cap_r_specified = false;
1448 1445 no_parallel = false;
1449 1446 } else {
1450 1447 pmake_cap_r_specified = true;
1451 1448 dmake_mode_type = serial_mode;
1452 1449 no_parallel = true;
1453 1450 }
1454 1451 return 0;
1455 1452 case 'r': /* Turn off internal rules */
1456 1453 if (invert_this) {
1457 1454 ignore_default_mk = false;
1458 1455 } else {
1459 1456 ignore_default_mk = true;
1460 1457 }
1461 1458 return 0;
1462 1459 case 'S': /* Reverse -k */
1463 1460 if (invert_this) {
1464 1461 continue_after_error = true;
1465 1462 } else {
1466 1463 continue_after_error = false;
1467 1464 stop_after_error_ever_seen = true;
1468 1465 }
1469 1466 return 0;
1470 1467 case 's': /* Silent flag */
1471 1468 if (invert_this) {
1472 1469 silent_all = false;
1473 1470 } else {
1474 1471 silent_all = true;
1475 1472 }
1476 1473 return 0;
1477 1474 case 'T': /* Print target list */
1478 1475 if (invert_this) {
1479 1476 list_all_targets = false;
1480 1477 do_not_exec_rule = false;
1481 1478 } else {
1482 1479 list_all_targets = true;
1483 1480 do_not_exec_rule = true;
1484 1481 }
1485 1482 return 0;
1486 1483 case 't': /* Touch flag */
1487 1484 if (invert_this) {
1488 1485 touch = false;
1489 1486 } else {
1490 1487 touch = true;
1491 1488 }
1492 1489 return 0;
1493 1490 case 'u': /* Unconditional flag */
1494 1491 if (invert_this) {
1495 1492 build_unconditional = false;
1496 1493 } else {
1497 1494 build_unconditional = true;
1498 1495 }
1499 1496 return 0;
1500 1497 case 'V': /* SVR4 mode */
1501 1498 svr4 = true;
1502 1499 return 0;
1503 1500 case 'v': /* Version flag */
1504 1501 if (invert_this) {
1505 1502 } else {
1506 1503 fprintf(stdout, "dmake: %s\n", verstring);
1507 1504 exit_status = 0;
1508 1505 exit(0);
1509 1506 }
1510 1507 return 0;
1511 1508 case 'w': /* Unconditional flag */
1512 1509 if (invert_this) {
1513 1510 report_cwd = false;
1514 1511 } else {
1515 1512 report_cwd = true;
1516 1513 }
1517 1514 return 0;
1518 1515 #if 0
1519 1516 case 'X': /* Filter stdout */
1520 1517 if (invert_this) {
1521 1518 filter_stderr = false;
1522 1519 } else {
1523 1520 filter_stderr = true;
1524 1521 }
1525 1522 return 0;
1526 1523 #endif
1527 1524 default:
1528 1525 break;
1529 1526 }
1530 1527 return 0;
1531 1528 }
1532 1529
1533 1530 /*
1534 1531 * setup_for_projectdir()
1535 1532 *
1536 1533 * Read the PROJECTDIR variable, if defined, and set the sccs path
1537 1534 *
1538 1535 * Parameters:
1539 1536 *
1540 1537 * Global variables used:
1541 1538 * sccs_dir_path Set to point to SCCS dir to use
1542 1539 */
1543 1540 static void
1544 1541 setup_for_projectdir(void)
1545 1542 {
1546 1543 static char path[MAXPATHLEN];
1547 1544 char cwdpath[MAXPATHLEN];
1548 1545 uid_t uid;
1549 1546 int done=0;
1550 1547
1551 1548 /* Check if we should use PROJECTDIR when reading the SCCS dir. */
1552 1549 sccs_dir_path = getenv("PROJECTDIR");
1553 1550 if ((sccs_dir_path != NULL) &&
1554 1551 (sccs_dir_path[0] != (int) slash_char)) {
1555 1552 struct passwd *pwent;
1556 1553
1557 1554 {
1558 1555 uid = getuid();
1559 1556 pwent = getpwuid(uid);
1560 1557 if (pwent == NULL) {
1561 1558 fatal(gettext("Bogus USERID "));
1562 1559 }
1563 1560 if ((pwent = getpwnam(sccs_dir_path)) == NULL) {
1564 1561 /*empty block : it'll go & check cwd */
1565 1562 }
1566 1563 else {
1567 1564 (void) sprintf(path, "%s/src", pwent->pw_dir);
1568 1565 if (access(path, F_OK) == 0) {
1569 1566 sccs_dir_path = path;
1570 1567 done = 1;
1571 1568 } else {
1572 1569 (void) sprintf(path, "%s/source", pwent->pw_dir);
1573 1570 if (access(path, F_OK) == 0) {
1574 1571 sccs_dir_path = path;
1575 1572 done = 1;
1576 1573 }
1577 1574 }
1578 1575 }
1579 1576 if (!done) {
1580 1577 if (getcwd(cwdpath, MAXPATHLEN - 1 )) {
1581 1578
1582 1579 (void) sprintf(path, "%s/%s", cwdpath,sccs_dir_path);
1583 1580 if (access(path, F_OK) == 0) {
1584 1581 sccs_dir_path = path;
1585 1582 done = 1;
1586 1583 } else {
1587 1584 fatal(gettext("Bogus PROJECTDIR '%s'"), sccs_dir_path);
1588 1585 }
1589 1586 }
1590 1587 }
1591 1588 }
1592 1589 }
1593 1590 }
1594 1591
1595 1592 char *
1596 1593 make_install_prefix(void)
1597 1594 {
1598 1595 int ret;
1599 1596 char origin[PATH_MAX];
1600 1597 char *dir;
1601 1598
1602 1599 if ((ret = readlink("/proc/self/path/a.out", origin,
1603 1600 PATH_MAX - 1)) < 0)
1604 1601 fatal("failed to read origin from /proc\n");
1605 1602
1606 1603
1607 1604 origin[ret] = '\0';
1608 1605 return strdup(dirname(origin));
1609 1606 }
1610 1607
1611 1608 static char *
1612 1609 add_to_env(const char *var, const char *value, const char *fallback)
1613 1610 {
1614 1611 const char *oldpath;
1615 1612 char *newpath;
1616 1613
1617 1614 oldpath = getenv(var);
1618 1615 if (oldpath == NULL) {
1619 1616 if (value != NULL) {
1620 1617 asprintf(&newpath, "%s=%s",
1621 1618 var, value);
1622 1619 } else {
1623 1620 asprintf(&newpath, "%s=%s",
1624 1621 var, fallback);
1625 1622 }
1626 1623 } else {
1627 1624 if (value != NULL) {
1628 1625 asprintf(&newpath, "%s=%s:%s",
1629 1626 var, oldpath, value);
1630 1627 } else {
1631 1628 asprintf(&newpath, "%s=%s:%s",
1632 1629 var, oldpath, fallback);
1633 1630 }
1634 1631 }
1635 1632
1636 1633 return (newpath);
1637 1634 }
1638 1635
1639 1636 /*
1640 1637 * set_sgs_support()
1641 1638 *
1642 1639 * Add the libmakestate.so.1 lib to the env var SGS_SUPPORT
1643 1640 * if it's not already in there.
1644 1641 * The SGS_SUPPORT env var and libmakestate.so.1 is used by
1645 1642 * the linker ld to report .make.state info back to make.
1646 1643 *
1647 1644 * In the new world we always will set the 32-bit and 64-bit versions of this
1648 1645 * variable explicitly so that we can take into account the correct isa and our
1649 1646 * prefix. So say that the prefix was /opt/local. Then we would want to search
1650 1647 * /opt/local/lib/libmakestate.so.1:libmakestate.so.1. We still want to search
1651 1648 * the original location just as a safety measure.
1652 1649 */
1653 1650 static void
1654 1651 set_sgs_support()
1655 1652 {
1656 1653 int len;
1657 1654 char *newpath, *newpath64;
1658 1655 char *lib32, *lib64;
1659 1656 static char *prev_path, *prev_path64;
1660 1657 char *origin = make_install_prefix();
1661 1658 struct stat st;
1662 1659
1663 1660 asprintf(&lib32, "%s/%s/%s", origin, "../lib",
1664 1661 LD_SUPPORT_MAKE_LIB);
1665 1662
1666 1663 if (stat(lib32, &st) != 0) {
1667 1664 free(lib32);
1668 1665 // Try the tools path
1669 1666 asprintf(&lib32, "%s/%s/%s/%s", origin, "../../lib/",
1670 1667 LD_SUPPORT_MAKE_ARCH, LD_SUPPORT_MAKE_LIB);
1671 1668
1672 1669 if (stat(lib32, &st) != 0) {
1673 1670 free(lib32);
1674 1671 lib32 = NULL;
1675 1672 }
1676 1673 }
1677 1674
1678 1675 asprintf(&lib64, "%s/%s/64/%s", origin, "../lib",
1679 1676 LD_SUPPORT_MAKE_LIB);
1680 1677
1681 1678 if (stat(lib64, &st) != 0) {
1682 1679 free(lib64);
1683 1680 // Try the tools path
1684 1681 asprintf(&lib64, "%s/%s/%s/64/%s", origin, "../../lib/",
1685 1682 LD_SUPPORT_MAKE_ARCH, LD_SUPPORT_MAKE_LIB);
1686 1683
1687 1684 if (stat(lib64, &st) != 0) {
1688 1685 free(lib64);
1689 1686 lib64 = NULL;
1690 1687 }
1691 1688 }
1692 1689
1693 1690 newpath = add_to_env(LD_SUPPORT_ENV_VAR_32, lib32, LD_SUPPORT_MAKE_LIB);
1694 1691 newpath64 = add_to_env(LD_SUPPORT_ENV_VAR_64, lib64, LD_SUPPORT_MAKE_LIB);
1695 1692
1696 1693 putenv(newpath);
1697 1694 if (prev_path) {
1698 1695 free(prev_path);
1699 1696 }
1700 1697 prev_path = newpath;
1701 1698
1702 1699 putenv(newpath64);
1703 1700 if (prev_path64) {
1704 1701 free(prev_path64);
1705 1702 }
1706 1703 prev_path64 = newpath64;
1707 1704 free(lib32);
1708 1705 free(lib64);
1709 1706 free(origin);
1710 1707 }
1711 1708
1712 1709 /*
1713 1710 * read_files_and_state(argc, argv)
1714 1711 *
1715 1712 * Read the makefiles we care about and the environment
1716 1713 * Also read the = style command line options
1717 1714 *
1718 1715 * Parameters:
1719 1716 * argc You know what this is
1720 1717 * argv You know what this is
1721 1718 *
1722 1719 * Static variables used:
1723 1720 * env_wins make -e, determines if env vars are RO
1724 1721 * ignore_default_mk make -r, determines if make.rules is read
1725 1722 * not_auto_depen dwight
1726 1723 *
1727 1724 * Global variables used:
1728 1725 * default_target_to_build Set to first proper target from file
1729 1726 * do_not_exec_rule Set to false when makfile is made
1730 1727 * dot The Name ".", used to read current dir
1731 1728 * empty_name The Name "", use as macro value
1732 1729 * keep_state Set if KEEP_STATE is in environment
1733 1730 * make_state The Name ".make.state", used to read file
1734 1731 * makefile_type Set to type of file being read
1735 1732 * makeflags The Name "MAKEFLAGS", used to set macro value
1736 1733 * not_auto dwight
1737 1734 * read_trace_level Checked to se if the reader should trace
1738 1735 * report_dependencies If -P is on we do not read .make.state
1739 1736 * trace_reader Set if reader should trace
1740 1737 * virtual_root The Name "VIRTUAL_ROOT", used to check value
1741 1738 */
1742 1739 static void
1743 1740 read_files_and_state(int argc, char **argv)
1744 1741 {
1745 1742 wchar_t buffer[1000];
1746 1743 wchar_t buffer_posix[1000];
1747 1744 register char ch;
1748 1745 register char *cp;
1749 1746 Property def_make_macro = NULL;
1750 1747 Name def_make_name;
1751 1748 Name default_makefile;
1752 1749 String_rec dest;
1753 1750 wchar_t destbuffer[STRING_BUFFER_LENGTH];
1754 1751 register int i;
1755 1752 register int j;
1756 1753 Name keep_state_name;
1757 1754 int length;
1758 1755 Name Makefile;
1759 1756 register Property macro;
1760 1757 struct stat make_state_stat;
1761 1758 Name makefile_name;
1762 1759 register int makefile_next = 0;
1763 1760 register Boolean makefile_read = false;
1764 1761 String_rec makeflags_string;
1765 1762 String_rec makeflags_string_posix;
1766 1763 String_rec * makeflags_string_current;
1767 1764 Name makeflags_value_saved;
1768 1765 register Name name;
1769 1766 Name new_make_value;
1770 1767 Boolean save_do_not_exec_rule;
1771 1768 Name sdotMakefile;
1772 1769 Name sdotmakefile_name;
1773 1770 static wchar_t state_file_str;
1774 1771 static char state_file_str_mb[MAXPATHLEN];
1775 1772 static struct _Name state_filename;
1776 1773 Boolean temp;
1777 1774 char tmp_char;
1778 1775 wchar_t *tmp_wcs_buffer;
1779 1776 register Name value;
1780 1777 ASCII_Dyn_Array makeflags_and_macro;
1781 1778 Boolean is_xpg4;
1782 1779
1783 1780 /*
1784 1781 * Remember current mode. It may be changed after reading makefile
1785 1782 * and we will have to correct MAKEFLAGS variable.
1786 1783 */
1787 1784 is_xpg4 = posix;
1788 1785
1789 1786 MBSTOWCS(wcs_buffer, "KEEP_STATE");
1790 1787 keep_state_name = GETNAME(wcs_buffer, FIND_LENGTH);
1791 1788 MBSTOWCS(wcs_buffer, "Makefile");
1792 1789 Makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1793 1790 MBSTOWCS(wcs_buffer, "makefile");
1794 1791 makefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
1795 1792 MBSTOWCS(wcs_buffer, "s.makefile");
1796 1793 sdotmakefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
1797 1794 MBSTOWCS(wcs_buffer, "s.Makefile");
1798 1795 sdotMakefile = GETNAME(wcs_buffer, FIND_LENGTH);
1799 1796
1800 1797 /*
1801 1798 * initialize global dependency entry for .NOT_AUTO
1802 1799 */
1803 1800 not_auto_depen->next = NULL;
1804 1801 not_auto_depen->name = not_auto;
1805 1802 not_auto_depen->automatic = not_auto_depen->stale = false;
1806 1803
1807 1804 /*
1808 1805 * Read internal definitions and rules.
1809 1806 */
1810 1807 if (read_trace_level > 1) {
1811 1808 trace_reader = true;
1812 1809 }
1813 1810 if (!ignore_default_mk) {
1814 1811 if (svr4) {
1815 1812 MBSTOWCS(wcs_buffer, "svr4.make.rules");
1816 1813 default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1817 1814 } else {
1818 1815 MBSTOWCS(wcs_buffer, "make.rules");
1819 1816 default_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
1820 1817 }
1821 1818 default_makefile->stat.is_file = true;
1822 1819
1823 1820 (void) read_makefile(default_makefile,
1824 1821 true,
1825 1822 false,
1826 1823 true);
1827 1824 }
1828 1825
1829 1826 /*
1830 1827 * If the user did not redefine the MAKE macro in the
1831 1828 * default makefile (make.rules), then we'd like to
1832 1829 * change the macro value of MAKE to be some form
1833 1830 * of argv[0] for recursive MAKE builds.
1834 1831 */
1835 1832 MBSTOWCS(wcs_buffer, "MAKE");
1836 1833 def_make_name = GETNAME(wcs_buffer, wslen(wcs_buffer));
1837 1834 def_make_macro = get_prop(def_make_name->prop, macro_prop);
1838 1835 if ((def_make_macro != NULL) &&
1839 1836 (IS_EQUAL(def_make_macro->body.macro.value->string_mb,
1840 1837 "make"))) {
1841 1838 MBSTOWCS(wcs_buffer, argv_zero_string);
1842 1839 new_make_value = GETNAME(wcs_buffer, wslen(wcs_buffer));
1843 1840 (void) SETVAR(def_make_name,
1844 1841 new_make_value,
1845 1842 false);
1846 1843 }
1847 1844
1848 1845 default_target_to_build = NULL;
1849 1846 trace_reader = false;
1850 1847
1851 1848 /*
1852 1849 * Read environment args. Let file args which follow override unless
1853 1850 * -e option seen. If -e option is not mentioned.
1854 1851 */
1855 1852 read_environment(env_wins);
1856 1853 if (getvar(virtual_root)->hash.length == 0) {
1857 1854 maybe_append_prop(virtual_root, macro_prop)
1858 1855 ->body.macro.exported = true;
1859 1856 MBSTOWCS(wcs_buffer, "/");
1860 1857 (void) SETVAR(virtual_root,
1861 1858 GETNAME(wcs_buffer, FIND_LENGTH),
1862 1859 false);
1863 1860 }
1864 1861
1865 1862 /*
1866 1863 * We now scan mf_argv and argv to see if we need to set
1867 1864 * any of the DMake-added options/variables in MAKEFLAGS.
1868 1865 */
1869 1866
1870 1867 makeflags_and_macro.start = 0;
1871 1868 makeflags_and_macro.size = 0;
1872 1869 enter_argv_values(mf_argc, mf_argv, &makeflags_and_macro);
1873 1870 enter_argv_values(argc, argv, &makeflags_and_macro);
1874 1871
1875 1872 /*
1876 1873 * Set MFLAGS and MAKEFLAGS
1877 1874 *
1878 1875 * Before reading makefile we do not know exactly which mode
1879 1876 * (posix or not) is used. So prepare two MAKEFLAGS strings
1880 1877 * for both posix and solaris modes because they are different.
1881 1878 */
1882 1879 INIT_STRING_FROM_STACK(makeflags_string, buffer);
1883 1880 INIT_STRING_FROM_STACK(makeflags_string_posix, buffer_posix);
1884 1881 append_char((int) hyphen_char, &makeflags_string);
1885 1882 append_char((int) hyphen_char, &makeflags_string_posix);
1886 1883
1887 1884 switch (read_trace_level) {
1888 1885 case 2:
1889 1886 append_char('D', &makeflags_string);
1890 1887 append_char('D', &makeflags_string_posix);
1891 1888 case 1:
1892 1889 append_char('D', &makeflags_string);
1893 1890 append_char('D', &makeflags_string_posix);
1894 1891 }
1895 1892 switch (debug_level) {
1896 1893 case 2:
1897 1894 append_char('d', &makeflags_string);
1898 1895 append_char('d', &makeflags_string_posix);
1899 1896 case 1:
1900 1897 append_char('d', &makeflags_string);
1901 1898 append_char('d', &makeflags_string_posix);
1902 1899 }
1903 1900 if (env_wins) {
1904 1901 append_char('e', &makeflags_string);
1905 1902 append_char('e', &makeflags_string_posix);
1906 1903 }
1907 1904 if (ignore_errors_all) {
1908 1905 append_char('i', &makeflags_string);
1909 1906 append_char('i', &makeflags_string_posix);
1910 1907 }
1911 1908 if (continue_after_error) {
1912 1909 if (stop_after_error_ever_seen) {
1913 1910 append_char('S', &makeflags_string_posix);
1914 1911 append_char((int) space_char, &makeflags_string_posix);
1915 1912 append_char((int) hyphen_char, &makeflags_string_posix);
1916 1913 }
1917 1914 append_char('k', &makeflags_string);
1918 1915 append_char('k', &makeflags_string_posix);
1919 1916 } else {
1920 1917 if (stop_after_error_ever_seen
1921 1918 && continue_after_error_ever_seen) {
1922 1919 append_char('k', &makeflags_string_posix);
1923 1920 append_char((int) space_char, &makeflags_string_posix);
1924 1921 append_char((int) hyphen_char, &makeflags_string_posix);
1925 1922 append_char('S', &makeflags_string_posix);
1926 1923 }
1927 1924 }
1928 1925 if (do_not_exec_rule) {
1929 1926 append_char('n', &makeflags_string);
1930 1927 append_char('n', &makeflags_string_posix);
1931 1928 }
1932 1929 switch (report_dependencies_level) {
1933 1930 case 4:
1934 1931 append_char('P', &makeflags_string);
1935 1932 append_char('P', &makeflags_string_posix);
1936 1933 case 3:
1937 1934 append_char('P', &makeflags_string);
1938 1935 append_char('P', &makeflags_string_posix);
1939 1936 case 2:
1940 1937 append_char('P', &makeflags_string);
1941 1938 append_char('P', &makeflags_string_posix);
1942 1939 case 1:
1943 1940 append_char('P', &makeflags_string);
1944 1941 append_char('P', &makeflags_string_posix);
1945 1942 }
1946 1943 if (trace_status) {
1947 1944 append_char('p', &makeflags_string);
1948 1945 append_char('p', &makeflags_string_posix);
1949 1946 }
1950 1947 if (quest) {
1951 1948 append_char('q', &makeflags_string);
1952 1949 append_char('q', &makeflags_string_posix);
1953 1950 }
1954 1951 if (silent_all) {
1955 1952 append_char('s', &makeflags_string);
1956 1953 append_char('s', &makeflags_string_posix);
1957 1954 }
1958 1955 if (touch) {
1959 1956 append_char('t', &makeflags_string);
1960 1957 append_char('t', &makeflags_string_posix);
1961 1958 }
1962 1959 if (build_unconditional) {
1963 1960 append_char('u', &makeflags_string);
1964 1961 append_char('u', &makeflags_string_posix);
1965 1962 }
1966 1963 if (report_cwd) {
1967 1964 append_char('w', &makeflags_string);
1968 1965 append_char('w', &makeflags_string_posix);
1969 1966 }
1970 1967 /* -c dmake_rcfile */
1971 1968 if (dmake_rcfile_specified) {
1972 1969 MBSTOWCS(wcs_buffer, "DMAKE_RCFILE");
1973 1970 dmake_rcfile = GETNAME(wcs_buffer, FIND_LENGTH);
1974 1971 append_makeflags_string(dmake_rcfile, &makeflags_string);
1975 1972 append_makeflags_string(dmake_rcfile, &makeflags_string_posix);
1976 1973 }
1977 1974 /* -g dmake_group */
1978 1975 if (dmake_group_specified) {
1979 1976 MBSTOWCS(wcs_buffer, "DMAKE_GROUP");
1980 1977 dmake_group = GETNAME(wcs_buffer, FIND_LENGTH);
1981 1978 append_makeflags_string(dmake_group, &makeflags_string);
1982 1979 append_makeflags_string(dmake_group, &makeflags_string_posix);
1983 1980 }
1984 1981 /* -j dmake_max_jobs */
1985 1982 if (dmake_max_jobs_specified) {
1986 1983 MBSTOWCS(wcs_buffer, "DMAKE_MAX_JOBS");
1987 1984 dmake_max_jobs = GETNAME(wcs_buffer, FIND_LENGTH);
1988 1985 append_makeflags_string(dmake_max_jobs, &makeflags_string);
1989 1986 append_makeflags_string(dmake_max_jobs, &makeflags_string_posix);
1990 1987 }
1991 1988 /* -m dmake_mode */
1992 1989 if (dmake_mode_specified) {
1993 1990 MBSTOWCS(wcs_buffer, "DMAKE_MODE");
1994 1991 dmake_mode = GETNAME(wcs_buffer, FIND_LENGTH);
1995 1992 append_makeflags_string(dmake_mode, &makeflags_string);
1996 1993 append_makeflags_string(dmake_mode, &makeflags_string_posix);
1997 1994 }
1998 1995 /* -x dmake_compat_mode */
1999 1996 // if (dmake_compat_mode_specified) {
2000 1997 // MBSTOWCS(wcs_buffer, "SUN_MAKE_COMPAT_MODE");
2001 1998 // dmake_compat_mode = GETNAME(wcs_buffer, FIND_LENGTH);
2002 1999 // append_makeflags_string(dmake_compat_mode, &makeflags_string);
2003 2000 // append_makeflags_string(dmake_compat_mode, &makeflags_string_posix);
2004 2001 // }
2005 2002 /* -x dmake_output_mode */
2006 2003 if (dmake_output_mode_specified) {
2007 2004 MBSTOWCS(wcs_buffer, "DMAKE_OUTPUT_MODE");
2008 2005 dmake_output_mode = GETNAME(wcs_buffer, FIND_LENGTH);
2009 2006 append_makeflags_string(dmake_output_mode, &makeflags_string);
2010 2007 append_makeflags_string(dmake_output_mode, &makeflags_string_posix);
2011 2008 }
2012 2009 /* -o dmake_odir */
2013 2010 if (dmake_odir_specified) {
2014 2011 MBSTOWCS(wcs_buffer, "DMAKE_ODIR");
2015 2012 dmake_odir = GETNAME(wcs_buffer, FIND_LENGTH);
2016 2013 append_makeflags_string(dmake_odir, &makeflags_string);
2017 2014 append_makeflags_string(dmake_odir, &makeflags_string_posix);
2018 2015 }
2019 2016 /* -M pmake_machinesfile */
2020 2017 if (pmake_machinesfile_specified) {
2021 2018 MBSTOWCS(wcs_buffer, "PMAKE_MACHINESFILE");
2022 2019 pmake_machinesfile = GETNAME(wcs_buffer, FIND_LENGTH);
2023 2020 append_makeflags_string(pmake_machinesfile, &makeflags_string);
2024 2021 append_makeflags_string(pmake_machinesfile, &makeflags_string_posix);
2025 2022 }
2026 2023 /* -R */
2027 2024 if (pmake_cap_r_specified) {
2028 2025 append_char((int) space_char, &makeflags_string);
2029 2026 append_char((int) hyphen_char, &makeflags_string);
2030 2027 append_char('R', &makeflags_string);
2031 2028 append_char((int) space_char, &makeflags_string_posix);
2032 2029 append_char((int) hyphen_char, &makeflags_string_posix);
2033 2030 append_char('R', &makeflags_string_posix);
2034 2031 }
2035 2032
2036 2033 /*
2037 2034 * Make sure MAKEFLAGS is exported
2038 2035 */
2039 2036 maybe_append_prop(makeflags, macro_prop)->
2040 2037 body.macro.exported = true;
2041 2038
2042 2039 if (makeflags_string.buffer.start[1] != (int) nul_char) {
2043 2040 if (makeflags_string.buffer.start[1] != (int) space_char) {
2044 2041 MBSTOWCS(wcs_buffer, "MFLAGS");
2045 2042 (void) SETVAR(GETNAME(wcs_buffer, FIND_LENGTH),
2046 2043 GETNAME(makeflags_string.buffer.start,
2047 2044 FIND_LENGTH),
2048 2045 false);
2049 2046 } else {
2050 2047 MBSTOWCS(wcs_buffer, "MFLAGS");
2051 2048 (void) SETVAR(GETNAME(wcs_buffer, FIND_LENGTH),
2052 2049 GETNAME(makeflags_string.buffer.start + 2,
2053 2050 FIND_LENGTH),
2054 2051 false);
2055 2052 }
2056 2053 }
2057 2054
2058 2055 /*
2059 2056 * Add command line macro to POSIX makeflags_string
2060 2057 */
2061 2058 if (makeflags_and_macro.start) {
2062 2059 tmp_char = (char) space_char;
2063 2060 cp = makeflags_and_macro.start;
2064 2061 do {
2065 2062 append_char(tmp_char, &makeflags_string_posix);
2066 2063 } while ( tmp_char = *cp++ );
2067 2064 retmem_mb(makeflags_and_macro.start);
2068 2065 }
2069 2066
2070 2067 /*
2071 2068 * Now set the value of MAKEFLAGS macro in accordance
2072 2069 * with current mode.
2073 2070 */
2074 2071 macro = maybe_append_prop(makeflags, macro_prop);
2075 2072 temp = (Boolean) macro->body.macro.read_only;
2076 2073 macro->body.macro.read_only = false;
2077 2074 if(posix || gnu_style) {
2078 2075 makeflags_string_current = &makeflags_string_posix;
2079 2076 } else {
2080 2077 makeflags_string_current = &makeflags_string;
2081 2078 }
2082 2079 if (makeflags_string_current->buffer.start[1] == (int) nul_char) {
2083 2080 makeflags_value_saved =
2084 2081 GETNAME( makeflags_string_current->buffer.start + 1
2085 2082 , FIND_LENGTH
2086 2083 );
2087 2084 } else {
2088 2085 if (makeflags_string_current->buffer.start[1] != (int) space_char) {
2089 2086 makeflags_value_saved =
2090 2087 GETNAME( makeflags_string_current->buffer.start
2091 2088 , FIND_LENGTH
2092 2089 );
2093 2090 } else {
2094 2091 makeflags_value_saved =
2095 2092 GETNAME( makeflags_string_current->buffer.start + 2
2096 2093 , FIND_LENGTH
2097 2094 );
2098 2095 }
2099 2096 }
2100 2097 (void) SETVAR( makeflags
2101 2098 , makeflags_value_saved
2102 2099 , false
2103 2100 );
2104 2101 macro->body.macro.read_only = temp;
2105 2102
2106 2103 /*
2107 2104 * Read command line "-f" arguments and ignore -c, g, j, K, M, m, O and o args.
2108 2105 */
2109 2106 save_do_not_exec_rule = do_not_exec_rule;
2110 2107 do_not_exec_rule = false;
2111 2108 if (read_trace_level > 0) {
2112 2109 trace_reader = true;
2113 2110 }
2114 2111
2115 2112 for (i = 1; i < argc; i++) {
2116 2113 if (argv[i] &&
2117 2114 (argv[i][0] == (int) hyphen_char) &&
2118 2115 (argv[i][1] == 'f') &&
2119 2116 (argv[i][2] == (int) nul_char)) {
2120 2117 argv[i] = NULL; /* Remove -f */
2121 2118 if (i >= argc - 1) {
2122 2119 fatal(gettext("No filename argument after -f flag"));
2123 2120 }
2124 2121 MBSTOWCS(wcs_buffer, argv[++i]);
2125 2122 primary_makefile = GETNAME(wcs_buffer, FIND_LENGTH);
2126 2123 (void) read_makefile(primary_makefile, true, true, true);
2127 2124 argv[i] = NULL; /* Remove filename */
2128 2125 makefile_read = true;
2129 2126 } else if (argv[i] &&
2130 2127 (argv[i][0] == (int) hyphen_char) &&
2131 2128 (argv[i][1] == 'c' ||
2132 2129 argv[i][1] == 'g' ||
2133 2130 argv[i][1] == 'j' ||
2134 2131 argv[i][1] == 'K' ||
2135 2132 argv[i][1] == 'M' ||
2136 2133 argv[i][1] == 'm' ||
2137 2134 argv[i][1] == 'O' ||
2138 2135 argv[i][1] == 'o') &&
2139 2136 (argv[i][2] == (int) nul_char)) {
2140 2137 argv[i] = NULL;
2141 2138 argv[++i] = NULL;
2142 2139 }
2143 2140 }
2144 2141
2145 2142 /*
2146 2143 * If no command line "-f" args then look for "makefile", and then for
2147 2144 * "Makefile" if "makefile" isn't found.
2148 2145 */
2149 2146 if (!makefile_read) {
2150 2147 (void) read_dir(dot,
2151 2148 (wchar_t *) NULL,
2152 2149 (Property) NULL,
2153 2150 (wchar_t *) NULL);
2154 2151 if (!posix) {
2155 2152 if (makefile_name->stat.is_file) {
2156 2153 if (Makefile->stat.is_file) {
2157 2154 warning(gettext("Both `makefile' and `Makefile' exist"));
2158 2155 }
2159 2156 primary_makefile = makefile_name;
2160 2157 makefile_read = read_makefile(makefile_name,
2161 2158 false,
2162 2159 false,
2163 2160 true);
2164 2161 }
2165 2162 if (!makefile_read &&
2166 2163 Makefile->stat.is_file) {
2167 2164 primary_makefile = Makefile;
2168 2165 makefile_read = read_makefile(Makefile,
2169 2166 false,
2170 2167 false,
2171 2168 true);
2172 2169 }
2173 2170 } else {
2174 2171
2175 2172 enum sccs_stat save_m_has_sccs = NO_SCCS;
2176 2173 enum sccs_stat save_M_has_sccs = NO_SCCS;
2177 2174
2178 2175 if (makefile_name->stat.is_file) {
2179 2176 if (Makefile->stat.is_file) {
2180 2177 warning(gettext("Both `makefile' and `Makefile' exist"));
2181 2178 }
2182 2179 }
2183 2180 if (makefile_name->stat.is_file) {
2184 2181 if (makefile_name->stat.has_sccs == NO_SCCS) {
2185 2182 primary_makefile = makefile_name;
2186 2183 makefile_read = read_makefile(makefile_name,
2187 2184 false,
2188 2185 false,
2189 2186 true);
2190 2187 } else {
2191 2188 save_m_has_sccs = makefile_name->stat.has_sccs;
2192 2189 makefile_name->stat.has_sccs = NO_SCCS;
2193 2190 primary_makefile = makefile_name;
2194 2191 makefile_read = read_makefile(makefile_name,
2195 2192 false,
2196 2193 false,
2197 2194 true);
2198 2195 }
2199 2196 }
2200 2197 if (!makefile_read &&
2201 2198 Makefile->stat.is_file) {
2202 2199 if (Makefile->stat.has_sccs == NO_SCCS) {
2203 2200 primary_makefile = Makefile;
2204 2201 makefile_read = read_makefile(Makefile,
2205 2202 false,
2206 2203 false,
2207 2204 true);
2208 2205 } else {
2209 2206 save_M_has_sccs = Makefile->stat.has_sccs;
2210 2207 Makefile->stat.has_sccs = NO_SCCS;
2211 2208 primary_makefile = Makefile;
2212 2209 makefile_read = read_makefile(Makefile,
2213 2210 false,
2214 2211 false,
2215 2212 true);
2216 2213 }
2217 2214 }
2218 2215 if (!makefile_read &&
2219 2216 makefile_name->stat.is_file) {
2220 2217 makefile_name->stat.has_sccs = save_m_has_sccs;
2221 2218 primary_makefile = makefile_name;
2222 2219 makefile_read = read_makefile(makefile_name,
2223 2220 false,
2224 2221 false,
2225 2222 true);
2226 2223 }
2227 2224 if (!makefile_read &&
2228 2225 Makefile->stat.is_file) {
2229 2226 Makefile->stat.has_sccs = save_M_has_sccs;
2230 2227 primary_makefile = Makefile;
2231 2228 makefile_read = read_makefile(Makefile,
2232 2229 false,
2233 2230 false,
2234 2231 true);
2235 2232 }
2236 2233 }
2237 2234 }
2238 2235 do_not_exec_rule = save_do_not_exec_rule;
2239 2236 allrules_read = makefile_read;
2240 2237 trace_reader = false;
2241 2238
2242 2239 /*
2243 2240 * Now get current value of MAKEFLAGS and compare it with
2244 2241 * the saved value we set before reading makefile.
2245 2242 * If they are different then MAKEFLAGS is subsequently set by
2246 2243 * makefile, just leave it there. Otherwise, if make mode
2247 2244 * is changed by using .POSIX target in makefile we need
2248 2245 * to correct MAKEFLAGS value.
2249 2246 */
2250 2247 Name mf_val = getvar(makeflags);
2251 2248 if( (posix != is_xpg4)
2252 2249 && (!strcmp(mf_val->string_mb, makeflags_value_saved->string_mb)))
2253 2250 {
2254 2251 if (makeflags_string_posix.buffer.start[1] == (int) nul_char) {
2255 2252 (void) SETVAR(makeflags,
2256 2253 GETNAME(makeflags_string_posix.buffer.start + 1,
2257 2254 FIND_LENGTH),
2258 2255 false);
2259 2256 } else {
2260 2257 if (makeflags_string_posix.buffer.start[1] != (int) space_char) {
2261 2258 (void) SETVAR(makeflags,
2262 2259 GETNAME(makeflags_string_posix.buffer.start,
2263 2260 FIND_LENGTH),
2264 2261 false);
2265 2262 } else {
2266 2263 (void) SETVAR(makeflags,
2267 2264 GETNAME(makeflags_string_posix.buffer.start + 2,
2268 2265 FIND_LENGTH),
2269 2266 false);
2270 2267 }
2271 2268 }
2272 2269 }
2273 2270
2274 2271 if (makeflags_string.free_after_use) {
2275 2272 retmem(makeflags_string.buffer.start);
2276 2273 }
2277 2274 if (makeflags_string_posix.free_after_use) {
2278 2275 retmem(makeflags_string_posix.buffer.start);
2279 2276 }
2280 2277 makeflags_string.buffer.start = NULL;
2281 2278 makeflags_string_posix.buffer.start = NULL;
2282 2279
2283 2280 if (posix) {
2284 2281 /*
2285 2282 * If the user did not redefine the ARFLAGS macro in the
2286 2283 * default makefile (make.rules), then we'd like to
2287 2284 * change the macro value of ARFLAGS to be in accordance
2288 2285 * with "POSIX" requirements.
2289 2286 */
2290 2287 MBSTOWCS(wcs_buffer, "ARFLAGS");
2291 2288 name = GETNAME(wcs_buffer, wslen(wcs_buffer));
2292 2289 macro = get_prop(name->prop, macro_prop);
2293 2290 if ((macro != NULL) && /* Maybe (macro == NULL) || ? */
2294 2291 (IS_EQUAL(macro->body.macro.value->string_mb,
2295 2292 "rv"))) {
2296 2293 MBSTOWCS(wcs_buffer, "-rv");
2297 2294 value = GETNAME(wcs_buffer, wslen(wcs_buffer));
2298 2295 (void) SETVAR(name,
2299 2296 value,
2300 2297 false);
2301 2298 }
2302 2299 }
2303 2300
2304 2301 if (!posix && !svr4) {
2305 2302 set_sgs_support();
2306 2303 }
2307 2304
2308 2305
2309 2306 /*
2310 2307 * Make sure KEEP_STATE is in the environment if KEEP_STATE is on.
2311 2308 */
2312 2309 macro = get_prop(keep_state_name->prop, macro_prop);
2313 2310 if ((macro != NULL) &&
2314 2311 macro->body.macro.exported) {
2315 2312 keep_state = true;
2316 2313 }
2317 2314 if (keep_state) {
2318 2315 if (macro == NULL) {
2319 2316 macro = maybe_append_prop(keep_state_name,
2320 2317 macro_prop);
2321 2318 }
2322 2319 macro->body.macro.exported = true;
2323 2320 (void) SETVAR(keep_state_name,
2324 2321 empty_name,
2325 2322 false);
2326 2323
2327 2324 /*
2328 2325 * Read state file
2329 2326 */
2330 2327
2331 2328 /* Before we read state, let's make sure we have
2332 2329 ** right state file.
2333 2330 */
2334 2331 /* just in case macro references are used in make_state file
2335 2332 ** name, we better expand them at this stage using expand_value.
2336 2333 */
2337 2334 INIT_STRING_FROM_STACK(dest, destbuffer);
2338 2335 expand_value(make_state, &dest, false);
2339 2336
2340 2337 make_state = GETNAME(dest.buffer.start, FIND_LENGTH);
2341 2338
2342 2339 if(!stat(make_state->string_mb, &make_state_stat)) {
2343 2340 if(!(make_state_stat.st_mode & S_IFREG) ) {
2344 2341 /* copy the make_state structure to the other
2345 2342 ** and then let make_state point to the new
2346 2343 ** one.
2347 2344 */
2348 2345 memcpy(&state_filename, make_state,sizeof(state_filename));
2349 2346 state_filename.string_mb = state_file_str_mb;
2350 2347 /* Just a kludge to avoid two slashes back to back */
2351 2348 if((make_state->hash.length == 1)&&
2352 2349 (make_state->string_mb[0] == '/')) {
2353 2350 make_state->hash.length = 0;
2354 2351 make_state->string_mb[0] = '\0';
2355 2352 }
2356 2353 sprintf(state_file_str_mb,"%s%s",
2357 2354 make_state->string_mb,"/.make.state");
2358 2355 make_state = &state_filename;
2359 2356 /* adjust the length to reflect the appended string */
2360 2357 make_state->hash.length += 12;
2361 2358 }
2362 2359 } else { /* the file doesn't exist or no permission */
2363 2360 char tmp_path[MAXPATHLEN];
2364 2361 char *slashp;
2365 2362
2366 2363 if (slashp = strrchr(make_state->string_mb, '/')) {
2367 2364 strncpy(tmp_path, make_state->string_mb,
2368 2365 (slashp - make_state->string_mb));
2369 2366 tmp_path[slashp - make_state->string_mb]=0;
2370 2367 if(strlen(tmp_path)) {
2371 2368 if(stat(tmp_path, &make_state_stat)) {
2372 2369 warning(gettext("directory %s for .KEEP_STATE_FILE does not exist"),tmp_path);
2373 2370 }
2374 2371 if (access(tmp_path, F_OK) != 0) {
2375 2372 warning(gettext("can't access dir %s"),tmp_path);
2376 2373 }
2377 2374 }
2378 2375 }
2379 2376 }
2380 2377 if (report_dependencies_level != 1) {
2381 2378 Makefile_type makefile_type_temp = makefile_type;
2382 2379 makefile_type = reading_statefile;
2383 2380 if (read_trace_level > 1) {
2384 2381 trace_reader = true;
2385 2382 }
2386 2383 (void) read_simple_file(make_state,
2387 2384 false,
2388 2385 false,
2389 2386 false,
2390 2387 false,
2391 2388 false,
2392 2389 true);
2393 2390 trace_reader = false;
2394 2391 makefile_type = makefile_type_temp;
2395 2392 }
2396 2393 }
2397 2394 }
2398 2395
2399 2396 /*
2400 2397 * Scan the argv for options and "=" type args and make them readonly.
2401 2398 */
2402 2399 static void
2403 2400 enter_argv_values(int argc, char *argv[], ASCII_Dyn_Array *makeflags_and_macro)
2404 2401 {
2405 2402 register char *cp;
2406 2403 register int i;
2407 2404 int length;
2408 2405 register Name name;
2409 2406 int opt_separator = argc;
2410 2407 char tmp_char;
2411 2408 wchar_t *tmp_wcs_buffer;
2412 2409 register Name value;
2413 2410 Boolean append = false;
2414 2411 Property macro;
2415 2412 struct stat statbuf;
2416 2413
2417 2414
2418 2415 /* Read argv options and "=" type args and make them readonly. */
2419 2416 makefile_type = reading_nothing;
2420 2417 for (i = 1; i < argc; ++i) {
2421 2418 append = false;
2422 2419 if (argv[i] == NULL) {
2423 2420 continue;
2424 2421 } else if (((argv[i][0] == '-') && (argv[i][1] == '-')) ||
2425 2422 ((argv[i][0] == (int) ' ') &&
2426 2423 (argv[i][1] == (int) '-') &&
2427 2424 (argv[i][2] == (int) ' ') &&
2428 2425 (argv[i][3] == (int) '-'))) {
2429 2426 argv[i] = NULL;
2430 2427 opt_separator = i;
2431 2428 continue;
2432 2429 } else if ((i < opt_separator) && (argv[i][0] == (int) hyphen_char)) {
2433 2430 switch (parse_command_option(argv[i][1])) {
2434 2431 case 1: /* -f seen */
2435 2432 ++i;
2436 2433 continue;
2437 2434 case 2: /* -c seen */
2438 2435 if (argv[i+1] == NULL) {
2439 2436 fatal(gettext("No dmake rcfile argument after -c flag"));
2440 2437 }
2441 2438 MBSTOWCS(wcs_buffer, "DMAKE_RCFILE");
2442 2439 name = GETNAME(wcs_buffer, FIND_LENGTH);
2443 2440 break;
2444 2441 case 4: /* -g seen */
2445 2442 if (argv[i+1] == NULL) {
2446 2443 fatal(gettext("No dmake group argument after -g flag"));
2447 2444 }
2448 2445 MBSTOWCS(wcs_buffer, "DMAKE_GROUP");
2449 2446 name = GETNAME(wcs_buffer, FIND_LENGTH);
2450 2447 break;
2451 2448 case 8: /* -j seen */
2452 2449 if (argv[i+1] == NULL) {
2453 2450 fatal(gettext("No dmake max jobs argument after -j flag"));
2454 2451 }
2455 2452 MBSTOWCS(wcs_buffer, "DMAKE_MAX_JOBS");
2456 2453 name = GETNAME(wcs_buffer, FIND_LENGTH);
2457 2454 break;
2458 2455 case 16: /* -M seen */
2459 2456 if (argv[i+1] == NULL) {
2460 2457 fatal(gettext("No pmake machinesfile argument after -M flag"));
2461 2458 }
2462 2459 MBSTOWCS(wcs_buffer, "PMAKE_MACHINESFILE");
2463 2460 name = GETNAME(wcs_buffer, FIND_LENGTH);
2464 2461 break;
2465 2462 case 32: /* -m seen */
2466 2463 if (argv[i+1] == NULL) {
2467 2464 fatal(gettext("No dmake mode argument after -m flag"));
2468 2465 }
2469 2466 MBSTOWCS(wcs_buffer, "DMAKE_MODE");
2470 2467 name = GETNAME(wcs_buffer, FIND_LENGTH);
2471 2468 break;
2472 2469 case 256: /* -K seen */
2473 2470 if (argv[i+1] == NULL) {
2474 2471 fatal(gettext("No makestate filename argument after -K flag"));
2475 2472 }
2476 2473 MBSTOWCS(wcs_buffer, argv[i+1]);
2477 2474 make_state = GETNAME(wcs_buffer, FIND_LENGTH);
2478 2475 keep_state = true;
2479 2476 argv[i] = NULL;
2480 2477 argv[i+1] = NULL;
2481 2478 continue;
2482 2479 case 512: /* -o seen */
2483 2480 if (argv[i+1] == NULL) {
2484 2481 fatal(gettext("No dmake output dir argument after -o flag"));
2485 2482 }
2486 2483 MBSTOWCS(wcs_buffer, "DMAKE_ODIR");
2487 2484 name = GETNAME(wcs_buffer, FIND_LENGTH);
2488 2485 break;
2489 2486 case 1024: /* -x seen */
2490 2487 if (argv[i+1] == NULL) {
2491 2488 fatal(gettext("No argument after -x flag"));
2492 2489 }
2493 2490 length = strlen( "SUN_MAKE_COMPAT_MODE=");
2494 2491 if (strncmp(argv[i+1], "SUN_MAKE_COMPAT_MODE=", length) == 0) {
2495 2492 argv[i+1] = &argv[i+1][length];
2496 2493 MBSTOWCS(wcs_buffer, "SUN_MAKE_COMPAT_MODE");
2497 2494 name = GETNAME(wcs_buffer, FIND_LENGTH);
2498 2495 dmake_compat_mode_specified = dmake_add_mode_specified;
2499 2496 break;
2500 2497 }
2501 2498 length = strlen( "DMAKE_OUTPUT_MODE=");
2502 2499 if (strncmp(argv[i+1], "DMAKE_OUTPUT_MODE=", length) == 0) {
2503 2500 argv[i+1] = &argv[i+1][length];
2504 2501 MBSTOWCS(wcs_buffer, "DMAKE_OUTPUT_MODE");
2505 2502 name = GETNAME(wcs_buffer, FIND_LENGTH);
2506 2503 dmake_output_mode_specified = dmake_add_mode_specified;
2507 2504 } else {
2508 2505 warning(gettext("Unknown argument `%s' after -x flag (ignored)"),
2509 2506 argv[i+1]);
2510 2507 argv[i] = argv[i + 1] = NULL;
2511 2508 continue;
2512 2509 }
2513 2510 break;
2514 2511 default: /* Shouldn't reach here */
2515 2512 argv[i] = NULL;
2516 2513 continue;
2517 2514 }
2518 2515 argv[i] = NULL;
2519 2516 if (i == (argc - 1)) {
2520 2517 break;
2521 2518 }
2522 2519 if ((length = strlen(argv[i+1])) >= MAXPATHLEN) {
2523 2520 tmp_wcs_buffer = ALLOC_WC(length + 1);
2524 2521 (void) mbstowcs(tmp_wcs_buffer, argv[i+1], length + 1);
2525 2522 value = GETNAME(tmp_wcs_buffer, FIND_LENGTH);
2526 2523 retmem(tmp_wcs_buffer);
2527 2524 } else {
2528 2525 MBSTOWCS(wcs_buffer, argv[i+1]);
2529 2526 value = GETNAME(wcs_buffer, FIND_LENGTH);
2530 2527 }
2531 2528 argv[i+1] = NULL;
2532 2529 } else if ((cp = strchr(argv[i], (int) equal_char)) != NULL) {
2533 2530 /*
2534 2531 * Combine all macro in dynamic array
2535 2532 */
2536 2533 if(*(cp-1) == (int) plus_char)
2537 2534 {
2538 2535 if(isspace(*(cp-2))) {
2539 2536 append = true;
2540 2537 cp--;
2541 2538 }
2542 2539 }
2543 2540 if(!append)
2544 2541 append_or_replace_macro_in_dyn_array(makeflags_and_macro, argv[i]);
2545 2542
2546 2543 while (isspace(*(cp-1))) {
2547 2544 cp--;
2548 2545 }
2549 2546 tmp_char = *cp;
2550 2547 *cp = (int) nul_char;
2551 2548 MBSTOWCS(wcs_buffer, argv[i]);
2552 2549 *cp = tmp_char;
2553 2550 name = GETNAME(wcs_buffer, wslen(wcs_buffer));
2554 2551 while (*cp != (int) equal_char) {
2555 2552 cp++;
2556 2553 }
2557 2554 cp++;
2558 2555 while (isspace(*cp) && (*cp != (int) nul_char)) {
2559 2556 cp++;
2560 2557 }
2561 2558 if ((length = strlen(cp)) >= MAXPATHLEN) {
2562 2559 tmp_wcs_buffer = ALLOC_WC(length + 1);
2563 2560 (void) mbstowcs(tmp_wcs_buffer, cp, length + 1);
2564 2561 value = GETNAME(tmp_wcs_buffer, FIND_LENGTH);
2565 2562 retmem(tmp_wcs_buffer);
2566 2563 } else {
2567 2564 MBSTOWCS(wcs_buffer, cp);
2568 2565 value = GETNAME(wcs_buffer, FIND_LENGTH);
2569 2566 }
2570 2567 argv[i] = NULL;
2571 2568 } else {
2572 2569 /* Illegal MAKEFLAGS argument */
2573 2570 continue;
2574 2571 }
2575 2572 if(append) {
2576 2573 setvar_append(name, value);
2577 2574 append = false;
2578 2575 } else {
2579 2576 macro = maybe_append_prop(name, macro_prop);
2580 2577 macro->body.macro.exported = true;
2581 2578 SETVAR(name, value, false)->body.macro.read_only = true;
2582 2579 }
2583 2580 }
2584 2581 }
2585 2582
2586 2583 /*
2587 2584 * Append the DMake option and value to the MAKEFLAGS string.
2588 2585 */
2589 2586 static void
2590 2587 append_makeflags_string(Name name, register String makeflags_string)
2591 2588 {
2592 2589 const char *option;
2593 2590
2594 2591 if (strcmp(name->string_mb, "DMAKE_GROUP") == 0) {
2595 2592 option = " -g ";
2596 2593 } else if (strcmp(name->string_mb, "DMAKE_MAX_JOBS") == 0) {
2597 2594 option = " -j ";
2598 2595 } else if (strcmp(name->string_mb, "DMAKE_MODE") == 0) {
2599 2596 option = " -m ";
2600 2597 } else if (strcmp(name->string_mb, "DMAKE_ODIR") == 0) {
2601 2598 option = " -o ";
2602 2599 } else if (strcmp(name->string_mb, "DMAKE_RCFILE") == 0) {
2603 2600 option = " -c ";
2604 2601 } else if (strcmp(name->string_mb, "PMAKE_MACHINESFILE") == 0) {
2605 2602 option = " -M ";
2606 2603 } else if (strcmp(name->string_mb, "DMAKE_OUTPUT_MODE") == 0) {
2607 2604 option = " -x DMAKE_OUTPUT_MODE=";
2608 2605 } else if (strcmp(name->string_mb, "SUN_MAKE_COMPAT_MODE") == 0) {
2609 2606 option = " -x SUN_MAKE_COMPAT_MODE=";
2610 2607 } else {
2611 2608 fatal(gettext("Internal error: name not recognized in append_makeflags_string()"));
2612 2609 }
2613 2610 Property prop = maybe_append_prop(name, macro_prop);
2614 2611 if( prop == 0 || prop->body.macro.value == 0 ||
2615 2612 prop->body.macro.value->string_mb == 0 ) {
2616 2613 return;
2617 2614 }
2618 2615 char mbs_value[MAXPATHLEN + 100];
2619 2616 strcpy(mbs_value, option);
2620 2617 strcat(mbs_value, prop->body.macro.value->string_mb);
2621 2618 MBSTOWCS(wcs_buffer, mbs_value);
2622 2619 append_string(wcs_buffer, makeflags_string, FIND_LENGTH);
2623 2620 }
2624 2621
2625 2622 /*
2626 2623 * read_environment(read_only)
2627 2624 *
2628 2625 * This routine reads the process environment when make starts and enters
2629 2626 * it as make macros. The environment variable SHELL is ignored.
2630 2627 *
2631 2628 * Parameters:
2632 2629 * read_only Should we make env vars read only?
2633 2630 *
2634 2631 * Global variables used:
2635 2632 * report_pwd Set if this make was started by other make
2636 2633 */
2637 2634 static void
2638 2635 read_environment(Boolean read_only)
2639 2636 {
2640 2637 register char **environment;
2641 2638 int length;
2642 2639 wchar_t *tmp_wcs_buffer;
2643 2640 Boolean alloced_tmp_wcs_buffer = false;
2644 2641 register wchar_t *name;
2645 2642 register wchar_t *value;
2646 2643 register Name macro;
2647 2644 Property val;
2648 2645 Boolean read_only_saved;
2649 2646
2650 2647 reading_environment = true;
2651 2648 environment = environ;
2652 2649 for (; *environment; environment++) {
2653 2650 read_only_saved = read_only;
2654 2651 if ((length = strlen(*environment)) >= MAXPATHLEN) {
2655 2652 tmp_wcs_buffer = ALLOC_WC(length + 1);
2656 2653 alloced_tmp_wcs_buffer = true;
2657 2654 (void) mbstowcs(tmp_wcs_buffer, *environment, length + 1);
2658 2655 name = tmp_wcs_buffer;
2659 2656 } else {
2660 2657 MBSTOWCS(wcs_buffer, *environment);
2661 2658 name = wcs_buffer;
2662 2659 }
2663 2660 value = (wchar_t *) wschr(name, (int) equal_char);
2664 2661
2665 2662 /*
2666 2663 * Looks like there's a bug in the system, but sometimes
2667 2664 * you can get blank lines in *environment.
2668 2665 */
2669 2666 if (!value) {
2670 2667 continue;
2671 2668 }
2672 2669 MBSTOWCS(wcs_buffer2, "SHELL=");
2673 2670 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2674 2671 continue;
2675 2672 }
2676 2673 MBSTOWCS(wcs_buffer2, "MAKEFLAGS=");
2677 2674 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2678 2675 report_pwd = true;
2679 2676 /*
2680 2677 * In POSIX mode we do not want MAKEFLAGS to be readonly.
2681 2678 * If the MAKEFLAGS macro is subsequently set by the makefile,
2682 2679 * it replaces the MAKEFLAGS variable currently found in the
2683 2680 * environment.
2684 2681 * See Assertion 50 in section 6.2.5.3 of standard P1003.3.2/D8.
2685 2682 */
2686 2683 if(posix) {
2687 2684 read_only_saved = false;
2688 2685 }
2689 2686 }
2690 2687
2691 2688 /*
2692 2689 * We ignore SUNPRO_DEPENDENCIES. This environment variable is
2693 2690 * set by make and read by cpp which then writes info to
2694 2691 * .make.dependency.xxx. When make is invoked by another make
2695 2692 * (recursive make), we don't want to read this because then
2696 2693 * the child make will end up writing to the parent
2697 2694 * directory's .make.state and clobbering them.
2698 2695 */
2699 2696 MBSTOWCS(wcs_buffer2, "SUNPRO_DEPENDENCIES");
2700 2697 if (IS_WEQUALN(name, wcs_buffer2, wslen(wcs_buffer2))) {
2701 2698 continue;
2702 2699 }
2703 2700
2704 2701 macro = GETNAME(name, value - name);
2705 2702 maybe_append_prop(macro, macro_prop)->body.macro.exported =
2706 2703 true;
2707 2704 if ((value == NULL) || ((value + 1)[0] == (int) nul_char)) {
2708 2705 val = setvar_daemon(macro,
2709 2706 (Name) NULL,
2710 2707 false, no_daemon, false, debug_level);
2711 2708 } else {
2712 2709 val = setvar_daemon(macro,
2713 2710 GETNAME(value + 1, FIND_LENGTH),
2714 2711 false, no_daemon, false, debug_level);
2715 2712 }
2716 2713 val->body.macro.read_only = read_only_saved;
2717 2714 if (alloced_tmp_wcs_buffer) {
2718 2715 retmem(tmp_wcs_buffer);
2719 2716 alloced_tmp_wcs_buffer = false;
2720 2717 }
2721 2718 }
2722 2719 reading_environment = false;
2723 2720 }
2724 2721
2725 2722 /*
2726 2723 * read_makefile(makefile, complain, must_exist, report_file)
2727 2724 *
2728 2725 * Read one makefile and check the result
2729 2726 *
2730 2727 * Return value:
2731 2728 * false is the read failed
2732 2729 *
2733 2730 * Parameters:
2734 2731 * makefile The file to read
2735 2732 * complain Passed thru to read_simple_file()
2736 2733 * must_exist Passed thru to read_simple_file()
2737 2734 * report_file Passed thru to read_simple_file()
2738 2735 *
2739 2736 * Global variables used:
2740 2737 * makefile_type Set to indicate we are reading main file
2741 2738 * recursion_level Initialized
2742 2739 */
2743 2740 static Boolean
2744 2741 read_makefile(register Name makefile, Boolean complain, Boolean must_exist, Boolean report_file)
2745 2742 {
2746 2743 Boolean b;
2747 2744
2748 2745 makefile_type = reading_makefile;
2749 2746 recursion_level = 0;
2750 2747 reading_dependencies = true;
2751 2748 b = read_simple_file(makefile, true, true, complain,
2752 2749 must_exist, report_file, false);
2753 2750 reading_dependencies = false;
2754 2751 return b;
2755 2752 }
2756 2753
2757 2754 /*
2758 2755 * make_targets(argc, argv, parallel_flag)
2759 2756 *
2760 2757 * Call doname on the specified targets
2761 2758 *
2762 2759 * Parameters:
2763 2760 * argc You know what this is
2764 2761 * argv You know what this is
2765 2762 * parallel_flag True if building in parallel
2766 2763 *
2767 2764 * Global variables used:
2768 2765 * build_failed_seen Used to generated message after failed -k
2769 2766 * commands_done Used to generate message "Up to date"
2770 2767 * default_target_to_build First proper target in makefile
2771 2768 * init The Name ".INIT", use to run command
2772 2769 * parallel Global parallel building flag
2773 2770 * quest make -q, suppresses messages
2774 2771 * recursion_level Initialized, used for tracing
2775 2772 * report_dependencies make -P, regroves whole process
2776 2773 */
2777 2774 static void
2778 2775 make_targets(int argc, char **argv, Boolean parallel_flag)
2779 2776 {
2780 2777 int i;
2781 2778 char *cp;
2782 2779 Doname result;
2783 2780 register Boolean target_to_make_found = false;
2784 2781
2785 2782 (void) doname(init, true, true);
2786 2783 recursion_level = 1;
2787 2784 parallel = parallel_flag;
2788 2785 /*
2789 2786 * make remaining args
2790 2787 */
2791 2788 /*
2792 2789 if ((report_dependencies_level == 0) && parallel) {
2793 2790 */
2794 2791 if (parallel) {
2795 2792 /*
2796 2793 * If building targets in parallel, start all of the
2797 2794 * remaining args to build in parallel.
2798 2795 */
2799 2796 for (i = 1; i < argc; i++) {
2800 2797 if ((cp = argv[i]) != NULL) {
2801 2798 commands_done = false;
2802 2799 if ((cp[0] == (int) period_char) &&
2803 2800 (cp[1] == (int) slash_char)) {
2804 2801 cp += 2;
2805 2802 }
2806 2803 if((cp[0] == (int) ' ') &&
2807 2804 (cp[1] == (int) '-') &&
2808 2805 (cp[2] == (int) ' ') &&
2809 2806 (cp[3] == (int) '-')) {
2810 2807 argv[i] = NULL;
2811 2808 continue;
2812 2809 }
2813 2810 MBSTOWCS(wcs_buffer, cp);
2814 2811 //default_target_to_build = GETNAME(wcs_buffer,
2815 2812 // FIND_LENGTH);
2816 2813 default_target_to_build = normalize_name(wcs_buffer,
2817 2814 wslen(wcs_buffer));
2818 2815 if (default_target_to_build == wait_name) {
2819 2816 if (parallel_process_cnt > 0) {
2820 2817 finish_running();
2821 2818 }
2822 2819 continue;
2823 2820 }
2824 2821 top_level_target = get_wstring(default_target_to_build->string_mb);
2825 2822 /*
2826 2823 * If we can't execute the current target in
2827 2824 * parallel, hold off the target processing
2828 2825 * to preserve the order of the targets as they appeared
2829 2826 * in command line.
2830 2827 */
2831 2828 if (!parallel_ok(default_target_to_build, false)
2832 2829 && parallel_process_cnt > 0) {
2833 2830 finish_running();
2834 2831 }
2835 2832 result = doname_check(default_target_to_build,
2836 2833 true,
2837 2834 false,
2838 2835 false);
2839 2836 gather_recursive_deps();
2840 2837 if (/* !commands_done && */
2841 2838 (result == build_ok) &&
2842 2839 !quest &&
2843 2840 (report_dependencies_level == 0) /* &&
2844 2841 (exists(default_target_to_build) > file_doesnt_exist) */) {
2845 2842 if (posix) {
2846 2843 if (!commands_done) {
2847 2844 (void) printf(gettext("`%s' is updated.\n"),
2848 2845 default_target_to_build->string_mb);
2849 2846 } else {
2850 2847 if (no_action_was_taken) {
2851 2848 (void) printf(gettext("`%s': no action was taken.\n"),
2852 2849 default_target_to_build->string_mb);
2853 2850 }
2854 2851 }
2855 2852 } else {
2856 2853 default_target_to_build->stat.time = file_no_time;
2857 2854 if (!commands_done &&
2858 2855 (exists(default_target_to_build) > file_doesnt_exist)) {
2859 2856 (void) printf(gettext("`%s' is up to date.\n"),
2860 2857 default_target_to_build->string_mb);
2861 2858 }
2862 2859 }
2863 2860 }
2864 2861 }
2865 2862 }
2866 2863 /* Now wait for all of the targets to finish running */
2867 2864 finish_running();
2868 2865 // setjmp(jmpbuffer);
2869 2866
2870 2867 }
2871 2868 for (i = 1; i < argc; i++) {
2872 2869 if ((cp = argv[i]) != NULL) {
2873 2870 target_to_make_found = true;
2874 2871 if ((cp[0] == (int) period_char) &&
2875 2872 (cp[1] == (int) slash_char)) {
2876 2873 cp += 2;
2877 2874 }
2878 2875 if((cp[0] == (int) ' ') &&
2879 2876 (cp[1] == (int) '-') &&
2880 2877 (cp[2] == (int) ' ') &&
2881 2878 (cp[3] == (int) '-')) {
2882 2879 argv[i] = NULL;
2883 2880 continue;
2884 2881 }
2885 2882 MBSTOWCS(wcs_buffer, cp);
2886 2883 default_target_to_build = normalize_name(wcs_buffer, wslen(wcs_buffer));
2887 2884 top_level_target = get_wstring(default_target_to_build->string_mb);
2888 2885 report_recursion(default_target_to_build);
2889 2886 commands_done = false;
2890 2887 if (parallel) {
2891 2888 result = (Doname) default_target_to_build->state;
2892 2889 } else {
2893 2890 result = doname_check(default_target_to_build,
2894 2891 true,
2895 2892 false,
2896 2893 false);
2897 2894 }
2898 2895 gather_recursive_deps();
2899 2896 if (build_failed_seen) {
2900 2897 build_failed_ever_seen = true;
2901 2898 warning(gettext("Target `%s' not remade because of errors"),
2902 2899 default_target_to_build->string_mb);
2903 2900 }
2904 2901 build_failed_seen = false;
2905 2902 if (report_dependencies_level > 0) {
2906 2903 print_dependencies(default_target_to_build,
2907 2904 get_prop(default_target_to_build->prop,
2908 2905 line_prop));
2909 2906 }
2910 2907 default_target_to_build->stat.time =
2911 2908 file_no_time;
2912 2909 if (default_target_to_build->colon_splits > 0) {
2913 2910 default_target_to_build->state =
2914 2911 build_dont_know;
2915 2912 }
2916 2913 if (!parallel &&
2917 2914 /* !commands_done && */
2918 2915 (result == build_ok) &&
2919 2916 !quest &&
2920 2917 (report_dependencies_level == 0) /* &&
2921 2918 (exists(default_target_to_build) > file_doesnt_exist) */) {
2922 2919 if (posix) {
2923 2920 if (!commands_done) {
2924 2921 (void) printf(gettext("`%s' is updated.\n"),
2925 2922 default_target_to_build->string_mb);
2926 2923 } else {
2927 2924 if (no_action_was_taken) {
2928 2925 (void) printf(gettext("`%s': no action was taken.\n"),
2929 2926 default_target_to_build->string_mb);
2930 2927 }
2931 2928 }
2932 2929 } else {
2933 2930 if (!commands_done &&
2934 2931 (exists(default_target_to_build) > file_doesnt_exist)) {
2935 2932 (void) printf(gettext("`%s' is up to date.\n"),
2936 2933 default_target_to_build->string_mb);
2937 2934 }
2938 2935 }
2939 2936 }
2940 2937 }
2941 2938 }
2942 2939
2943 2940 /*
2944 2941 * If no file arguments have been encountered,
2945 2942 * make the first name encountered that doesnt start with a dot
2946 2943 */
2947 2944 if (!target_to_make_found) {
2948 2945 if (default_target_to_build == NULL) {
2949 2946 fatal(gettext("No arguments to build"));
2950 2947 }
2951 2948 commands_done = false;
2952 2949 top_level_target = get_wstring(default_target_to_build->string_mb);
2953 2950 report_recursion(default_target_to_build);
2954 2951
2955 2952
2956 2953 if (getenv("SPRO_EXPAND_ERRORS")){
2957 2954 (void) printf("::(%s)\n",
2958 2955 default_target_to_build->string_mb);
2959 2956 }
2960 2957
2961 2958
2962 2959 result = doname_parallel(default_target_to_build, true, false);
2963 2960 gather_recursive_deps();
2964 2961 if (build_failed_seen) {
2965 2962 build_failed_ever_seen = true;
2966 2963 warning(gettext("Target `%s' not remade because of errors"),
2967 2964 default_target_to_build->string_mb);
2968 2965 }
2969 2966 build_failed_seen = false;
2970 2967 if (report_dependencies_level > 0) {
2971 2968 print_dependencies(default_target_to_build,
2972 2969 get_prop(default_target_to_build->
2973 2970 prop,
2974 2971 line_prop));
2975 2972 }
2976 2973 default_target_to_build->stat.time = file_no_time;
2977 2974 if (default_target_to_build->colon_splits > 0) {
2978 2975 default_target_to_build->state = build_dont_know;
2979 2976 }
2980 2977 if (/* !commands_done && */
2981 2978 (result == build_ok) &&
2982 2979 !quest &&
2983 2980 (report_dependencies_level == 0) /* &&
2984 2981 (exists(default_target_to_build) > file_doesnt_exist) */) {
2985 2982 if (posix) {
2986 2983 if (!commands_done) {
2987 2984 (void) printf(gettext("`%s' is updated.\n"),
2988 2985 default_target_to_build->string_mb);
2989 2986 } else {
2990 2987 if (no_action_was_taken) {
2991 2988 (void) printf(gettext("`%s': no action was taken.\n"),
2992 2989 default_target_to_build->string_mb);
2993 2990 }
2994 2991 }
2995 2992 } else {
2996 2993 if (!commands_done &&
2997 2994 (exists(default_target_to_build) > file_doesnt_exist)) {
2998 2995 (void) printf(gettext("`%s' is up to date.\n"),
2999 2996 default_target_to_build->string_mb);
3000 2997 }
3001 2998 }
3002 2999 }
3003 3000 }
3004 3001 }
3005 3002
3006 3003 /*
3007 3004 * report_recursion(target)
3008 3005 *
3009 3006 * If this is a recursive make and the parent make has KEEP_STATE on
3010 3007 * this routine reports the dependency to the parent make
3011 3008 *
3012 3009 * Parameters:
3013 3010 * target Target to report
3014 3011 *
3015 3012 * Global variables used:
3016 3013 * makefiles_used List of makefiles read
3017 3014 * recursive_name The Name ".RECURSIVE", printed
3018 3015 * report_dependency dwight
3019 3016 */
3020 3017 static void
3021 3018 report_recursion(register Name target)
3022 3019 {
3023 3020 register FILE *report_file = get_report_file();
3024 3021
3025 3022 if ((report_file == NULL) || (report_file == (FILE*)-1)) {
3026 3023 return;
3027 3024 }
3028 3025 if (primary_makefile == NULL) {
3029 3026 /*
3030 3027 * This can happen when there is no makefile and
3031 3028 * only implicit rules are being used.
3032 3029 */
3033 3030 return;
3034 3031 }
3035 3032 (void) fprintf(report_file,
3036 3033 "%s: %s ",
3037 3034 get_target_being_reported_for(),
3038 3035 recursive_name->string_mb);
3039 3036 report_dependency(get_current_path());
3040 3037 report_dependency(target->string_mb);
3041 3038 report_dependency(primary_makefile->string_mb);
3042 3039 (void) fprintf(report_file, "\n");
3043 3040 }
3044 3041
3045 3042 /* Next function "append_or_replace_macro_in_dyn_array" must be in "misc.cc". */
3046 3043 /* NIKMOL */
3047 3044 extern void
3048 3045 append_or_replace_macro_in_dyn_array(ASCII_Dyn_Array *Ar, char *macro)
3049 3046 {
3050 3047 register char *cp0; /* work pointer in macro */
3051 3048 register char *cp1; /* work pointer in array */
3052 3049 register char *cp2; /* work pointer in array */
3053 3050 register char *cp3; /* work pointer in array */
3054 3051 register char *name; /* macro name */
3055 3052 register char *value; /* macro value */
3056 3053 register int len_array;
3057 3054 register int len_macro;
3058 3055
3059 3056 char * esc_value = NULL;
3060 3057 int esc_len;
3061 3058
3062 3059 if (!(len_macro = strlen(macro))) return;
3063 3060 name = macro;
3064 3061 while (isspace(*(name))) {
3065 3062 name++;
3066 3063 }
3067 3064 if (!(value = strchr(name, (int) equal_char))) {
3068 3065 /* no '=' in macro */
3069 3066 goto ERROR_MACRO;
3070 3067 }
3071 3068 cp0 = value;
3072 3069 value++;
3073 3070 while (isspace(*(value))) {
3074 3071 value++;
3075 3072 }
3076 3073 while (isspace(*(cp0-1))) {
3077 3074 cp0--;
3078 3075 }
3079 3076 if (cp0 <= name) goto ERROR_MACRO; /* no name */
3080 3077 if (!(Ar->size)) goto ALLOC_ARRAY;
3081 3078 cp1 = Ar->start;
3082 3079
3083 3080 LOOK_FOR_NAME:
3084 3081 if (!(cp1 = strchr(cp1, name[0]))) goto APPEND_MACRO;
3085 3082 if (!(cp2 = strchr(cp1, (int) equal_char))) goto APPEND_MACRO;
3086 3083 if (strncmp(cp1, name, (size_t)(cp0-name))) {
3087 3084 /* another name */
3088 3085 cp1++;
3089 3086 goto LOOK_FOR_NAME;
3090 3087 }
3091 3088 if (cp1 != Ar->start) {
3092 3089 if (!isspace(*(cp1-1))) {
3093 3090 /* another name */
3094 3091 cp1++;
3095 3092 goto LOOK_FOR_NAME;
3096 3093 }
3097 3094 }
3098 3095 for (cp3 = cp1 + (cp0-name); cp3 < cp2; cp3++) {
3099 3096 if (isspace(*cp3)) continue;
3100 3097 /* else: another name */
3101 3098 cp1++;
3102 3099 goto LOOK_FOR_NAME;
3103 3100 }
3104 3101 /* Look for the next macro name in array */
3105 3102 cp3 = cp2+1;
3106 3103 if (*cp3 != (int) doublequote_char) {
3107 3104 /* internal error */
3108 3105 goto ERROR_MACRO;
3109 3106 }
3110 3107 if (!(cp3 = strchr(cp3+1, (int) doublequote_char))) {
3111 3108 /* internal error */
3112 3109 goto ERROR_MACRO;
3113 3110 }
3114 3111 cp3++;
3115 3112 while (isspace(*cp3)) {
3116 3113 cp3++;
3117 3114 }
3118 3115
3119 3116 cp2 = cp1; /* remove old macro */
3120 3117 if ((*cp3) && (cp3 < Ar->start + Ar->size)) {
3121 3118 for (; cp3 < Ar->start + Ar->size; cp3++) {
3122 3119 *cp2++ = *cp3;
3123 3120 }
3124 3121 }
3125 3122 for (; cp2 < Ar->start + Ar->size; cp2++) {
3126 3123 *cp2 = 0;
3127 3124 }
3128 3125 if (*cp1) {
3129 3126 /* check next name */
3130 3127 goto LOOK_FOR_NAME;
3131 3128 }
3132 3129 goto APPEND_MACRO;
3133 3130
3134 3131 ALLOC_ARRAY:
3135 3132 if (Ar->size) {
3136 3133 cp1 = Ar->start;
3137 3134 } else {
3138 3135 cp1 = 0;
3139 3136 }
3140 3137 Ar->size += 128;
3141 3138 Ar->start = getmem(Ar->size);
3142 3139 for (len_array=0; len_array < Ar->size; len_array++) {
3143 3140 Ar->start[len_array] = 0;
3144 3141 }
3145 3142 if (cp1) {
3146 3143 strcpy(Ar->start, cp1);
3147 3144 retmem((wchar_t *) cp1);
3148 3145 }
3149 3146
3150 3147 APPEND_MACRO:
3151 3148 len_array = strlen(Ar->start);
3152 3149 esc_value = (char*)malloc(strlen(value)*2 + 1);
3153 3150 quote_str(value, esc_value);
3154 3151 esc_len = strlen(esc_value) - strlen(value);
3155 3152 if (len_array + len_macro + esc_len + 5 >= Ar->size) goto ALLOC_ARRAY;
3156 3153 strcat(Ar->start, " ");
3157 3154 strncat(Ar->start, name, cp0-name);
3158 3155 strcat(Ar->start, "=");
3159 3156 strncat(Ar->start, esc_value, strlen(esc_value));
3160 3157 free(esc_value);
3161 3158 return;
3162 3159 ERROR_MACRO:
3163 3160 /* Macro without '=' or with invalid left/right part */
3164 3161 return;
3165 3162 }
3166 3163
3167 3164 static void
3168 3165 report_dir_enter_leave(Boolean entering)
3169 3166 {
3170 3167 char rcwd[MAXPATHLEN];
3171 3168 static char * mlev = NULL;
3172 3169 char * make_level_str = NULL;
3173 3170 int make_level_val = 0;
3174 3171
3175 3172 make_level_str = getenv("MAKELEVEL");
3176 3173 if(make_level_str) {
3177 3174 make_level_val = atoi(make_level_str);
3178 3175 }
3179 3176 if(mlev == NULL) {
3180 3177 mlev = (char*) malloc(MAXPATHLEN);
3181 3178 }
3182 3179 if(entering) {
3183 3180 sprintf(mlev, "MAKELEVEL=%d", make_level_val + 1);
3184 3181 } else {
3185 3182 make_level_val--;
3186 3183 sprintf(mlev, "MAKELEVEL=%d", make_level_val);
3187 3184 }
3188 3185 putenv(mlev);
3189 3186
3190 3187 if(report_cwd) {
3191 3188 if(make_level_val <= 0) {
3192 3189 if(entering) {
3193 3190 sprintf( rcwd
3194 3191 , gettext("dmake: Entering directory `%s'\n")
3195 3192 , get_current_path());
3196 3193 } else {
3197 3194 sprintf( rcwd
3198 3195 , gettext("dmake: Leaving directory `%s'\n")
3199 3196 , get_current_path());
3200 3197 }
3201 3198 } else {
3202 3199 if(entering) {
3203 3200 sprintf( rcwd
3204 3201 , gettext("dmake[%d]: Entering directory `%s'\n")
3205 3202 , make_level_val, get_current_path());
3206 3203 } else {
3207 3204 sprintf( rcwd
3208 3205 , gettext("dmake[%d]: Leaving directory `%s'\n")
3209 3206 , make_level_val, get_current_path());
3210 3207 }
3211 3208 }
3212 3209 printf("%s", rcwd);
3213 3210 }
3214 3211 }
↓ open down ↓ |
2014 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX