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