10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER START
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The contents of this file are subject to the terms of the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Common Development and Distribution License (the "License").
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You may not use this file except in compliance with the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * See the License for the specific language governing permissions
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and limitations under the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * When distributing Covered Code, include this CDDL HEADER in each
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If applicable, add the following below this CDDL HEADER, with the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * fields enclosed by brackets "[]" replaced with your own identifying
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * information: Portions Copyright [yyyy] [name of copyright owner]
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER END
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Use is subject to license terms.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This file contains the makefile reader.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Included files
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <mksh/macro.h> /* expand_value(), expand_macro() */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <mksh/read.h> /* get_next_block_fn() */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * typedefs & structs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Static variables
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic int line_started_with_space=0; // Used to diagnose spaces instead of tabs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * File table of contents
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void parse_makefile(register Name true_makefile_name, register Source source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic Source push_macro_value(register Source bp, register wchar_t *buffer, int size, register Source source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweextern void enter_target_groups_and_dependencies(Name_vector target, Name_vector depes, Cmd_line command, Separator separator, Boolean target_group_seen);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweextern Name normalize_name(register wchar_t *name_string, register int length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * read_simple_file(makefile_name, chase_path, doname_it,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * complain, must_exist, report_file, lock_makefile)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Make the makefile and setup to read it. Actually read it if it is stdio
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * false if the read failed
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * makefile_name Name of the file to read
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * chase_path Use the makefile path when opening file
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * doname_it Call doname() to build the file first
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * complain Print message if doname/open fails
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * must_exist Generate fatal if file is missing
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * report_file Report file when running -P
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * lock_makefile Lock the makefile when reading
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Static variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * do_not_exec_rule Is -n on?
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * file_being_read Set to the name of the new file
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * line_number The number of the current makefile line
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * makefiles_used A list of all makefiles used, appended to
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweread_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)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Property makefile = maybe_append_prop(makefile_name,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register int n;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t *previous_file_being_read = file_being_read;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t * wcb = get_wstring(makefile_name->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal(gettext("Too many nested include statements"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (makefile->body.makefile.contents != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((makefile->body.makefile.contents == NULL) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // As regularly installed
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // Tools build
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (doname(makefile_name, true, false) == build_dont_know) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Try normalized filename */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe string_start=get_wstring(makefile_name->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (string_end=string_start+1; *string_end != L'\0'; string_end++);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe normalized_makefile_name=normalize_name(string_start, string_end - string_start);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((strcmp(makefile_name->string_mb, normalized_makefile_name->string_mb) == 0) ||
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (doname(normalized_makefile_name, true, false) == build_dont_know)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (n == 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Commented out: retmem_mb(normalized_makefile_name->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * We have to return this memory, but it seems to trigger a bug
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * in dmake or in Sun C++ 5.7 compiler (it works ok if this code
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * is compiled using Sun C++ 5.6).
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // retmem_mb(normalized_makefile_name->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Lock the file for read, but not when -n. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe make_state_lockfile = getmem(strlen(make_state->string_mb) + strlen(".lock") + 1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (makefile->body.makefile.contents == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (doname(makefile_name, true, false) == build_failed)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // Before calling exists() make sure that we have the right timestamp
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (exists(makefile_name) == file_doesnt_exist) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(make_state_locked && (make_state_lockfile != NULL)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * These values are the size and bytes of
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the MULTI-BYTE makefile.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->fd = open_vroot(makefile_name->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ALLOC_WC((int) (makefile_name->stat.size + 2));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->string.text.end = source->string.text.p;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->string.text.p + makefile_name->stat.size;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Do we ever reach here? */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->string.text.p + makefile->body.makefile.size;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe makefile_name = GETNAME(wcs_buffer, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Memory to read standard in, then convert it
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * to wide char strings.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe file_being_read = (wchar_t *) wcsdup(wcs_buffer);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (n < 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal(gettext("Error reading standard input: %s"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Now, convert the sequence of multibyte chars into
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * a sequence of corresponding wide character codes.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->string.text.p = ALLOC_WC(num_mb_chars + 1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((int) num_wc_chars >= 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext(">>>>>>>>>>>>>>>> Reading makefile %s\n"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext(">>>>>>>>>>>>>>>> End of makefile %s\n"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Unlock .make.state. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * parse_makefile(true_makefile_name, source)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Strings are read from Sources.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * When macros are found, their values are represented by a
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Source that is pushed on a stack. At end of string
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * (that is returned from GET_CHAR() as 0), the block is popped.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * true_makefile_name The name of makefile we are parsing
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * source The source block to read from
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * do_not_exec_rule Is -n on?
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * line_number The number of the current makefile line
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * makefile_type What kind of makefile are we reading?
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * empty_name The Name ""
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweparse_makefile(register Name true_makefile_name, register Source source)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe char mb_buffer[MB_LEN_MAX];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean save_do_not_exec_rule = do_not_exec_rule;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Move some values from their struct to register declared locals */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Read whitespace on old line. Leave pointer on first char on
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * next line.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (WCTOMB(mb_buffer, GET_CHAR());
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source_p++, WCTOMB(mb_buffer, GET_CHAR()))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe switch (mb_buffer[0]) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (char_number=0; 1; source_p++,char_number++) switch (GET_CHAR()) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* End of this string. Pop it and return to the previous one */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Go back to the top of this loop */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Go back to the top of this loop since the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * new line does not start with a regular char.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* We found the first proper char on the new line */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Whitespace. Just keep going in this loop */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Comment. Skip over it */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // Illegal byte sequence - skip its first byte
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Comments can be continued */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // Illegal byte sequence - skip its first byte
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * After we skip the comment we go to
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the end of line handler since end of
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * line terminates comments.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Macro reference */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If we are reading from the expansion of a
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * macro we already expanded everything enough.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Expand the value and push the Source on the stack of
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * things being read.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Source t = (Source) alloca((int) sizeof (Source_rec));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* We found the first proper char on the new line */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * We found the first normal char (one that starts an identifier)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * on the newline.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Inspect that first char to see if it maybe is special anyway */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Just in case */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Evaluate the line before it is read */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Stuff the line in a string so we can eval it. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Eval the macro */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* And push the value */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* We now have a line we can start reading */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Check if this is an include command */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((IS_WEQUALN(source_p, include_space, 8)) ||
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Yes, this is an include.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Skip spaces to get to the filename.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Find the end of the filename */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Strip "./" from the head of the name */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* if include file name is surrounded by double quotes */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((name_start[0] == (int) doublequote_char) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (name_start[name_length - 1] == (int) doublequote_char)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* if name does not begin with a slash char */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(include_name, include_buffer);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t *slash = wcsrchr(include_name.buffer.start, (int) slash_char);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe name_length = include_name.text.p - name_start;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Even when we run -n we want to create makefiles */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe makefile_name = GETNAME(name_start, name_length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Read the file */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Read of include file `%s' failed"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Check if the word include was split across 8K boundary. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe tmp_bytes_left_in_string = source->string.text.end - source_p;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Reset the status in preparation for the new line */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (nvp = ⌖ nvp != NULL; nvp = nvp->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (nvp = &depes; nvp != NULL; nvp = nvp->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* The state machine starts here */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/****************************************************************
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Scan name state
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Scan an identifier. We skip over chars until we find a break char */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* First skip white space. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* We found the end of the line. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Do postprocessing or return error */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Continuation */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Whitespace is skipped */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Comment. Skip over it */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // Illegal byte sequence - skip its first byte
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // Illegal byte sequence - skip its first byte
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Macro reference. Expand and push value */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Source t = (Source) alloca((int) sizeof (Source_rec));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* End of white space */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* First proper identifier character */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Save what we have seen so far of the identifier */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Get more text to read */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Unmatched `(' on line"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Unmatched `{' on line"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Enter name */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Do postprocessing or return error */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Check if this is a quoting backslash */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Unexpected comment seen"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Save the identifier so far */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Eval and push the macro */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Unmatched `)' on line"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Unmatched `}' on line"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Fall into */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/** POSIX **/
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/** END POSIX **/
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* End of the target list. We now start reading */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* dependencies or a conditional assignment */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Extra `:', `::', or `:=' on dependency line"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Enter the last target */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Check if it is ":" "::" or ":=" */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe switch (*++source_p) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* End of reading names. Start reading the rule */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Unexpected command seen"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Enter the last dependency */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Make sure to enter a rule even if the is */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* no text here */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ** following code drops the target separator plus char if it starts
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* We found "+=" construct */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* "+" is not a break char. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Ignore it if it is part of an identifier */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Make sure the "+" is followed by a "=" */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe switch (*++source_p) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Must be a separator on rules"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* The "+" just starts a regular name. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Start reading that name */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Fall into */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* We found macro assignment. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Check if it is legal and if it is appending */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Reader must special check for "MACRO:sh=" */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* notation */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (GETNAME(name_string.buffer.start,FIND_LENGTH) == sh_name))) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (GETNAME(name_string.buffer.start,FIND_LENGTH) == shell_name))) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Macro assignment on dependency line"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Enter the macro name */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Skip whitespace to the start of the value */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Find the end of the value */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* BID_1225561 */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_char((int) backslash_char, &name_string);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/****************/
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Complete the value in the string */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (name_string.buffer.start != name_string.text.p) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/****************************************************************
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * enter dependencies state
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* Expects pointer on first non whitespace char after last dependency. (On */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* next line.) We end up here after having read a "targets : dependencies" */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* line. The state checks if there is a rule to read and if so dispatches */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* to scan_command_state scan_command_state reads one rule line and the */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* returns here */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* First check if the first char on the next line is special */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* The line should be evaluate before it is read */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Source t = (Source) alloca((int) sizeof (Source_rec));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // Illegal byte sequence - skip its first byte
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // Illegal byte sequence - skip its first byte
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* We read all the command lines for the target/dependency line. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Enter the stuff */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe enter_target_groups_and_dependencies( &target, &depes, command,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/****************************************************************
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * scan command state
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* We need to read one rule line. Do that and return to */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* the enter dependencies state */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_char((int) backslash_char, &name_string);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while ((*string_start != (int) newline_char) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe command_tail->ignore_command_dependency = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/****************************************************************
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * enter equal state
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe enter_equal(target.names[0], macro_value, append);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/****************************************************************
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * enter conditional state
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (nvp = ⌖ nvp != NULL; nvp = nvp->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/****************************************************************
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Error states
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Invalid byte sequence"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (line_started_with_space == (line_number - 1)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Unexpected end of line seen\n\t*** missing separator (did you mean TAB instead of 8 spaces?)"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Unexpected end of line seen"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Badly formed macro assignment"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Internal error. Unknown reader state"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * push_macro_value(bp, buffer, size, source)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Macro and function that evaluates one macro
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and makes the reader read from the value of it
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The source block to read the macro from
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * bp The new source block to fill in
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * buffer Buffer to read from
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * size size of the buffer
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * source The old source block
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowepush_macro_value(register Source bp, register wchar_t *buffer, int size, register Source source)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bp->string.buffer.start = bp->string.text.p = buffer;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bp->string.buffer.end = buffer + (size/SIZEOFWCHAR_T);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_macro(source, &bp->string, (wchar_t *) NULL, false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* 4209588: 'make' doesn't understand a macro with whitespaces in the head as target.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * strip whitespace from the begining of the macro value
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * enter_target_groups_and_dependencies(target, depes, command, separator,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target_group_seen)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target Structure that shows the target(s) on the line
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * we are currently parsing. This can looks like
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target1 .. targetN : dependencies
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target1 + .. + targetN : dependencies
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * depes Dependencies
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * command Points to the command(s) to be executed for
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * this target.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * separator : or :: or :=
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target_group_seen Set if we have target1 + .. + targetN
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * After reading the command lines for a target, this routine
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * is called to setup the dependencies and the commands for it.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If the target is a % pattern or part of a target group, then
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the appropriate routines are called.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweenter_target_groups_and_dependencies(Name_vector target, Name_vector depes, Cmd_line command, Separator separator, Boolean target_group_seen)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (; target != NULL; target = target->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_reader(gettext("Unexpected '+' on dependency line"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If we saw it in the makefile it must be
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Make sure that we use dependencies
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * entered for makefiles */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If the target is special we delegate
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the processing */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Check if this is a "a%b : x%y" type rule */