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