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