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