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