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