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