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