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