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