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