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