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