Print this page
make: unifdef for NSE (undefined)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/bin/read.cc
+++ new/usr/src/cmd/make/bin/read.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 * read.c
28 28 *
29 29 * This file contains the makefile reader.
30 30 */
31 31
32 32 /*
33 33 * Included files
34 34 */
35 35 #include <avo/avo_alloca.h> /* alloca() */
36 36 #include <errno.h> /* errno */
37 37 #include <fcntl.h> /* fcntl() */
38 38 #include <mk/defs.h>
39 39 #include <mksh/macro.h> /* expand_value(), expand_macro() */
40 40 #include <mksh/misc.h> /* getmem() */
41 41 #include <mksh/read.h> /* get_next_block_fn() */
42 42 #include <sys/uio.h> /* read() */
43 43 #include <unistd.h> /* read(), unlink() */
44 44
45 45
46 46 /*
47 47 * typedefs & structs
48 48 */
49 49
50 50 /*
51 51 * Static variables
52 52 */
53 53
54 54 static int line_started_with_space=0; // Used to diagnose spaces instead of tabs
55 55
56 56 /*
57 57 * File table of contents
58 58 */
59 59 static void parse_makefile(register Name true_makefile_name, register Source source);
60 60 static Source push_macro_value(register Source bp, register wchar_t *buffer, int size, register Source source);
61 61 extern void enter_target_groups_and_dependencies(Name_vector target, Name_vector depes, Cmd_line command, Separator separator, Boolean target_group_seen);
62 62 extern Name normalize_name(register wchar_t *name_string, register int length);
63 63
64 64 /*
65 65 * read_simple_file(makefile_name, chase_path, doname_it,
66 66 * complain, must_exist, report_file, lock_makefile)
67 67 *
68 68 * Make the makefile and setup to read it. Actually read it if it is stdio
69 69 *
70 70 * Return value:
71 71 * false if the read failed
72 72 *
73 73 * Parameters:
74 74 * makefile_name Name of the file to read
75 75 * chase_path Use the makefile path when opening file
76 76 * doname_it Call doname() to build the file first
77 77 * complain Print message if doname/open fails
78 78 * must_exist Generate fatal if file is missing
79 79 * report_file Report file when running -P
80 80 * lock_makefile Lock the makefile when reading
81 81 *
82 82 * Static variables used:
83 83 *
84 84 * Global variables used:
85 85 * do_not_exec_rule Is -n on?
86 86 * file_being_read Set to the name of the new file
87 87 * line_number The number of the current makefile line
88 88 * makefiles_used A list of all makefiles used, appended to
89 89 */
90 90
91 91
92 92 Boolean
93 93 read_simple_file(register Name makefile_name, register Boolean chase_path, register Boolean doname_it, Boolean complain, Boolean must_exist, Boolean report_file, Boolean lock_makefile)
94 94 {
95 95 static short max_include_depth;
96 96 register Property makefile = maybe_append_prop(makefile_name,
97 97 makefile_prop);
98 98 Boolean forget_after_parse = false;
99 99 static pathpt makefile_path;
100 100 register int n;
101 101 char *path;
102 102 register Source source = ALLOC(Source);
103 103 Property orig_makefile = makefile;
104 104 Dependency *dpp;
105 105 Dependency dp;
106 106 register int length;
107 107 wchar_t *previous_file_being_read = file_being_read;
108 108 int previous_line_number = line_number;
↓ open down ↓ |
108 lines elided |
↑ open up ↑ |
109 109 wchar_t previous_current_makefile[MAXPATHLEN];
110 110 Makefile_type save_makefile_type;
111 111 Name normalized_makefile_name;
112 112 register wchar_t *string_start;
113 113 register wchar_t *string_end;
114 114
115 115
116 116
117 117 wchar_t * wcb = get_wstring(makefile_name->string_mb);
118 118
119 -#ifdef NSE
120 - if (report_file){
121 - wscpy(previous_current_makefile, current_makefile);
122 - wscpy(current_makefile, wcb);
123 - }
124 -#endif
125 119 if (max_include_depth++ >= 40) {
126 120 fatal(catgets(catd, 1, 66, "Too many nested include statements"));
127 121 }
128 122 if (makefile->body.makefile.contents != NULL) {
129 123 retmem(makefile->body.makefile.contents);
130 124 }
131 125 source->inp_buf =
132 126 source->inp_buf_ptr =
133 127 source->inp_buf_end = NULL;
134 128 source->error_converting = false;
135 129 makefile->body.makefile.contents = NULL;
136 130 makefile->body.makefile.size = 0;
137 131 if ((makefile_name->hash.length != 1) ||
138 132 (wcb[0] != (int) hyphen_char)) {
139 133 if ((makefile->body.makefile.contents == NULL) &&
140 134 (doname_it)) {
141 135 if (makefile_path == NULL) {
142 136 add_dir_to_path(".",
143 137 &makefile_path,
144 138 -1);
145 139 add_dir_to_path(NOCATGETS("/usr/share/lib/make"),
146 140 &makefile_path,
147 141 -1);
148 142 add_dir_to_path(NOCATGETS("/etc/default"),
149 143 &makefile_path,
150 144 -1);
151 145 }
152 146 save_makefile_type = makefile_type;
153 147 makefile_type = reading_nothing;
154 148 if (doname(makefile_name, true, false) == build_dont_know) {
155 149 /* Try normalized filename */
156 150 string_start=get_wstring(makefile_name->string_mb);
157 151 for (string_end=string_start+1; *string_end != L'\0'; string_end++);
158 152 normalized_makefile_name=normalize_name(string_start, string_end - string_start);
159 153 if ((strcmp(makefile_name->string_mb, normalized_makefile_name->string_mb) == 0) ||
160 154 (doname(normalized_makefile_name, true, false) == build_dont_know)) {
161 155 n = access_vroot(makefile_name->string_mb,
162 156 4,
163 157 chase_path ?
164 158 makefile_path : NULL,
165 159 VROOT_DEFAULT);
166 160 if (n == 0) {
167 161 get_vroot_path((char **) NULL,
168 162 &path,
169 163 (char **) NULL);
170 164 if ((path[0] == (int) period_char) &&
171 165 (path[1] == (int) slash_char)) {
172 166 path += 2;
173 167 }
174 168 MBSTOWCS(wcs_buffer, path);
175 169 makefile_name = GETNAME(wcs_buffer,
176 170 FIND_LENGTH);
177 171 }
178 172 }
179 173 retmem(string_start);
180 174 /*
181 175 * Commented out: retmem_mb(normalized_makefile_name->string_mb);
182 176 * We have to return this memory, but it seems to trigger a bug
183 177 * in dmake or in Sun C++ 5.7 compiler (it works ok if this code
184 178 * is compiled using Sun C++ 5.6).
185 179 */
186 180 // retmem_mb(normalized_makefile_name->string_mb);
187 181 }
188 182 makefile_type = save_makefile_type;
189 183 }
190 184 source->string.free_after_use = false;
191 185 source->previous = NULL;
192 186 source->already_expanded = false;
193 187 /* Lock the file for read, but not when -n. */
194 188 if (lock_makefile &&
195 189 !do_not_exec_rule) {
196 190
197 191 make_state_lockfile = getmem(strlen(make_state->string_mb) + strlen(NOCATGETS(".lock")) + 1);
198 192 (void) sprintf(make_state_lockfile,
199 193 NOCATGETS("%s.lock"),
200 194 make_state->string_mb);
201 195 (void) file_lock(make_state->string_mb,
202 196 make_state_lockfile,
203 197 (int *) &make_state_locked,
204 198 0);
205 199 if(!make_state_locked) {
206 200 printf(NOCATGETS("-- NO LOCKING for read\n"));
207 201 retmem_mb(make_state_lockfile);
208 202 make_state_lockfile = 0;
209 203 return failed;
210 204 }
211 205 }
212 206 if (makefile->body.makefile.contents == NULL) {
213 207 save_makefile_type = makefile_type;
214 208 makefile_type = reading_nothing;
215 209 if ((doname_it) &&
216 210 (doname(makefile_name, true, false) == build_failed)) {
217 211 if (complain) {
218 212 (void) fprintf(stderr,
219 213 #ifdef DISTRIBUTED
220 214 catgets(catd, 1, 67, "dmake: Couldn't dmake `%s'\n"),
221 215 #else
222 216 catgets(catd, 1, 237, "make: Couldn't make `%s'\n"),
223 217 #endif
224 218 makefile_name->string_mb);
225 219 }
226 220 max_include_depth--;
227 221 makefile_type = save_makefile_type;
228 222 return failed;
229 223 }
230 224 makefile_type = save_makefile_type;
231 225 //
232 226 // Before calling exists() make sure that we have the right timestamp
233 227 //
234 228 makefile_name->stat.time = file_no_time;
235 229
236 230 if (exists(makefile_name) == file_doesnt_exist) {
237 231 if (complain ||
238 232 (makefile_name->stat.stat_errno != ENOENT)) {
239 233 if (must_exist) {
240 234 fatal(catgets(catd, 1, 68, "Can't find `%s': %s"),
241 235 makefile_name->string_mb,
242 236 errmsg(makefile_name->
243 237 stat.stat_errno));
244 238 } else {
245 239 warning(catgets(catd, 1, 69, "Can't find `%s': %s"),
246 240 makefile_name->string_mb,
247 241 errmsg(makefile_name->
248 242 stat.stat_errno));
249 243 }
250 244 }
251 245 max_include_depth--;
252 246 if(make_state_locked && (make_state_lockfile != NULL)) {
253 247 (void) unlink(make_state_lockfile);
254 248 retmem_mb(make_state_lockfile);
255 249 make_state_lockfile = NULL;
256 250 make_state_locked = false;
257 251 }
258 252 retmem(wcb);
259 253 retmem_mb((char *)source);
260 254 return failed;
261 255 }
262 256 /*
263 257 * These values are the size and bytes of
264 258 * the MULTI-BYTE makefile.
265 259 */
266 260 orig_makefile->body.makefile.size =
267 261 makefile->body.makefile.size =
268 262 source->bytes_left_in_file =
269 263 makefile_name->stat.size;
270 264 if (report_file) {
271 265 for (dpp = &makefiles_used;
272 266 *dpp != NULL;
273 267 dpp = &(*dpp)->next);
274 268 dp = ALLOC(Dependency);
275 269 dp->next = NULL;
276 270 dp->name = makefile_name;
277 271 dp->automatic = false;
278 272 dp->stale = false;
279 273 dp->built = false;
280 274 *dpp = dp;
281 275 }
282 276 source->fd = open_vroot(makefile_name->string_mb,
283 277 O_RDONLY,
284 278 0,
285 279 NULL,
286 280 VROOT_DEFAULT);
287 281 if (source->fd < 0) {
288 282 if (complain || (errno != ENOENT)) {
289 283 if (must_exist) {
290 284 fatal(catgets(catd, 1, 70, "Can't open `%s': %s"),
291 285 makefile_name->string_mb,
292 286 errmsg(errno));
293 287 } else {
294 288 warning(catgets(catd, 1, 71, "Can't open `%s': %s"),
295 289 makefile_name->string_mb,
296 290 errmsg(errno));
297 291 }
298 292 }
299 293 max_include_depth--;
300 294 return failed;
301 295 }
302 296 (void) fcntl(source->fd, F_SETFD, 1);
303 297 orig_makefile->body.makefile.contents =
304 298 makefile->body.makefile.contents =
305 299 source->string.text.p =
306 300 source->string.buffer.start =
307 301 ALLOC_WC((int) (makefile_name->stat.size + 2));
308 302 if (makefile_type == reading_cpp_file) {
309 303 forget_after_parse = true;
310 304 }
311 305 source->string.text.end = source->string.text.p;
312 306 source->string.buffer.end =
313 307 source->string.text.p + makefile_name->stat.size;
314 308 } else {
315 309 /* Do we ever reach here? */
316 310 source->fd = -1;
317 311 source->string.text.p =
318 312 source->string.buffer.start =
319 313 makefile->body.makefile.contents;
320 314 source->string.text.end =
321 315 source->string.buffer.end =
322 316 source->string.text.p + makefile->body.makefile.size;
323 317 source->bytes_left_in_file =
324 318 makefile->body.makefile.size;
325 319 }
326 320 file_being_read = wcb;
327 321 } else {
328 322 char *stdin_text_p;
329 323 char *stdin_text_end;
330 324 char *stdin_buffer_start;
331 325 char *stdin_buffer_end;
332 326 char *p_mb;
333 327 int num_mb_chars;
334 328 size_t num_wc_chars;
335 329
336 330 MBSTOWCS(wcs_buffer, NOCATGETS("Standard in"));
337 331 makefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
338 332 /*
339 333 * Memory to read standard in, then convert it
340 334 * to wide char strings.
341 335 */
342 336 stdin_buffer_start =
343 337 stdin_text_p = getmem(length = 1024);
344 338 stdin_buffer_end = stdin_text_p + length;
345 339 MBSTOWCS(wcs_buffer, NOCATGETS("standard input"));
346 340 file_being_read = (wchar_t *) wsdup(wcs_buffer);
347 341 line_number = 0;
348 342 while ((n = read(fileno(stdin),
349 343 stdin_text_p,
350 344 length)) > 0) {
351 345 length -= n;
352 346 stdin_text_p += n;
353 347 if (length == 0) {
354 348 p_mb = getmem(length = 1024 +
355 349 (stdin_buffer_end -
356 350 stdin_buffer_start));
357 351 (void) strncpy(p_mb,
358 352 stdin_buffer_start,
359 353 (stdin_buffer_end -
360 354 stdin_buffer_start));
361 355 retmem_mb(stdin_buffer_start);
362 356 stdin_text_p = p_mb +
363 357 (stdin_buffer_end - stdin_buffer_start);
364 358 stdin_buffer_start = p_mb;
365 359 stdin_buffer_end =
366 360 stdin_buffer_start + length;
367 361 length = 1024;
368 362 }
369 363 }
370 364 if (n < 0) {
371 365 fatal(catgets(catd, 1, 72, "Error reading standard input: %s"),
372 366 errmsg(errno));
373 367 }
374 368 stdin_text_p = stdin_buffer_start;
375 369 stdin_text_end = stdin_buffer_end - length;
376 370 num_mb_chars = stdin_text_end - stdin_text_p;
377 371
378 372 /*
379 373 * Now, convert the sequence of multibyte chars into
380 374 * a sequence of corresponding wide character codes.
381 375 */
382 376 source->string.free_after_use = false;
383 377 source->previous = NULL;
384 378 source->bytes_left_in_file = 0;
385 379 source->fd = -1;
386 380 source->already_expanded = false;
387 381 source->string.buffer.start =
388 382 source->string.text.p = ALLOC_WC(num_mb_chars + 1);
389 383 source->string.buffer.end =
390 384 source->string.text.p + num_mb_chars;
391 385 num_wc_chars = mbstowcs(source->string.text.p,
392 386 stdin_text_p,
393 387 num_mb_chars);
394 388 if ((int) num_wc_chars >= 0) {
395 389 source->string.text.end =
396 390 source->string.text.p + num_wc_chars;
397 391 }
398 392 (void) retmem_mb(stdin_text_p);
399 393 }
↓ open down ↓ |
265 lines elided |
↑ open up ↑ |
400 394 line_number = 1;
401 395 if (trace_reader) {
402 396 (void) printf(catgets(catd, 1, 73, ">>>>>>>>>>>>>>>> Reading makefile %s\n"),
403 397 makefile_name->string_mb);
404 398 }
405 399 parse_makefile(makefile_name, source);
406 400 if (trace_reader) {
407 401 (void) printf(catgets(catd, 1, 74, ">>>>>>>>>>>>>>>> End of makefile %s\n"),
408 402 makefile_name->string_mb);
409 403 }
410 -#ifdef NSE
411 - if (report_file && (previous_current_makefile[0] != NULL)) {
412 - wscpy(current_makefile, previous_current_makefile);
413 - }
414 -#endif
415 404 if(file_being_read) {
416 405 retmem(file_being_read);
417 406 }
418 407 file_being_read = previous_file_being_read;
419 408 line_number = previous_line_number;
420 409 makefile_type = reading_nothing;
421 410 max_include_depth--;
422 411 if (make_state_locked) {
423 412 /* Unlock .make.state. */
424 413 unlink(make_state_lockfile);
425 414 make_state_locked = false;
426 415 retmem_mb(make_state_lockfile);
427 416 }
428 417 if (forget_after_parse) {
429 418 retmem(makefile->body.makefile.contents);
430 419 makefile->body.makefile.contents = NULL;
431 420 }
432 421 retmem_mb((char *)source);
433 422 return succeeded;
434 423 }
435 424
436 425 /*
437 426 * parse_makefile(true_makefile_name, source)
438 427 *
439 428 * Strings are read from Sources.
440 429 * When macros are found, their values are represented by a
441 430 * Source that is pushed on a stack. At end of string
442 431 * (that is returned from GET_CHAR() as 0), the block is popped.
443 432 *
444 433 * Parameters:
445 434 * true_makefile_name The name of makefile we are parsing
446 435 * source The source block to read from
447 436 *
448 437 * Global variables used:
449 438 * do_not_exec_rule Is -n on?
450 439 * line_number The number of the current makefile line
451 440 * makefile_type What kind of makefile are we reading?
452 441 * empty_name The Name ""
453 442 */
454 443 static void
455 444 parse_makefile(register Name true_makefile_name, register Source source)
456 445 {
457 446 /*
458 447 char mb_buffer[MB_LEN_MAX];
459 448 */
460 449 register wchar_t *source_p;
461 450 register wchar_t *source_end;
462 451 register wchar_t *string_start;
463 452 wchar_t *string_end;
464 453 register Boolean macro_seen_in_string;
465 454 Boolean append;
466 455 String_rec name_string;
467 456 wchar_t name_buffer[STRING_BUFFER_LENGTH];
468 457 register int distance;
469 458 register int paren_count;
470 459 int brace_count;
471 460 int char_number;
472 461 Cmd_line command;
473 462 Cmd_line command_tail;
474 463 Name macro_value;
475 464
476 465 Name_vector_rec target;
477 466 Name_vector_rec depes;
478 467 Name_vector_rec extra_name_vector;
479 468 Name_vector current_names;
480 469 Name_vector extra_names = &extra_name_vector;
481 470 Name_vector nvp;
482 471 Boolean target_group_seen;
483 472
484 473 register Reader_state state;
485 474 register Reader_state on_eoln_state;
486 475 register Separator separator;
487 476
488 477 wchar_t buffer[4 * STRING_BUFFER_LENGTH];
489 478 Source extrap;
490 479
491 480 Boolean save_do_not_exec_rule = do_not_exec_rule;
492 481 Name makefile_name;
493 482
494 483 static Name sh_name;
495 484 static Name shell_name;
496 485 int i;
497 486
498 487 static wchar_t include_space[10];
499 488 static wchar_t include_tab[10];
500 489 int tmp_bytes_left_in_string;
501 490 Boolean tmp_maybe_include = false;
502 491 int emptycount = 0;
503 492 Boolean first_target;
504 493
505 494 String_rec include_name;
506 495 wchar_t include_buffer[STRING_BUFFER_LENGTH];
507 496
508 497 target.next = depes.next = NULL;
509 498 /* Move some values from their struct to register declared locals */
510 499 CACHE_SOURCE(0);
511 500
512 501 start_new_line:
513 502 /*
514 503 * Read whitespace on old line. Leave pointer on first char on
515 504 * next line.
516 505 */
517 506 first_target = true;
518 507 on_eoln_state = exit_state;
519 508 /*
520 509 for (WCTOMB(mb_buffer, GET_CHAR());
521 510 1;
522 511 source_p++, WCTOMB(mb_buffer, GET_CHAR()))
523 512 switch (mb_buffer[0]) {
524 513 */
525 514 for (char_number=0; 1; source_p++,char_number++) switch (GET_CHAR()) {
526 515 case nul_char:
527 516 /* End of this string. Pop it and return to the previous one */
528 517 GET_NEXT_BLOCK(source);
529 518 source_p--;
530 519 if (source == NULL) {
531 520 GOTO_STATE(on_eoln_state);
532 521 }
533 522 break;
534 523 case newline_char:
535 524 end_of_line:
536 525 source_p++;
537 526 if (source->fd >= 0) {
538 527 line_number++;
539 528 }
540 529 switch (GET_CHAR()) {
541 530 case nul_char:
542 531 GET_NEXT_BLOCK(source);
543 532 if (source == NULL) {
544 533 GOTO_STATE(on_eoln_state);
545 534 }
546 535 /* Go back to the top of this loop */
547 536 goto start_new_line;
548 537 case newline_char:
549 538 case numbersign_char:
550 539 case dollar_char:
551 540 case space_char:
552 541 case tab_char:
553 542 /*
554 543 * Go back to the top of this loop since the
555 544 * new line does not start with a regular char.
556 545 */
557 546 goto start_new_line;
558 547 default:
559 548 /* We found the first proper char on the new line */
560 549 goto start_new_line_no_skip;
561 550 }
562 551 case space_char:
563 552 if (char_number == 0)
564 553 line_started_with_space=line_number;
565 554 case tab_char:
566 555 /* Whitespace. Just keep going in this loop */
567 556 break;
568 557 case numbersign_char:
569 558 /* Comment. Skip over it */
570 559 for (; 1; source_p++) {
571 560 switch (GET_CHAR()) {
572 561 case nul_char:
573 562 GET_NEXT_BLOCK_NOCHK(source);
574 563 if (source == NULL) {
575 564 GOTO_STATE(on_eoln_state);
576 565 }
577 566 if (source->error_converting) {
578 567 // Illegal byte sequence - skip its first byte
579 568 source->inp_buf_ptr++;
580 569 }
581 570 source_p--;
582 571 break;
583 572 case backslash_char:
584 573 /* Comments can be continued */
585 574 if (*++source_p == (int) nul_char) {
586 575 GET_NEXT_BLOCK_NOCHK(source);
587 576 if (source == NULL) {
588 577 GOTO_STATE(on_eoln_state);
589 578 }
590 579 if (source->error_converting) {
591 580 // Illegal byte sequence - skip its first byte
592 581 source->inp_buf_ptr++;
593 582 source_p--;
594 583 break;
595 584 }
596 585 }
597 586 if(*source_p == (int) newline_char) {
598 587 if (source->fd >= 0) {
599 588 line_number++;
600 589 }
601 590 }
602 591 break;
603 592 case newline_char:
604 593 /*
605 594 * After we skip the comment we go to
606 595 * the end of line handler since end of
607 596 * line terminates comments.
608 597 */
609 598 goto end_of_line;
610 599 }
611 600 }
612 601 case dollar_char:
613 602 /* Macro reference */
614 603 if (source->already_expanded) {
615 604 /*
616 605 * If we are reading from the expansion of a
617 606 * macro we already expanded everything enough.
618 607 */
619 608 goto start_new_line_no_skip;
620 609 }
621 610 /*
622 611 * Expand the value and push the Source on the stack of
623 612 * things being read.
624 613 */
625 614 source_p++;
626 615 UNCACHE_SOURCE();
627 616 {
628 617 Source t = (Source) alloca((int) sizeof (Source_rec));
629 618 source = push_macro_value(t,
630 619 buffer,
631 620 sizeof buffer,
632 621 source);
633 622 }
634 623 CACHE_SOURCE(1);
635 624 break;
636 625 default:
637 626 /* We found the first proper char on the new line */
638 627 goto start_new_line_no_skip;
639 628 }
640 629
641 630 /*
642 631 * We found the first normal char (one that starts an identifier)
643 632 * on the newline.
644 633 */
645 634 start_new_line_no_skip:
646 635 /* Inspect that first char to see if it maybe is special anyway */
647 636 switch (GET_CHAR()) {
648 637 case nul_char:
649 638 GET_NEXT_BLOCK(source);
650 639 if (source == NULL) {
651 640 GOTO_STATE(on_eoln_state);
652 641 }
653 642 goto start_new_line_no_skip;
654 643 case newline_char:
655 644 /* Just in case */
656 645 goto start_new_line;
657 646 case exclam_char:
658 647 /* Evaluate the line before it is read */
659 648 string_start = source_p + 1;
660 649 macro_seen_in_string = false;
661 650 /* Stuff the line in a string so we can eval it. */
662 651 for (; 1; source_p++) {
663 652 switch (GET_CHAR()) {
664 653 case newline_char:
665 654 goto eoln_1;
666 655 case nul_char:
667 656 if (source->fd > 0) {
668 657 if (!macro_seen_in_string) {
669 658 macro_seen_in_string = true;
670 659 INIT_STRING_FROM_STACK(
671 660 name_string, name_buffer);
672 661 }
673 662 append_string(string_start,
674 663 &name_string,
675 664 source_p - string_start);
676 665 GET_NEXT_BLOCK(source);
677 666 string_start = source_p;
678 667 source_p--;
679 668 break;
680 669 }
681 670 eoln_1:
682 671 if (!macro_seen_in_string) {
683 672 INIT_STRING_FROM_STACK(name_string,
684 673 name_buffer);
685 674 }
686 675 append_string(string_start,
687 676 &name_string,
688 677 source_p - string_start);
689 678 extrap = (Source)
690 679 alloca((int) sizeof (Source_rec));
691 680 extrap->string.buffer.start = NULL;
692 681 extrap->inp_buf =
693 682 extrap->inp_buf_ptr =
694 683 extrap->inp_buf_end = NULL;
695 684 extrap->error_converting = false;
696 685 if (*source_p == (int) nul_char) {
697 686 source_p++;
698 687 }
699 688 /* Eval the macro */
700 689 expand_value(GETNAME(name_string.buffer.start,
701 690 FIND_LENGTH),
702 691 &extrap->string,
703 692 false);
704 693 if (name_string.free_after_use) {
705 694 retmem(name_string.buffer.start);
706 695 }
707 696 UNCACHE_SOURCE();
708 697 extrap->string.text.p =
709 698 extrap->string.buffer.start;
710 699 extrap->fd = -1;
711 700 /* And push the value */
712 701 extrap->previous = source;
713 702 source = extrap;
714 703 CACHE_SOURCE(0);
715 704 goto line_evald;
716 705 }
717 706 }
718 707 default:
719 708 goto line_evald;
720 709 }
721 710
722 711 /* We now have a line we can start reading */
723 712 line_evald:
724 713 if (source == NULL) {
725 714 GOTO_STATE(exit_state);
726 715 }
727 716 /* Check if this is an include command */
728 717 if ((makefile_type == reading_makefile) &&
729 718 !source->already_expanded) {
730 719 if (include_space[0] == (int) nul_char) {
731 720 MBSTOWCS(include_space, NOCATGETS("include "));
732 721 MBSTOWCS(include_tab, NOCATGETS("include\t"));
733 722 }
734 723 if ((IS_WEQUALN(source_p, include_space, 8)) ||
735 724 (IS_WEQUALN(source_p, include_tab, 8))) {
736 725 source_p += 7;
737 726 if (iswspace(*source_p)) {
738 727 Makefile_type save_makefile_type;
739 728 wchar_t *name_start;
740 729 int name_length;
741 730
742 731 /*
743 732 * Yes, this is an include.
744 733 * Skip spaces to get to the filename.
745 734 */
746 735 while (iswspace(*source_p) ||
747 736 (*source_p == (int) nul_char)) {
748 737 switch (GET_CHAR()) {
749 738 case nul_char:
750 739 GET_NEXT_BLOCK(source);
751 740 if (source == NULL) {
752 741 GOTO_STATE(on_eoln_state);
753 742 }
754 743 break;
755 744
756 745 default:
757 746 source_p++;
758 747 break;
759 748 }
760 749 }
761 750
762 751 string_start = source_p;
763 752 /* Find the end of the filename */
764 753 macro_seen_in_string = false;
765 754 while (!iswspace(*source_p) ||
766 755 (*source_p == (int) nul_char)) {
767 756 switch (GET_CHAR()) {
768 757 case nul_char:
769 758 if (!macro_seen_in_string) {
770 759 INIT_STRING_FROM_STACK(name_string,
771 760 name_buffer);
772 761 }
773 762 append_string(string_start,
774 763 &name_string,
775 764 source_p - string_start);
776 765 macro_seen_in_string = true;
777 766 GET_NEXT_BLOCK(source);
778 767 string_start = source_p;
779 768 if (source == NULL) {
780 769 GOTO_STATE(on_eoln_state);
781 770 }
782 771 break;
783 772
784 773 default:
785 774 source_p++;
786 775 break;
787 776 }
788 777 }
789 778
790 779 source->string.text.p = source_p;
791 780 if (macro_seen_in_string) {
792 781 append_string(string_start,
793 782 &name_string,
794 783 source_p - string_start);
795 784 name_start = name_string.buffer.start;
796 785 name_length = name_string.text.p - name_start;
797 786 } else {
798 787 name_start = string_start;
799 788 name_length = source_p - string_start;
800 789 }
801 790
802 791 /* Strip "./" from the head of the name */
803 792 if ((name_start[0] == (int) period_char) &&
804 793 (name_start[1] == (int) slash_char)) {
805 794 name_start += 2;
806 795 name_length -= 2;
807 796 }
808 797 /* if include file name is surrounded by double quotes */
809 798 if ((name_start[0] == (int) doublequote_char) &&
810 799 (name_start[name_length - 1] == (int) doublequote_char)) {
811 800 name_start += 1;
812 801 name_length -= 2;
813 802
814 803 /* if name does not begin with a slash char */
815 804 if (name_start[0] != (int) slash_char) {
816 805 if ((name_start[0] == (int) period_char) &&
817 806 (name_start[1] == (int) slash_char)) {
818 807 name_start += 2;
819 808 name_length -= 2;
820 809 }
821 810
822 811 INIT_STRING_FROM_STACK(include_name, include_buffer);
823 812 APPEND_NAME(true_makefile_name,
824 813 &include_name,
825 814 true_makefile_name->hash.length);
826 815
827 816 wchar_t *slash = wsrchr(include_name.buffer.start, (int) slash_char);
828 817 if (slash != NULL) {
829 818 include_name.text.p = slash + 1;
830 819 append_string(name_start,
831 820 &include_name,
832 821 name_length);
833 822
834 823 name_start = include_name.buffer.start;
835 824 name_length = include_name.text.p - name_start;
836 825 }
837 826 }
838 827 }
839 828
840 829 /* Even when we run -n we want to create makefiles */
841 830 do_not_exec_rule = false;
842 831 makefile_name = GETNAME(name_start, name_length);
843 832 if (makefile_name->dollar) {
844 833 String_rec destination;
845 834 wchar_t buffer[STRING_BUFFER_LENGTH];
846 835 wchar_t *p;
847 836 wchar_t *q;
848 837
849 838 INIT_STRING_FROM_STACK(destination, buffer);
850 839 expand_value(makefile_name,
851 840 &destination,
852 841 false);
853 842 for (p = destination.buffer.start;
854 843 (*p != (int) nul_char) && iswspace(*p);
855 844 p++);
856 845 for (q = p;
857 846 (*q != (int) nul_char) && !iswspace(*q);
858 847 q++);
859 848 makefile_name = GETNAME(p, q-p);
860 849 if (destination.free_after_use) {
861 850 retmem(destination.buffer.start);
862 851 }
863 852 }
864 853 source_p++;
865 854 UNCACHE_SOURCE();
866 855 /* Read the file */
867 856 save_makefile_type = makefile_type;
868 857 if (read_simple_file(makefile_name,
869 858 true,
870 859 true,
871 860 true,
872 861 false,
873 862 true,
874 863 false) == failed) {
875 864 fatal_reader(catgets(catd, 1, 75, "Read of include file `%s' failed"),
876 865 makefile_name->string_mb);
877 866 }
878 867 makefile_type = save_makefile_type;
879 868 do_not_exec_rule = save_do_not_exec_rule;
880 869 CACHE_SOURCE(0);
881 870 goto start_new_line;
882 871 } else {
883 872 source_p -= 7;
884 873 }
885 874 } else {
886 875 /* Check if the word include was split across 8K boundary. */
887 876
888 877 tmp_bytes_left_in_string = source->string.text.end - source_p;
889 878 if (tmp_bytes_left_in_string < 8) {
890 879 tmp_maybe_include = false;
891 880 if (IS_WEQUALN(source_p,
892 881 include_space,
893 882 tmp_bytes_left_in_string)) {
894 883 tmp_maybe_include = true;
895 884 }
896 885 if (tmp_maybe_include) {
897 886 GET_NEXT_BLOCK(source);
898 887 tmp_maybe_include = false;
899 888 goto line_evald;
900 889 }
901 890 }
902 891 }
903 892 }
904 893
905 894 /* Reset the status in preparation for the new line */
906 895 for (nvp = ⌖ nvp != NULL; nvp = nvp->next) {
907 896 nvp->used = 0;
908 897 }
909 898 for (nvp = &depes; nvp != NULL; nvp = nvp->next) {
910 899 nvp->used = 0;
911 900 }
912 901 target_group_seen = false;
913 902 command = command_tail = NULL;
914 903 macro_value = NULL;
915 904 append = false;
916 905 current_names = ⌖
917 906 SET_STATE(scan_name_state);
918 907 on_eoln_state = illegal_eoln_state;
919 908 separator = none_seen;
920 909
921 910 /* The state machine starts here */
922 911 enter_state:
923 912 while (1) switch (state) {
924 913
925 914 /****************************************************************
926 915 * Scan name state
927 916 */
928 917 case scan_name_state:
929 918 /* Scan an identifier. We skip over chars until we find a break char */
930 919 /* First skip white space. */
931 920 for (; 1; source_p++) switch (GET_CHAR()) {
932 921 case nul_char:
933 922 GET_NEXT_BLOCK(source);
934 923 source_p--;
935 924 if (source == NULL) {
936 925 GOTO_STATE(on_eoln_state);
937 926 }
938 927 break;
939 928 case newline_char:
940 929 /* We found the end of the line. */
941 930 /* Do postprocessing or return error */
942 931 source_p++;
943 932 if (source->fd >= 0) {
944 933 line_number++;
945 934 }
946 935 GOTO_STATE(on_eoln_state);
947 936 case backslash_char:
948 937 /* Continuation */
949 938 if (*++source_p == (int) nul_char) {
950 939 GET_NEXT_BLOCK(source);
951 940 if (source == NULL) {
952 941 GOTO_STATE(on_eoln_state);
953 942 }
954 943 }
955 944 if (*source_p == (int) newline_char) {
956 945 if (source->fd >= 0) {
957 946 line_number++;
958 947 }
959 948 } else {
960 949 source_p--;
961 950 }
962 951 break;
963 952 case tab_char:
964 953 case space_char:
965 954 /* Whitespace is skipped */
966 955 break;
967 956 case numbersign_char:
968 957 /* Comment. Skip over it */
969 958 for (; 1; source_p++) {
970 959 switch (GET_CHAR()) {
971 960 case nul_char:
972 961 GET_NEXT_BLOCK_NOCHK(source);
973 962 if (source == NULL) {
974 963 GOTO_STATE(on_eoln_state);
975 964 }
976 965 if (source->error_converting) {
977 966 // Illegal byte sequence - skip its first byte
978 967 source->inp_buf_ptr++;
979 968 }
980 969 source_p--;
981 970 break;
982 971 case backslash_char:
983 972 if (*++source_p == (int) nul_char) {
984 973 GET_NEXT_BLOCK_NOCHK(source);
985 974 if (source == NULL) {
986 975 GOTO_STATE(on_eoln_state);
987 976 }
988 977 if (source->error_converting) {
989 978 // Illegal byte sequence - skip its first byte
990 979 source->inp_buf_ptr++;
991 980 source_p--;
992 981 break;
993 982 }
994 983 }
995 984 if(*source_p == (int) newline_char) {
996 985 if (source->fd >= 0) {
997 986 line_number++;
998 987 }
999 988 }
1000 989 break;
1001 990 case newline_char:
1002 991 source_p++;
1003 992 if (source->fd >= 0) {
1004 993 line_number++;
1005 994 }
1006 995 GOTO_STATE(on_eoln_state);
1007 996 }
1008 997 }
1009 998 case dollar_char:
1010 999 /* Macro reference. Expand and push value */
1011 1000 if (source->already_expanded) {
1012 1001 goto scan_name;
1013 1002 }
1014 1003 source_p++;
1015 1004 UNCACHE_SOURCE();
1016 1005 {
1017 1006 Source t = (Source) alloca((int) sizeof (Source_rec));
1018 1007 source = push_macro_value(t,
1019 1008 buffer,
1020 1009 sizeof buffer,
1021 1010 source);
1022 1011 }
1023 1012 CACHE_SOURCE(1);
1024 1013 break;
1025 1014 default:
1026 1015 /* End of white space */
1027 1016 goto scan_name;
1028 1017 }
1029 1018
1030 1019 /* First proper identifier character */
1031 1020 scan_name:
1032 1021
1033 1022 string_start = source_p;
1034 1023 paren_count = brace_count = 0;
1035 1024 macro_seen_in_string = false;
1036 1025 resume_name_scan:
1037 1026 for (; 1; source_p++) {
1038 1027 switch (GET_CHAR()) {
1039 1028 case nul_char:
1040 1029 /* Save what we have seen so far of the identifier */
1041 1030 if (source_p != string_start) {
1042 1031 if (!macro_seen_in_string) {
1043 1032 INIT_STRING_FROM_STACK(name_string,
1044 1033 name_buffer);
1045 1034 }
1046 1035 append_string(string_start,
1047 1036 &name_string,
1048 1037 source_p - string_start);
1049 1038 macro_seen_in_string = true;
1050 1039 }
1051 1040 /* Get more text to read */
1052 1041 GET_NEXT_BLOCK(source);
1053 1042 string_start = source_p;
1054 1043 source_p--;
1055 1044 if (source == NULL) {
1056 1045 GOTO_STATE(on_eoln_state);
1057 1046 }
1058 1047 break;
1059 1048 case newline_char:
1060 1049 if (paren_count > 0) {
1061 1050 fatal_reader(catgets(catd, 1, 76, "Unmatched `(' on line"));
1062 1051 }
1063 1052 if (brace_count > 0) {
1064 1053 fatal_reader(catgets(catd, 1, 77, "Unmatched `{' on line"));
1065 1054 }
1066 1055 source_p++;
1067 1056 /* Enter name */
1068 1057 current_names = enter_name(&name_string,
1069 1058 macro_seen_in_string,
1070 1059 string_start,
1071 1060 source_p - 1,
1072 1061 current_names,
1073 1062 &extra_names,
1074 1063 &target_group_seen);
1075 1064 first_target = false;
1076 1065 if (extra_names == NULL) {
1077 1066 extra_names = (Name_vector)
1078 1067 alloca((int) sizeof (Name_vector_rec));
1079 1068 }
1080 1069 /* Do postprocessing or return error */
1081 1070 if (source->fd >= 0) {
1082 1071 line_number++;
1083 1072 }
1084 1073 GOTO_STATE(on_eoln_state);
1085 1074 case backslash_char:
1086 1075 /* Check if this is a quoting backslash */
1087 1076 if (!macro_seen_in_string) {
1088 1077 INIT_STRING_FROM_STACK(name_string,
1089 1078 name_buffer);
1090 1079 macro_seen_in_string = true;
1091 1080 }
1092 1081 append_string(string_start,
1093 1082 &name_string,
1094 1083 source_p - string_start);
1095 1084 if (*++source_p == (int) nul_char) {
1096 1085 GET_NEXT_BLOCK(source);
1097 1086 if (source == NULL) {
1098 1087 GOTO_STATE(on_eoln_state);
1099 1088 }
1100 1089 }
1101 1090 if (*source_p == (int) newline_char) {
1102 1091 if (source->fd >= 0) {
1103 1092 line_number++;
1104 1093 }
1105 1094 *source_p = (int) space_char;
1106 1095 string_start = source_p;
1107 1096 goto resume_name_scan;
1108 1097 } else {
1109 1098 string_start = source_p;
1110 1099 break;
1111 1100 }
1112 1101 break;
1113 1102 case numbersign_char:
1114 1103 if (paren_count + brace_count > 0) {
1115 1104 break;
1116 1105 }
1117 1106 fatal_reader(catgets(catd, 1, 78, "Unexpected comment seen"));
1118 1107 case dollar_char:
1119 1108 if (source->already_expanded) {
1120 1109 break;
1121 1110 }
1122 1111 /* Save the identifier so far */
1123 1112 if (source_p != string_start) {
1124 1113 if (!macro_seen_in_string) {
1125 1114 INIT_STRING_FROM_STACK(name_string,
1126 1115 name_buffer);
1127 1116 }
1128 1117 append_string(string_start,
1129 1118 &name_string,
1130 1119 source_p - string_start);
1131 1120 macro_seen_in_string = true;
1132 1121 }
1133 1122 /* Eval and push the macro */
1134 1123 source_p++;
1135 1124 UNCACHE_SOURCE();
1136 1125 {
1137 1126 Source t =
1138 1127 (Source) alloca((int) sizeof (Source_rec));
1139 1128 source = push_macro_value(t,
1140 1129 buffer,
1141 1130 sizeof buffer,
1142 1131 source);
1143 1132 }
1144 1133 CACHE_SOURCE(1);
1145 1134 string_start = source_p + 1;
1146 1135 break;
1147 1136 case parenleft_char:
1148 1137 paren_count++;
1149 1138 break;
1150 1139 case parenright_char:
1151 1140 if (--paren_count < 0) {
1152 1141 fatal_reader(catgets(catd, 1, 79, "Unmatched `)' on line"));
1153 1142 }
1154 1143 break;
1155 1144 case braceleft_char:
1156 1145 brace_count++;
1157 1146 break;
1158 1147 case braceright_char:
1159 1148 if (--brace_count < 0) {
1160 1149 fatal_reader(catgets(catd, 1, 80, "Unmatched `}' on line"));
1161 1150 }
1162 1151 break;
1163 1152 case ampersand_char:
1164 1153 case greater_char:
1165 1154 case bar_char:
1166 1155 if (paren_count + brace_count == 0) {
1167 1156 source_p++;
1168 1157 }
1169 1158 /* Fall into */
1170 1159 case tab_char:
1171 1160 case space_char:
1172 1161 if (paren_count + brace_count > 0) {
1173 1162 break;
1174 1163 }
1175 1164 current_names = enter_name(&name_string,
1176 1165 macro_seen_in_string,
1177 1166 string_start,
1178 1167 source_p,
1179 1168 current_names,
1180 1169 &extra_names,
1181 1170 &target_group_seen);
1182 1171 first_target = false;
1183 1172 if (extra_names == NULL) {
1184 1173 extra_names = (Name_vector)
1185 1174 alloca((int) sizeof (Name_vector_rec));
1186 1175 }
1187 1176 goto enter_state;
1188 1177 case colon_char:
1189 1178 if (paren_count + brace_count > 0) {
1190 1179 break;
1191 1180 }
1192 1181 if (separator == conditional_seen) {
1193 1182 break;
1194 1183 }
1195 1184 /** POSIX **/
1196 1185 #if 0
1197 1186 if(posix) {
1198 1187 emptycount = 0;
1199 1188 }
1200 1189 #endif
1201 1190 /** END POSIX **/
1202 1191 /* End of the target list. We now start reading */
1203 1192 /* dependencies or a conditional assignment */
1204 1193 if (separator != none_seen) {
1205 1194 fatal_reader(catgets(catd, 1, 81, "Extra `:', `::', or `:=' on dependency line"));
1206 1195 }
1207 1196 /* Enter the last target */
1208 1197 if ((string_start != source_p) ||
1209 1198 macro_seen_in_string) {
1210 1199 current_names =
1211 1200 enter_name(&name_string,
1212 1201 macro_seen_in_string,
1213 1202 string_start,
1214 1203 source_p,
1215 1204 current_names,
1216 1205 &extra_names,
1217 1206 &target_group_seen);
1218 1207 first_target = false;
1219 1208 if (extra_names == NULL) {
1220 1209 extra_names = (Name_vector)
1221 1210 alloca((int)
1222 1211 sizeof (Name_vector_rec));
1223 1212 }
1224 1213 }
1225 1214 /* Check if it is ":" "::" or ":=" */
1226 1215 scan_colon_label:
1227 1216 switch (*++source_p) {
1228 1217 case nul_char:
1229 1218 GET_NEXT_BLOCK(source);
1230 1219 source_p--;
1231 1220 if (source == NULL) {
1232 1221 GOTO_STATE(enter_dependencies_state);
1233 1222 }
1234 1223 goto scan_colon_label;
1235 1224 case equal_char:
1236 1225 if(svr4) {
1237 1226 fatal_reader(catgets(catd, 1, 82, "syntax error"));
1238 1227 }
1239 1228 separator = conditional_seen;
1240 1229 source_p++;
1241 1230 current_names = &depes;
1242 1231 GOTO_STATE(scan_name_state);
1243 1232 case colon_char:
1244 1233 separator = two_colon;
1245 1234 source_p++;
1246 1235 break;
1247 1236 default:
1248 1237 separator = one_colon;
1249 1238 }
1250 1239 current_names = &depes;
1251 1240 on_eoln_state = enter_dependencies_state;
1252 1241 GOTO_STATE(scan_name_state);
1253 1242 case semicolon_char:
1254 1243 if (paren_count + brace_count > 0) {
1255 1244 break;
1256 1245 }
1257 1246 /* End of reading names. Start reading the rule */
1258 1247 if ((separator != one_colon) &&
1259 1248 (separator != two_colon)) {
1260 1249 fatal_reader(catgets(catd, 1, 83, "Unexpected command seen"));
1261 1250 }
1262 1251 /* Enter the last dependency */
1263 1252 if ((string_start != source_p) ||
1264 1253 macro_seen_in_string) {
1265 1254 current_names =
1266 1255 enter_name(&name_string,
1267 1256 macro_seen_in_string,
1268 1257 string_start,
1269 1258 source_p,
1270 1259 current_names,
1271 1260 &extra_names,
1272 1261 &target_group_seen);
1273 1262 first_target = false;
1274 1263 if (extra_names == NULL) {
1275 1264 extra_names = (Name_vector)
1276 1265 alloca((int)
1277 1266 sizeof (Name_vector_rec));
1278 1267 }
1279 1268 }
1280 1269 source_p++;
1281 1270 /* Make sure to enter a rule even if the is */
1282 1271 /* no text here */
1283 1272 command = command_tail = ALLOC(Cmd_line);
1284 1273 command->next = NULL;
1285 1274 command->command_line = empty_name;
1286 1275 command->make_refd = false;
1287 1276 command->ignore_command_dependency = false;
1288 1277 command->assign = false;
1289 1278 command->ignore_error = false;
1290 1279 command->silent = false;
1291 1280
1292 1281 GOTO_STATE(scan_command_state);
1293 1282 case plus_char:
1294 1283 /*
1295 1284 ** following code drops the target separator plus char if it starts
1296 1285 ** a line.
1297 1286 */
1298 1287 if(first_target && !macro_seen_in_string &&
1299 1288 source_p == string_start) {
1300 1289 for (; 1; source_p++)
1301 1290 switch (GET_CHAR()) {
1302 1291 case nul_char:
1303 1292 if (source_p != string_start) {
1304 1293 if (!macro_seen_in_string) {
1305 1294 INIT_STRING_FROM_STACK(name_string,
1306 1295 name_buffer);
1307 1296 }
1308 1297 append_string(string_start,
1309 1298 &name_string,
1310 1299 source_p - string_start);
1311 1300 macro_seen_in_string = true;
1312 1301 }
1313 1302 GET_NEXT_BLOCK(source);
1314 1303 string_start = source_p;
1315 1304 source_p--;
1316 1305 if (source == NULL) {
1317 1306 GOTO_STATE(on_eoln_state);
1318 1307 }
1319 1308 break;
1320 1309 case plus_char:
1321 1310 source_p++;
1322 1311 while (*source_p == (int) nul_char) {
1323 1312 if (source_p != string_start) {
1324 1313 if (!macro_seen_in_string) {
1325 1314 INIT_STRING_FROM_STACK(name_string,
1326 1315 name_buffer);
1327 1316 }
1328 1317 append_string(string_start,
1329 1318 &name_string,
1330 1319 source_p - string_start);
1331 1320 macro_seen_in_string = true;
1332 1321 }
1333 1322 GET_NEXT_BLOCK(source);
1334 1323 string_start = source_p;
1335 1324 if (source == NULL) {
1336 1325 GOTO_STATE(on_eoln_state);
1337 1326 }
1338 1327 }
1339 1328 if (*source_p == (int) tab_char ||
1340 1329 *source_p == (int) space_char) {
1341 1330 macro_seen_in_string = false;
1342 1331 string_start = source_p + 1;
1343 1332 } else {
1344 1333 goto resume_name_scan;
1345 1334 }
1346 1335 break;
1347 1336 case tab_char:
1348 1337 case space_char:
1349 1338 string_start = source_p + 1;
1350 1339 break;
1351 1340 default:
1352 1341 goto resume_name_scan;
1353 1342 }
1354 1343 }
1355 1344 if (paren_count + brace_count > 0) {
1356 1345 break;
1357 1346 }
1358 1347 /* We found "+=" construct */
1359 1348 if (source_p != string_start) {
1360 1349 /* "+" is not a break char. */
1361 1350 /* Ignore it if it is part of an identifier */
1362 1351 source_p++;
1363 1352 goto resume_name_scan;
1364 1353 }
1365 1354 /* Make sure the "+" is followed by a "=" */
1366 1355 scan_append:
1367 1356 switch (*++source_p) {
1368 1357 case nul_char:
1369 1358 if (!macro_seen_in_string) {
1370 1359 INIT_STRING_FROM_STACK(name_string,
1371 1360 name_buffer);
1372 1361 }
1373 1362 append_string(string_start,
1374 1363 &name_string,
1375 1364 source_p - string_start);
1376 1365 GET_NEXT_BLOCK(source);
1377 1366 source_p--;
1378 1367 string_start = source_p;
1379 1368 if (source == NULL) {
1380 1369 GOTO_STATE(illegal_eoln_state);
1381 1370 }
1382 1371 goto scan_append;
1383 1372 case equal_char:
1384 1373 if(!svr4) {
1385 1374 append = true;
1386 1375 } else {
1387 1376 fatal_reader(catgets(catd, 1, 84, "Must be a separator on rules"));
1388 1377 }
1389 1378 break;
1390 1379 default:
1391 1380 /* The "+" just starts a regular name. */
1392 1381 /* Start reading that name */
1393 1382 goto resume_name_scan;
1394 1383 }
1395 1384 /* Fall into */
1396 1385 case equal_char:
1397 1386 if (paren_count + brace_count > 0) {
1398 1387 break;
1399 1388 }
1400 1389 /* We found macro assignment. */
1401 1390 /* Check if it is legal and if it is appending */
1402 1391 switch (separator) {
1403 1392 case none_seen:
1404 1393 separator = equal_seen;
1405 1394 on_eoln_state = enter_equal_state;
1406 1395 break;
1407 1396 case conditional_seen:
1408 1397 on_eoln_state = enter_conditional_state;
1409 1398 break;
1410 1399 default:
1411 1400 /* Reader must special check for "MACRO:sh=" */
1412 1401 /* notation */
1413 1402 if (sh_name == NULL) {
1414 1403 MBSTOWCS(wcs_buffer, NOCATGETS("sh"));
1415 1404 sh_name = GETNAME(wcs_buffer, FIND_LENGTH);
1416 1405 MBSTOWCS(wcs_buffer, NOCATGETS("shell"));
1417 1406 shell_name = GETNAME(wcs_buffer, FIND_LENGTH);
1418 1407 }
1419 1408
1420 1409 if (!macro_seen_in_string) {
1421 1410 INIT_STRING_FROM_STACK(name_string,
1422 1411 name_buffer);
1423 1412 }
1424 1413 append_string(string_start,
1425 1414 &name_string,
1426 1415 source_p - string_start
1427 1416 );
1428 1417
1429 1418 if ( (((target.used == 1) &&
1430 1419 (depes.used == 1) &&
1431 1420 (depes.names[0] == sh_name)) ||
1432 1421 ((target.used == 1) &&
1433 1422 (depes.used == 0) &&
1434 1423 (separator == one_colon) &&
1435 1424 (GETNAME(name_string.buffer.start,FIND_LENGTH) == sh_name))) &&
1436 1425 (!svr4)) {
1437 1426 String_rec macro_name;
1438 1427 wchar_t buffer[100];
1439 1428
1440 1429 INIT_STRING_FROM_STACK(macro_name,
1441 1430 buffer);
1442 1431 APPEND_NAME(target.names[0],
1443 1432 ¯o_name,
1444 1433 FIND_LENGTH);
1445 1434 append_char((int) colon_char,
1446 1435 ¯o_name);
1447 1436 APPEND_NAME(sh_name,
1448 1437 ¯o_name,
1449 1438 FIND_LENGTH);
1450 1439 target.names[0] =
1451 1440 GETNAME(macro_name.buffer.start,
1452 1441 FIND_LENGTH);
1453 1442 separator = equal_seen;
1454 1443 on_eoln_state = enter_equal_state;
1455 1444 break;
1456 1445 } else if ( (((target.used == 1) &&
1457 1446 (depes.used == 1) &&
1458 1447 (depes.names[0] == shell_name)) ||
1459 1448 ((target.used == 1) &&
1460 1449 (depes.used == 0) &&
1461 1450 (separator == one_colon) &&
1462 1451 (GETNAME(name_string.buffer.start,FIND_LENGTH) == shell_name))) &&
1463 1452 (!svr4)) {
1464 1453 String_rec macro_name;
1465 1454 wchar_t buffer[100];
1466 1455
1467 1456 INIT_STRING_FROM_STACK(macro_name,
1468 1457 buffer);
1469 1458 APPEND_NAME(target.names[0],
1470 1459 ¯o_name,
1471 1460 FIND_LENGTH);
1472 1461 append_char((int) colon_char,
1473 1462 ¯o_name);
1474 1463 APPEND_NAME(shell_name,
1475 1464 ¯o_name,
1476 1465 FIND_LENGTH);
1477 1466 target.names[0] =
1478 1467 GETNAME(macro_name.buffer.start,
1479 1468 FIND_LENGTH);
1480 1469 separator = equal_seen;
1481 1470 on_eoln_state = enter_equal_state;
1482 1471 break;
1483 1472 }
1484 1473 if(svr4) {
1485 1474 fatal_reader(catgets(catd, 1, 85, "syntax error"));
1486 1475 }
1487 1476 else {
1488 1477 fatal_reader(catgets(catd, 1, 86, "Macro assignment on dependency line"));
1489 1478 }
1490 1479 }
1491 1480 if (append) {
1492 1481 source_p--;
1493 1482 }
1494 1483 /* Enter the macro name */
1495 1484 if ((string_start != source_p) ||
1496 1485 macro_seen_in_string) {
1497 1486 current_names =
1498 1487 enter_name(&name_string,
1499 1488 macro_seen_in_string,
1500 1489 string_start,
1501 1490 source_p,
1502 1491 current_names,
1503 1492 &extra_names,
1504 1493 &target_group_seen);
1505 1494 first_target = false;
1506 1495 if (extra_names == NULL) {
1507 1496 extra_names = (Name_vector)
1508 1497 alloca((int)
1509 1498 sizeof (Name_vector_rec));
1510 1499 }
1511 1500 }
1512 1501 if (append) {
1513 1502 source_p++;
1514 1503 }
1515 1504 macro_value = NULL;
1516 1505 source_p++;
1517 1506 distance = 0;
1518 1507 /* Skip whitespace to the start of the value */
1519 1508 macro_seen_in_string = false;
1520 1509 for (; 1; source_p++) {
1521 1510 switch (GET_CHAR()) {
1522 1511 case nul_char:
1523 1512 GET_NEXT_BLOCK(source);
1524 1513 source_p--;
1525 1514 if (source == NULL) {
1526 1515 GOTO_STATE(on_eoln_state);
1527 1516 }
1528 1517 break;
1529 1518 case backslash_char:
1530 1519 if (*++source_p == (int) nul_char) {
1531 1520 GET_NEXT_BLOCK(source);
1532 1521 if (source == NULL) {
1533 1522 GOTO_STATE(on_eoln_state);
1534 1523 }
1535 1524 }
1536 1525 if (*source_p != (int) newline_char) {
1537 1526 if (!macro_seen_in_string) {
1538 1527 macro_seen_in_string =
1539 1528 true;
1540 1529 INIT_STRING_FROM_STACK(name_string,
1541 1530 name_buffer);
1542 1531 }
1543 1532 append_char((int)
1544 1533 backslash_char,
1545 1534 &name_string);
1546 1535 append_char(*source_p,
1547 1536 &name_string);
1548 1537 string_start = source_p+1;
1549 1538 goto macro_value_start;
1550 1539 } else {
1551 1540 if (source->fd >= 0) {
1552 1541 line_number++;
1553 1542 }
1554 1543 }
1555 1544 break;
1556 1545 case newline_char:
1557 1546 case numbersign_char:
1558 1547 string_start = source_p;
1559 1548 goto macro_value_end;
1560 1549 case tab_char:
1561 1550 case space_char:
1562 1551 break;
1563 1552 default:
1564 1553 string_start = source_p;
1565 1554 goto macro_value_start;
1566 1555 }
1567 1556 }
1568 1557 macro_value_start:
1569 1558 /* Find the end of the value */
1570 1559 for (; 1; source_p++) {
1571 1560 if (distance != 0) {
1572 1561 *source_p = *(source_p + distance);
1573 1562 }
1574 1563 switch (GET_CHAR()) {
1575 1564 case nul_char:
1576 1565 if (!macro_seen_in_string) {
1577 1566 macro_seen_in_string = true;
1578 1567 INIT_STRING_FROM_STACK(name_string,
1579 1568 name_buffer);
1580 1569 }
1581 1570 append_string(string_start,
1582 1571 &name_string,
1583 1572 source_p - string_start);
1584 1573 GET_NEXT_BLOCK(source);
1585 1574 string_start = source_p;
1586 1575 source_p--;
1587 1576 if (source == NULL) {
1588 1577 GOTO_STATE(on_eoln_state);
1589 1578 }
1590 1579 break;
1591 1580 case backslash_char:
1592 1581 source_p++;
1593 1582 if (distance != 0) {
1594 1583 *source_p =
1595 1584 *(source_p + distance);
1596 1585 }
1597 1586 if (*source_p == (int) nul_char) {
1598 1587 if (!macro_seen_in_string) {
1599 1588 macro_seen_in_string =
1600 1589 true;
1601 1590 INIT_STRING_FROM_STACK(name_string,
1602 1591 name_buffer);
1603 1592 }
1604 1593
1605 1594 /* BID_1225561 */
1606 1595 *(source_p - 1) = (int) space_char;
1607 1596 append_string(string_start,
1608 1597 &name_string,
1609 1598 source_p -
1610 1599 string_start - 1);
1611 1600 GET_NEXT_BLOCK(source);
1612 1601 string_start = source_p;
1613 1602 if (source == NULL) {
1614 1603 GOTO_STATE(on_eoln_state);
1615 1604 }
1616 1605 if (distance != 0) {
1617 1606 *source_p =
1618 1607 *(source_p +
1619 1608 distance);
1620 1609 }
1621 1610 if (*source_p == (int) newline_char) {
1622 1611 append_char((int) space_char, &name_string);
1623 1612 } else {
1624 1613 append_char((int) backslash_char, &name_string);
1625 1614 }
1626 1615 /****************/
1627 1616 }
1628 1617 if (*source_p == (int) newline_char) {
1629 1618 source_p--;
1630 1619 line_number++;
1631 1620 distance++;
1632 1621 *source_p = (int) space_char;
1633 1622 while ((*(source_p +
1634 1623 distance + 1) ==
1635 1624 (int) tab_char) ||
1636 1625 (*(source_p +
1637 1626 distance + 1) ==
1638 1627 (int) space_char)) {
1639 1628 distance++;
1640 1629 }
1641 1630 }
1642 1631 break;
1643 1632 case newline_char:
1644 1633 case numbersign_char:
1645 1634 goto macro_value_end;
1646 1635 }
1647 1636 }
1648 1637 macro_value_end:
1649 1638 /* Complete the value in the string */
1650 1639 if (!macro_seen_in_string) {
1651 1640 macro_seen_in_string = true;
1652 1641 INIT_STRING_FROM_STACK(name_string,
1653 1642 name_buffer);
1654 1643 }
1655 1644 append_string(string_start,
1656 1645 &name_string,
1657 1646 source_p - string_start);
1658 1647 if (name_string.buffer.start != name_string.text.p) {
1659 1648 macro_value =
1660 1649 GETNAME(name_string.buffer.start,
1661 1650 FIND_LENGTH);
1662 1651 }
1663 1652 if (name_string.free_after_use) {
1664 1653 retmem(name_string.buffer.start);
1665 1654 }
1666 1655 for (; distance > 0; distance--) {
1667 1656 *source_p++ = (int) space_char;
1668 1657 }
1669 1658 GOTO_STATE(on_eoln_state);
1670 1659 }
1671 1660 }
1672 1661
1673 1662 /****************************************************************
1674 1663 * enter dependencies state
1675 1664 */
1676 1665 case enter_dependencies_state:
1677 1666 enter_dependencies_label:
1678 1667 /* Expects pointer on first non whitespace char after last dependency. (On */
1679 1668 /* next line.) We end up here after having read a "targets : dependencies" */
1680 1669 /* line. The state checks if there is a rule to read and if so dispatches */
1681 1670 /* to scan_command_state scan_command_state reads one rule line and the */
1682 1671 /* returns here */
1683 1672
1684 1673 /* First check if the first char on the next line is special */
1685 1674 switch (GET_CHAR()) {
1686 1675 case nul_char:
1687 1676 GET_NEXT_BLOCK(source);
1688 1677 if (source == NULL) {
1689 1678 break;
1690 1679 }
1691 1680 goto enter_dependencies_label;
1692 1681 case exclam_char:
1693 1682 /* The line should be evaluate before it is read */
1694 1683 macro_seen_in_string = false;
1695 1684 string_start = source_p + 1;
1696 1685 for (; 1; source_p++) {
1697 1686 switch (GET_CHAR()) {
1698 1687 case newline_char:
1699 1688 goto eoln_2;
1700 1689 case nul_char:
1701 1690 if (source->fd > 0) {
1702 1691 if (!macro_seen_in_string) {
1703 1692 macro_seen_in_string = true;
1704 1693 INIT_STRING_FROM_STACK(name_string,
1705 1694 name_buffer);
1706 1695 }
1707 1696 append_string(string_start,
1708 1697 &name_string,
1709 1698 source_p - string_start);
1710 1699 GET_NEXT_BLOCK(source);
1711 1700 string_start = source_p;
1712 1701 source_p--;
1713 1702 break;
1714 1703 }
1715 1704 eoln_2:
1716 1705 if (!macro_seen_in_string) {
1717 1706 INIT_STRING_FROM_STACK(name_string,
1718 1707 name_buffer);
1719 1708 }
1720 1709 append_string(string_start,
1721 1710 &name_string,
1722 1711 source_p - string_start);
1723 1712 extrap = (Source)
1724 1713 alloca((int) sizeof (Source_rec));
1725 1714 extrap->string.buffer.start = NULL;
1726 1715 extrap->inp_buf =
1727 1716 extrap->inp_buf_ptr =
1728 1717 extrap->inp_buf_end = NULL;
1729 1718 extrap->error_converting = false;
1730 1719 expand_value(GETNAME(name_string.buffer.start,
1731 1720 FIND_LENGTH),
1732 1721 &extrap->string,
1733 1722 false);
1734 1723 if (name_string.free_after_use) {
1735 1724 retmem(name_string.buffer.start);
1736 1725 }
1737 1726 UNCACHE_SOURCE();
1738 1727 extrap->string.text.p =
1739 1728 extrap->string.buffer.start;
1740 1729 extrap->fd = -1;
1741 1730 extrap->previous = source;
1742 1731 source = extrap;
1743 1732 CACHE_SOURCE(0);
1744 1733 goto enter_dependencies_label;
1745 1734 }
1746 1735 }
1747 1736 case dollar_char:
1748 1737 if (source->already_expanded) {
1749 1738 break;
1750 1739 }
1751 1740 source_p++;
1752 1741 UNCACHE_SOURCE();
1753 1742 {
1754 1743 Source t = (Source) alloca((int) sizeof (Source_rec));
1755 1744 source = push_macro_value(t,
1756 1745 buffer,
1757 1746 sizeof buffer,
1758 1747 source);
1759 1748 }
1760 1749 CACHE_SOURCE(0);
1761 1750 goto enter_dependencies_label;
1762 1751 case numbersign_char:
1763 1752 if (makefile_type != reading_makefile) {
1764 1753 source_p++;
1765 1754 GOTO_STATE(scan_command_state);
1766 1755 }
1767 1756 for (; 1; source_p++) {
1768 1757 switch (GET_CHAR()) {
1769 1758 case nul_char:
1770 1759 GET_NEXT_BLOCK_NOCHK(source);
1771 1760 if (source == NULL) {
1772 1761 GOTO_STATE(on_eoln_state);
1773 1762 }
1774 1763 if (source->error_converting) {
1775 1764 // Illegal byte sequence - skip its first byte
1776 1765 source->inp_buf_ptr++;
1777 1766 }
1778 1767 source_p--;
1779 1768 break;
1780 1769 case backslash_char:
1781 1770 if (*++source_p == (int) nul_char) {
1782 1771 GET_NEXT_BLOCK_NOCHK(source);
1783 1772 if (source == NULL) {
1784 1773 GOTO_STATE(on_eoln_state);
1785 1774 }
1786 1775 if (source->error_converting) {
1787 1776 // Illegal byte sequence - skip its first byte
1788 1777 source->inp_buf_ptr++;
1789 1778 source_p--;
1790 1779 break;
1791 1780 }
1792 1781 }
1793 1782 if(*source_p == (int) newline_char) {
1794 1783 if (source->fd >= 0) {
1795 1784 line_number++;
1796 1785 }
1797 1786 }
1798 1787 break;
1799 1788 case newline_char:
1800 1789 source_p++;
1801 1790 if (source->fd >= 0) {
1802 1791 line_number++;
1803 1792 }
1804 1793 goto enter_dependencies_label;
1805 1794 }
1806 1795 }
1807 1796
1808 1797 case tab_char:
1809 1798 GOTO_STATE(scan_command_state);
1810 1799 }
1811 1800
1812 1801 /* We read all the command lines for the target/dependency line. */
1813 1802 /* Enter the stuff */
1814 1803 enter_target_groups_and_dependencies( &target, &depes, command,
1815 1804 separator, target_group_seen);
1816 1805
1817 1806 goto start_new_line;
1818 1807
1819 1808 /****************************************************************
1820 1809 * scan command state
1821 1810 */
1822 1811 case scan_command_state:
1823 1812 /* We need to read one rule line. Do that and return to */
1824 1813 /* the enter dependencies state */
1825 1814 string_start = source_p;
1826 1815 macro_seen_in_string = false;
1827 1816 for (; 1; source_p++) {
1828 1817 switch (GET_CHAR()) {
1829 1818 case backslash_char:
1830 1819 if (!macro_seen_in_string) {
1831 1820 INIT_STRING_FROM_STACK(name_string,
1832 1821 name_buffer);
1833 1822 }
1834 1823 append_string(string_start,
1835 1824 &name_string,
1836 1825 source_p - string_start);
1837 1826 macro_seen_in_string = true;
1838 1827 if (*++source_p == (int) nul_char) {
1839 1828 GET_NEXT_BLOCK(source);
1840 1829 if (source == NULL) {
1841 1830 string_start = source_p;
1842 1831 goto command_newline;
1843 1832 }
1844 1833 }
1845 1834 append_char((int) backslash_char, &name_string);
1846 1835 append_char(*source_p, &name_string);
1847 1836 if (*source_p == (int) newline_char) {
1848 1837 if (source->fd >= 0) {
1849 1838 line_number++;
1850 1839 }
1851 1840 if (*++source_p == (int) nul_char) {
1852 1841 GET_NEXT_BLOCK(source);
1853 1842 if (source == NULL) {
1854 1843 string_start = source_p;
1855 1844 goto command_newline;
1856 1845 }
1857 1846 }
1858 1847 if (*source_p == (int) tab_char) {
1859 1848 source_p++;
1860 1849 }
1861 1850 } else {
1862 1851 if (*++source_p == (int) nul_char) {
1863 1852 GET_NEXT_BLOCK(source);
1864 1853 if (source == NULL) {
1865 1854 string_start = source_p;
1866 1855 goto command_newline;
1867 1856 }
1868 1857 }
1869 1858 }
1870 1859 string_start = source_p;
1871 1860 if ((*source_p == (int) newline_char) ||
1872 1861 (*source_p == (int) backslash_char) ||
1873 1862 (*source_p == (int) nul_char)) {
1874 1863 source_p--;
1875 1864 }
1876 1865 break;
1877 1866 case newline_char:
1878 1867 command_newline:
1879 1868 if ((string_start != source_p) ||
1880 1869 macro_seen_in_string) {
1881 1870 if (macro_seen_in_string) {
1882 1871 append_string(string_start,
1883 1872 &name_string,
1884 1873 source_p - string_start);
1885 1874 string_start =
1886 1875 name_string.buffer.start;
1887 1876 string_end = name_string.text.p;
1888 1877 } else {
1889 1878 string_end = source_p;
1890 1879 }
1891 1880 while ((*string_start != (int) newline_char) &&
1892 1881 iswspace(*string_start)){
1893 1882 string_start++;
1894 1883 }
1895 1884 if ((string_end > string_start) ||
1896 1885 (makefile_type == reading_statefile)) {
1897 1886 if (command_tail == NULL) {
1898 1887 command =
1899 1888 command_tail =
1900 1889 ALLOC(Cmd_line);
1901 1890 } else {
1902 1891 command_tail->next =
1903 1892 ALLOC(Cmd_line);
1904 1893 command_tail =
1905 1894 command_tail->next;
1906 1895 }
1907 1896 command_tail->next = NULL;
1908 1897 command_tail->make_refd = false;
1909 1898 command_tail->ignore_command_dependency = false;
1910 1899 command_tail->assign = false;
1911 1900 command_tail->ignore_error = false;
1912 1901 command_tail->silent = false;
1913 1902 command_tail->command_line =
1914 1903 GETNAME(string_start,
1915 1904 string_end - string_start);
1916 1905 if (macro_seen_in_string &&
1917 1906 name_string.free_after_use) {
1918 1907 retmem(name_string.
1919 1908 buffer.start);
1920 1909 }
1921 1910 }
1922 1911 }
1923 1912 do {
1924 1913 if ((source != NULL) && (source->fd >= 0)) {
1925 1914 line_number++;
1926 1915 }
1927 1916 if ((source != NULL) &&
1928 1917 (*++source_p == (int) nul_char)) {
1929 1918 GET_NEXT_BLOCK(source);
1930 1919 if (source == NULL) {
1931 1920 GOTO_STATE(on_eoln_state);
1932 1921 }
1933 1922 }
1934 1923 } while (*source_p == (int) newline_char);
1935 1924
1936 1925 GOTO_STATE(enter_dependencies_state);
1937 1926 case nul_char:
1938 1927 if (!macro_seen_in_string) {
1939 1928 INIT_STRING_FROM_STACK(name_string,
1940 1929 name_buffer);
1941 1930 }
1942 1931 append_string(string_start,
1943 1932 &name_string,
1944 1933 source_p - string_start);
1945 1934 macro_seen_in_string = true;
1946 1935 GET_NEXT_BLOCK(source);
1947 1936 string_start = source_p;
1948 1937 source_p--;
1949 1938 if (source == NULL) {
1950 1939 GOTO_STATE(enter_dependencies_state);
1951 1940 }
1952 1941 break;
1953 1942 }
1954 1943 }
1955 1944
1956 1945 /****************************************************************
1957 1946 * enter equal state
1958 1947 */
1959 1948 case enter_equal_state:
1960 1949 if (target.used != 1) {
1961 1950 GOTO_STATE(poorly_formed_macro_state);
1962 1951 }
1963 1952 enter_equal(target.names[0], macro_value, append);
1964 1953 goto start_new_line;
1965 1954
1966 1955 /****************************************************************
1967 1956 * enter conditional state
1968 1957 */
1969 1958 case enter_conditional_state:
1970 1959 if (depes.used != 1) {
1971 1960 GOTO_STATE(poorly_formed_macro_state);
1972 1961 }
1973 1962 for (nvp = ⌖ nvp != NULL; nvp = nvp->next) {
1974 1963 for (i = 0; i < nvp->used; i++) {
1975 1964 enter_conditional(nvp->names[i],
1976 1965 depes.names[0],
1977 1966 macro_value,
1978 1967 append);
1979 1968 }
1980 1969 }
1981 1970 goto start_new_line;
1982 1971
1983 1972 /****************************************************************
1984 1973 * Error states
1985 1974 */
1986 1975 case illegal_bytes_state:
1987 1976 fatal_reader(catgets(catd, 1, 340, "Invalid byte sequence"));
1988 1977 case illegal_eoln_state:
1989 1978 if (line_number > 1) {
1990 1979 if (line_started_with_space == (line_number - 1)) {
1991 1980 line_number--;
1992 1981 fatal_reader(catgets(catd, 1, 90, "Unexpected end of line seen\n\t*** missing separator (did you mean TAB instead of 8 spaces?)"));
1993 1982 }
1994 1983 }
1995 1984 fatal_reader(catgets(catd, 1, 87, "Unexpected end of line seen"));
1996 1985 case poorly_formed_macro_state:
1997 1986 fatal_reader(catgets(catd, 1, 88, "Badly formed macro assignment"));
1998 1987 case exit_state:
1999 1988 return;
2000 1989 default:
2001 1990 fatal_reader(catgets(catd, 1, 89, "Internal error. Unknown reader state"));
2002 1991 }
2003 1992 }
2004 1993
2005 1994 /*
2006 1995 * push_macro_value(bp, buffer, size, source)
2007 1996 *
2008 1997 * Macro and function that evaluates one macro
2009 1998 * and makes the reader read from the value of it
2010 1999 *
2011 2000 * Return value:
2012 2001 * The source block to read the macro from
2013 2002 *
2014 2003 * Parameters:
2015 2004 * bp The new source block to fill in
2016 2005 * buffer Buffer to read from
2017 2006 * size size of the buffer
2018 2007 * source The old source block
2019 2008 *
2020 2009 * Global variables used:
2021 2010 */
2022 2011 static Source
2023 2012 push_macro_value(register Source bp, register wchar_t *buffer, int size, register Source source)
2024 2013 {
2025 2014 bp->string.buffer.start = bp->string.text.p = buffer;
2026 2015 bp->string.text.end = NULL;
2027 2016 bp->string.buffer.end = buffer + (size/SIZEOFWCHAR_T);
2028 2017 bp->string.free_after_use = false;
2029 2018 bp->inp_buf =
2030 2019 bp->inp_buf_ptr =
2031 2020 bp->inp_buf_end = NULL;
2032 2021 bp->error_converting = false;
2033 2022 expand_macro(source, &bp->string, (wchar_t *) NULL, false);
2034 2023 bp->string.text.p = bp->string.buffer.start;
2035 2024
2036 2025 /* 4209588: 'make' doesn't understand a macro with whitespaces in the head as target.
2037 2026 * strip whitespace from the begining of the macro value
2038 2027 */
2039 2028 while (iswspace(*bp->string.text.p)) {
2040 2029 bp->string.text.p++;
2041 2030 }
2042 2031
2043 2032 bp->fd = -1;
2044 2033 bp->already_expanded = true;
2045 2034 bp->previous = source;
2046 2035 return bp;
2047 2036 }
2048 2037
2049 2038 /*
2050 2039 * enter_target_groups_and_dependencies(target, depes, command, separator,
2051 2040 * target_group_seen)
2052 2041 *
2053 2042 * Parameters:
2054 2043 * target Structure that shows the target(s) on the line
2055 2044 * we are currently parsing. This can looks like
2056 2045 * target1 .. targetN : dependencies
2057 2046 * commands
2058 2047 * or
2059 2048 * target1 + .. + targetN : dependencies
2060 2049 * commands
2061 2050 * depes Dependencies
2062 2051 * command Points to the command(s) to be executed for
2063 2052 * this target.
2064 2053 * separator : or :: or :=
2065 2054 * target_group_seen Set if we have target1 + .. + targetN
2066 2055 *
2067 2056 *
2068 2057 * After reading the command lines for a target, this routine
2069 2058 * is called to setup the dependencies and the commands for it.
2070 2059 * If the target is a % pattern or part of a target group, then
2071 2060 * the appropriate routines are called.
2072 2061 */
2073 2062
2074 2063 void
2075 2064 enter_target_groups_and_dependencies(Name_vector target, Name_vector depes, Cmd_line command, Separator separator, Boolean target_group_seen)
2076 2065 {
2077 2066 int i;
2078 2067 Boolean reset= true;
2079 2068 Chain target_group_member;
2080 2069 Percent percent_ptr;
2081 2070
2082 2071 for (; target != NULL; target = target->next) {
2083 2072 for (i = 0; i < target->used; i++) {
2084 2073 if (target->names[i] != NULL) {
2085 2074 if (target_group_seen) {
2086 2075 target_group_member =
2087 2076 find_target_groups(target, i, reset);
2088 2077 if(target_group_member == NULL) {
2089 2078 fatal_reader(catgets(catd, 1, 328, "Unexpected '+' on dependency line"));
2090 2079 }
2091 2080 }
2092 2081 reset = false;
2093 2082
2094 2083 /* If we saw it in the makefile it must be
2095 2084 * a file */
2096 2085 target->names[i]->stat.is_file = true;
2097 2086 /* Make sure that we use dependencies
2098 2087 * entered for makefiles */
2099 2088 target->names[i]->state = build_dont_know;
2100 2089
2101 2090 /* If the target is special we delegate
2102 2091 * the processing */
2103 2092 if (target->names[i]->special_reader
2104 2093 != no_special) {
2105 2094 special_reader(target->names[i],
2106 2095 depes,
2107 2096 command);
2108 2097 }
2109 2098 /* Check if this is a "a%b : x%y" type rule */
2110 2099 else if (target->names[i]->percent) {
2111 2100 percent_ptr =
2112 2101 enter_percent(target->names[i],
2113 2102 target->target_group[i],
2114 2103 depes, command);
2115 2104 if (target_group_seen) {
2116 2105 target_group_member->percent_member =
2117 2106 percent_ptr;
2118 2107 }
2119 2108 } else if (target->names[i]->dollar) {
2120 2109 enter_dyntarget(target->names[i]);
2121 2110 enter_dependencies
2122 2111 (target->names[i],
2123 2112 target->target_group[i],
2124 2113 depes,
2125 2114 command,
2126 2115 separator);
2127 2116 } else {
2128 2117 if (target_group_seen) {
2129 2118 target_group_member->percent_member =
2130 2119 NULL;
2131 2120 }
2132 2121
2133 2122 enter_dependencies
2134 2123 (target->names[i],
2135 2124 target->target_group[i],
2136 2125 depes,
2137 2126 command,
2138 2127 separator);
2139 2128 }
2140 2129 }
2141 2130 }
2142 2131 }
2143 2132 }
2144 2133
2145 2134
↓ open down ↓ |
1721 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX