10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER START
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
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 *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * or http://www.opensolaris.org/os/licensing.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * See the License for the specific language governing permissions
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and limitations under the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
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 *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER END
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Use is subject to license terms.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * implicit.c
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Handle suffix and percent rules
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Included files
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <mk/defs.h>
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <mksh/macro.h> /* expand_value() */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <mksh/misc.h> /* retmem() */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <libintl.h>
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Defined macros
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * typedefs & structs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Static variables
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic wchar_t WIDE_NULL[1] = {(wchar_t) nul_char};
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * File table of contents
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweextern Doname find_suffix_rule(Name target, Name target_body, Name target_suffix, Property *command, Boolean rechecking);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweextern Doname find_ar_suffix_rule(register Name target, Name true_target, Property *command, Boolean rechecking);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweextern Doname find_double_suffix_rule(register Name target, Property *command, Boolean rechecking);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweextern void build_suffix_list(register Name target_suffix);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweextern Doname find_percent_rule(register Name target, Property *command, Boolean rechecking);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void create_target_group_and_dependencies_list(Name target, Percent pat_rule, String percent);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic Boolean match_found_with_pattern(Name target, Percent pat_rule, String percent, wchar_t *percent_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void construct_string_from_pattern(Percent pat_rule, String percent, String result);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic Boolean dependency_exists(Name target, Property line);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweextern Property maybe_append_prop(Name, Property_id);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweextern void add_target_to_chain(Name target, Chain * query);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * find_suffix_rule(target, target_body, target_suffix, command, rechecking)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Does the lookup for single and double suffix rules.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * It calls build_suffix_list() to build the list of possible suffixes
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * for the given target.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * It then scans the list to find the first possible source file that
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * exists. This is done by concatenating the body of the target name
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * (target name less target suffix) and the source suffix and checking
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * if the resulting file exists.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Indicates if search failed or not
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target The target we need a rule for
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target_body The target name without the suffix
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target_suffix The suffix of the target
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * command Pointer to slot to deposit cmd in if found
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * rechecking true if we are rechecking target which depends
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * on conditional macro and keep_state is set
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * debug_level Indicates how much tracing to do
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * recursion_level Used for tracing
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic Boolean actual_doname = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* /tolik/
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * fix bug 1247448: Suffix Rules failed when combine with Pattern Matching Rules.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * When make attemps to apply % rule it didn't look for a single suffix rule because
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * if "doname" is called from "find_percent_rule" argument "implicit" is set to true
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and find_suffix_rule was not called. I've commented the checking of "implicit"
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * in "doname" and make got infinite recursion for SVR4 tilde rules.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Usage of "we_are_in_tilde" is intended to avoid this recursion.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic Boolean we_are_in_tilde = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard LoweDoname
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowefind_suffix_rule(Name target, Name target_body, Name target_suffix, Property *command, Boolean rechecking)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe static wchar_t static_string_buf_3M [ 3 * MAXPATHLEN ];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name true_target = target;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t *sourcename = (wchar_t*)static_string_buf_3M;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register wchar_t *put_suffix;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Property source_suffix;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Name source;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Doname result;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Property line;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe extern Boolean tilde_rule;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean name_found = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean posix_tilde_attempt = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int src_len = MAXPATHLEN + strlen(target_body->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * To avoid infinite recursion
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(we_are_in_tilde) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe we_are_in_tilde = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return(build_dont_know);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If the target is a constructed one for a "::" target,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * we need to consider that.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (target->has_target_prop) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target = get_prop(target->prop,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_prop)->body.target.target;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf("%*sfind_suffix_rule(%s,%s,%s)\n",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_body->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_suffix->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (command != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((true_target->suffix_scan_done == true) && (*command == NULL)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_ok;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->suffix_scan_done = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Enter all names from the directory where the target lives as
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * files that makes sense.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This will make finding the synthesized source possible.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe read_directory_of_file(target_body);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Cache the suffixes for this target suffix if not done. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!target_suffix->has_read_suffixes) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe build_suffix_list(target_suffix);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Preload the sourcename vector with the head of the target name. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (src_len >= sizeof(static_string_buf_3M)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sourcename = ALLOC_WC(src_len);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) mbstowcs(sourcename,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_body->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (int) target_body->hash.length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe put_suffix = sourcename + target_body->hash.length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Scan the suffix list for the target if one exists. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (target_suffix->has_suffixes) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweposix_attempts:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (source_suffix = get_prop(target_suffix->prop,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix_prop);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source_suffix != NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source_suffix = get_prop(source_suffix->next,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix_prop)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Build the synthesized source name. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) mbstowcs(put_suffix,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source_suffix->body.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix.suffix->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (int) source_suffix->body.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix.suffix->hash.length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe put_suffix[source_suffix->body.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix.suffix->hash.length] =
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (int) nul_char;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe WCSTOMBS(mbs_buffer, sourcename);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext("%*sTrying %s\n"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe mbs_buffer);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source = getname_fn(sourcename, FIND_LENGTH, false, &name_found);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If the source file is not registered as
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * a file, this source suffix did not match.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(vpath_defined && !posix && !svr4) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) exists(source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!source->stat.is_file) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!(posix|svr4))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!name_found) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe free_name(source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* following code will ensure that the corresponding
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ** tilde rules are executed when corresponding s. file
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ** exists in the current directory. Though the current
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ** target ends with a ~ character, there wont be any
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ** any file in the current directory with that suffix
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ** as it's fictitious. Even if it exists, it'll
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ** execute all the rules for the ~ target.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(source->string_mb[source->hash.length - 1] == '~' &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ( svr4 || posix_tilde_attempt ) )
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe char *p, *np;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe char *tmpbuf;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe tmpbuf = getmem(source->hash.length + 8);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* + 8 to add "s." or "SCCS/s." */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe memset(tmpbuf,0,source->hash.length + 8);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->string_mb[source->hash.length - 1] = '\0';
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(p = (char *) memchr((char *)source->string_mb,'/',source->hash.length))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while(1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(np = (char *) memchr((char *)p+1,'/',source->hash.length - (p - source->string_mb))) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe p = np;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {break;}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* copy everything including '/' */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe strncpy(tmpbuf, source->string_mb, p - source->string_mb + 1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe strcat(tmpbuf, "s.");
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe strcat(tmpbuf, p+1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe retmem((wchar_t *) source->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->string_mb = tmpbuf;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe strcpy(tmpbuf, "s.");
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe strcat(tmpbuf, source->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe retmem((wchar_t *) source->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->string_mb = tmpbuf;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->hash.length = strlen(source->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(exists(source) == file_doesnt_exist)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe tilde_rule = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe we_are_in_tilde = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!name_found) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe free_name(source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(posix && posix_tilde_attempt) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(exists(source) == file_doesnt_exist) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!name_found) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe free_name(source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (command != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!name_found) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe store_name(source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The source file is a file.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Make sure it is up to date.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (dependency_exists(source,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe get_prop(target->prop,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line_prop))) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result = (Doname) source->state;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#if 0 /* with_squiggle sends false, which is buggy. : djay */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result = doname(source,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (Boolean) source_suffix->body.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix.suffix->with_squiggle,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#else
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result = doname(source,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#endif
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result = target_can_be_built(source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (result == build_ok) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return result;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!name_found) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe free_name(source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe switch (result) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case build_dont_know:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If we still can't build the source,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * this rule is not a match,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * try the next one.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (source->stat.time == file_doesnt_exist) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!name_found) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe free_name(source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case build_running:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!name_found) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe store_name(source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->suffix_scan_done = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line = maybe_append_prop(target, line_prop);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe enter_dependency(line, source, false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.target = true_target;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_running;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case build_ok:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!name_found) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe store_name(source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case build_failed:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!name_found) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe store_name(source);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (sourcename != static_string_buf_3M) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe retmem(sourcename);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_failed;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe WCSTOMBS(mbs_buffer, sourcename);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext("%*sFound %s\n"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe mbs_buffer);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (source->depends_on_conditional) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target->depends_on_conditional = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Since it is possible that the same target is built several times during
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the make run, we have to patch the target with all information we found
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * here. Thus, the target will have an explicit rule the next time around.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line = maybe_append_prop(target, line_prop);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (*command == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *command = line;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((source->stat.time > (*command)->body.line.dependency_time) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (debug_level > 1)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext("%*sDate(%s)=%s Date-dependencies(%s)=%s\n"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe time_to_string(source->
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe stat.time),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe time_to_string((*command)->
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe body.line.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe dependency_time));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Determine if this new dependency made the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target out of date.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (*command)->body.line.dependency_time =
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe MAX((*command)->body.line.dependency_time,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->stat.time);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean out_of_date;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (target->is_member) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe out_of_date = (Boolean) OUT_OF_DATE_SEC(target->stat.time,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (*command)->body.line.dependency_time);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe out_of_date = (Boolean) OUT_OF_DATE(target->stat.time,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (*command)->body.line.dependency_time);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (build_unconditional || out_of_date) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!rechecking) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.is_out_of_date = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext("%*sBuilding %s using suffix rule for %s%s because it is out of date relative to %s\n"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source_suffix->body.suffix.suffix->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_suffix->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Add the implicit rule as the target's explicit
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * rule if none actually given, and register
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * dependency.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The time checking above really should be
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * conditional on actual use of implicit rule
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * as well.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.sccs_command = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (line->body.line.command_template == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.command_template =
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source_suffix->body.suffix.command_template;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe enter_dependency(line, source, false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.target = true_target;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Also make sure the rule is built with
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * $* and $< bound properly.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.star = target_body;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(svr4|posix) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe char * p;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe char tstr[256];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe extern Boolean dollarless_flag;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe extern Name dollarless_value;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(tilde_rule) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe MBSTOWCS(wcs_buffer, source->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe dollarless_value = GETNAME(wcs_buffer,FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe dollarless_flag = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.less = source;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.percent = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe add_target_to_chain(source, &(line->body.line.query));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (sourcename != static_string_buf_3M) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe retmem(sourcename);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_ok;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(posix && posix_tilde_attempt) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe posix_tilde_attempt = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe goto posix_attempts;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((command != NULL) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ((*command) != NULL) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ((*command)->body.line.star == NULL)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (*command)->body.line.star = target_body;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (sourcename != static_string_buf_3M) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe retmem(sourcename);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Return here in case no rule matched the target */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_dont_know;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * find_ar_suffix_rule(target, true_target, command, rechecking)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Scans the .SUFFIXES list and tries
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * to find a suffix on it that matches the tail of the target member name.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If it finds a matching suffix it calls find_suffix_rule() to find
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * a rule for the target using the suffix ".a".
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Indicates if search failed or not
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target The target we need a rule for
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * true_target The proper name
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * command Pointer to slot where we stuff cmd, if found
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * rechecking true if we are rechecking target which depends
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * on conditional macro and keep_state is set
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * debug_level Indicates how much tracing to do
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * dot_a The Name ".a", compared against
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * recursion_level Used for tracing
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * suffixes List of suffixes used for scan (from .SUFFIXES)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard LoweDoname
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowefind_ar_suffix_rule(register Name target, Name true_target, Property *command, Boolean rechecking)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t *target_end;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Dependency suffix;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register int suffix_length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Property line;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name body;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe static Name dot_a;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Wstring targ_string(true_target);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Wstring suf_string;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (dot_a == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe MBSTOWCS(wcs_buffer, ".a");
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe dot_a = GETNAME(wcs_buffer, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_end = targ_string.get_string() + true_target->hash.length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * We compare the tail of the target name with the suffixes
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * from .SUFFIXES.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf("%*sfind_ar_suffix_rule(%s)\n",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Scan the .SUFFIXES list to see if the target matches any of
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * those suffixes.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (suffix = suffixes; suffix != NULL; suffix = suffix->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Compare one suffix. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix_length = suffix->name->hash.length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suf_string.init(suffix->name);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!IS_WEQUALN(suf_string.get_string(),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_end - suffix_length,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix_length)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe goto not_this_one;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The target tail matched a suffix from the .SUFFIXES list.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Now check for a rule to match.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target->suffix_scan_done = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe body = GETNAME(targ_string.get_string(),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (int)(true_target->hash.length -
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix_length));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe we_are_in_tilde = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe switch (find_suffix_rule(target,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe body,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe dot_a,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe command,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rechecking)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case build_ok:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line = get_prop(target->prop, line_prop);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.star = body;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_ok;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case build_running:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_running;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If no rule was found, we try the next suffix to see
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * if it matches the target tail, and so on.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Go here if the suffix did not match the target tail.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe not_this_one:;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_dont_know;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * find_double_suffix_rule(target, command, rechecking)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Scans the .SUFFIXES list and tries
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * to find a suffix on it that matches the tail of the target name.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If it finds a matching suffix it calls find_suffix_rule() to find
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * a rule for the target.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Indicates if scan failed or not
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target Target we need a rule for
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * command Pointer to slot where we stuff cmd, if found
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * rechecking true if we are rechecking target which depends
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * on conditional macro and keep_state is set
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * debug_level Indicates how much tracing to do
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * recursion_level Used for tracing
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * suffixes List of suffixes used for scan (from .SUFFIXES)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard LoweDoname
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowefind_double_suffix_rule(register Name target, Property *command, Boolean rechecking)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name true_target = target;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name target_body;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register wchar_t *target_end;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Dependency suffix;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register int suffix_length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean scanned_once = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean name_found = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Wstring targ_string;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Wstring suf_string;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If the target is a constructed one for a "::" target,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * we need to consider that.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (target->has_target_prop) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target = get_prop(target->prop,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_prop)->body.target.target;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe targ_string.init(true_target);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * We compare the tail of the target name with the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * suffixes from .SUFFIXES.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_end = targ_string.get_string() + true_target->hash.length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf("%*sfind_double_suffix_rule(%s)\n",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Scan the .SUFFIXES list to see if the target matches
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * any of those suffixes.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (suffix = suffixes; suffix != NULL; suffix = suffix->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target->suffix_scan_done = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->suffix_scan_done = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Compare one suffix. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix_length = suffix->name->hash.length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suf_string.init(suffix->name);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Check the lengths, or else RTC will report rua. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (true_target->hash.length < suffix_length) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe goto not_this_one;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else if (!IS_WEQUALN(suf_string.get_string(),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (target_end - suffix_length),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix_length)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe goto not_this_one;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The target tail matched a suffix from the .SUFFIXES list.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Now check for a rule to match.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe we_are_in_tilde = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_body = GETNAME(
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe targ_string.get_string(),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (int)(true_target->hash.length - suffix_length)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe );
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe switch (find_suffix_rule(target,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_body,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix->name,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe command,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rechecking)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case build_ok:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_ok;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case build_running:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_running;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (true_target->suffix_scan_done == true) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe scanned_once = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If no rule was found, we try the next suffix to see
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * if it matches the target tail. And so on.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Go here if the suffix did not match the target tail.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe not_this_one:;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (scanned_once)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->suffix_scan_done = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_dont_know;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * build_suffix_list(target_suffix)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Scans the .SUFFIXES list and figures out
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * which suffixes this target can be derived from.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The target itself is not know here, we just know the suffix of the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target. For each suffix on the list the target can be derived iff
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * a rule exists for the name "<suffix-on-list><target-suffix>".
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * A list of all possible building suffixes is built, with the rule for
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * each, and tacked to the target suffix nameblock.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target_suffix The suffix we build a match list for
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * debug_level Indicates how much tracing to do
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * recursion_level Used for tracing
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * suffixes List of suffixes used for scan (from .SUFFIXES)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * working_on_targets Indicates that this is a real target
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowevoid
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowebuild_suffix_list(register Name target_suffix)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Dependency source_suffix;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t rule_name[MAXPATHLEN];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Property line;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Property suffix;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name rule;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If this is before default.mk has been read we just return to try */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* again later */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((suffixes == NULL) || !working_on_targets) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf("%*sbuild_suffix_list(%s) ",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_suffix->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Mark the target suffix saying we cashed its list */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_suffix->has_read_suffixes = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Scan the .SUFFIXES list */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (source_suffix = suffixes;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source_suffix != NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source_suffix = source_suffix->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Build the name "<suffix-on-list><target-suffix>".
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * (a popular one would be ".c.o").
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) mbstowcs(rule_name,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source_suffix->name->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (int) source_suffix->name->hash.length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) mbstowcs(rule_name + source_suffix->name->hash.length,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_suffix->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (int) target_suffix->hash.length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Check if that name has a rule. If not, it cannot match
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * any implicit rule scan and is ignored.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The GETNAME() call only checks for presence, it will not
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * enter the name if it is not defined.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (((rule = getname_fn(rule_name,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (int) (source_suffix->name->
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe hash.length +
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_suffix->hash.length),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true)) != NULL) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ((line = get_prop(rule->prop, line_prop)) != NULL)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf("%s ", rule->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This makes it possible to quickly determine if
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * it will pay to look for a suffix property.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_suffix->has_suffixes = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Add the suffix property to the target suffix
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and save the rule with it.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * All information the implicit rule scanner need
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * is saved in the suffix property.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix = append_prop(target_suffix, suffix_prop);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix->body.suffix.suffix = source_suffix->name;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix->body.suffix.command_template =
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.command_template;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf("\n");
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * find_percent_rule(target, command, rechecking)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Tries to find a rule from the list of wildcard matched rules.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * It scans the list attempting to match the target.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * For each target match it checks if the corresponding source exists.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If it does the match is returned.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The percent_list is built at makefile read time.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Each percent rule get one entry on the list.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Indicates if the scan failed or not
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target The target we need a rule for
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * command Pointer to slot where we stuff cmd, if found
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * rechecking true if we are rechecking target which depends
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * on conditional macro and keep_state is set
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * debug_level Indicates how much tracing to do
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * percent_list List of all percent rules
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * recursion_level Used for tracing
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * empty_name
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard LoweDoname
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowefind_percent_rule(register Name target, Property *command, Boolean rechecking)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Percent pat_rule, pat_depe;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Name depe_to_check;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Dependency depe;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Property line;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe String_rec string;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t string_buf[STRING_BUFFER_LENGTH];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe String_rec percent;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t percent_buf[STRING_BUFFER_LENGTH];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name true_target = target;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name less;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean nonpattern_less;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean dep_name_found = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Doname result = build_dont_know;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Percent rule_candidate = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean rule_maybe_ok;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean is_pattern;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If the target is constructed for a "::" target we consider that */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (target->has_target_prop) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target = get_prop(target->prop,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target_prop)->body.target.target;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (target->has_long_member_name) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target = get_prop(target->prop,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe long_member_name_prop)->body.long_member_name.member_name;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext("%*sLooking for %% rule for %s\n"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (pat_rule = percent_list;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule != NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule = pat_rule->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Avoid infinite recursion when expanding patterns */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (pat_rule->being_expanded == true) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Mark this pat_rule as "maybe ok". If no % rule is found
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe make will use this rule. The following algorithm is used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe 1) make scans all pattern rules in order to find the rule
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe where ALL dependencies, including nonpattern ones, exist or
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe can be built (GNU behaviour). If such rule is found make
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe will apply it.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe 2) During this check make also remembers the first pattern rule
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe where all PATTERN dependencies can be build (no matter what
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe happens with nonpattern dependencies).
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe 3) If no rule satisfying 1) is found, make will apply the rule
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe remembered in 2) if there is one.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rule_maybe_ok = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* used to track first percent dependency */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe less = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe nonpattern_less = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* check whether pattern matches.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if it matches, percent string will contain matched percent part of pattern */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!match_found_with_pattern(true_target, pat_rule, &percent, percent_buf)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (pat_rule->dependencies != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (pat_depe = pat_rule->dependencies;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_depe != NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_depe = pat_depe->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* checking result for dependency */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result = build_dont_know;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe dep_name_found = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (pat_depe->name->percent) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe is_pattern = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* build dependency name */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(string, string_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe construct_string_from_pattern(pat_depe, &percent, &string);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe_to_check = getname_fn(string.buffer.start,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe FIND_LENGTH,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe false,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe &dep_name_found
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe );
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((less == NULL) || nonpattern_less) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe less = depe_to_check;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe nonpattern_less = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* nonpattern dependency */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe is_pattern = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe_to_check = pat_depe->name;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(depe_to_check->dollar) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(string, string_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value(depe_to_check, &string, false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe_to_check = getname_fn(string.buffer.start,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe FIND_LENGTH,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe false,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe &dep_name_found
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe );
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (less == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe less = depe_to_check;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (depe_to_check == empty_name) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result = build_ok;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext("%*sTrying %s\n"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe_to_check->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule->being_expanded = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* suppress message output */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int save_debug_level = debug_level;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe debug_level = 0;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* check whether dependency can be built */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (dependency_exists(depe_to_check,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe get_prop(target->prop,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line_prop)))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result = (Doname) depe_to_check->state;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(actual_doname) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result = doname(depe_to_check, true, true);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result = target_can_be_built(depe_to_check);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!dep_name_found) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(result != build_ok && result != build_running) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe free_name(depe_to_check);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe store_name(depe_to_check);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(result != build_ok && is_pattern) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rule_maybe_ok = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* restore debug_level */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe debug_level = save_debug_level;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (pat_depe->name->percent) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (string.free_after_use) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe retmem(string.buffer.start);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* make can't figure out how to make this dependency */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (result != build_ok && result != build_running) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule->being_expanded = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result = build_ok;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* this pattern rule is the needed one since all dependencies could be built */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (result == build_ok || result == build_running) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Make does not know how to build some of dependencies from this rule.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe But if all "pattern" dependencies can be built, we remember this rule
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe as a candidate for the case if no other pattern rule found.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(rule_maybe_ok && rule_candidate == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rule_candidate = pat_rule;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* if no pattern matching rule was found, use the remembered candidate
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe or return build_dont_know if there is no candidate.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (result != build_ok && result != build_running) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(rule_candidate) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule = rule_candidate;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_dont_know;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* if we are performing only check whether dependency could be built with existing rules,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return success */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (command == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(pat_rule != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule->being_expanded = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return result;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext("%*sMatched %s:"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (pat_depe = pat_rule->dependencies;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_depe != NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_depe = pat_depe->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (pat_depe->name->percent) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(string, string_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe construct_string_from_pattern(pat_depe, &percent, &string);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe_to_check = GETNAME(string.buffer.start, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe_to_check = pat_depe->name;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(depe_to_check->dollar) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(string, string_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value(depe_to_check, &string, false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe_to_check = GETNAME(string.buffer.start, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (depe_to_check != empty_name) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(" %s", depe_to_check->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext(" from: %s:"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule->name->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (pat_depe = pat_rule->dependencies;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_depe != NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_depe = pat_depe->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(" %s", pat_depe->name->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf("\n");
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (true_target->colons == no_colon) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->colons = one_colon;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* create deppendency list and target group from matched pattern rule */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe create_target_group_and_dependencies_list(target, pat_rule, &percent);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* save command */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line = get_prop(target->prop, line_prop);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *command = line;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* free query chain if one exist */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while(line->body.line.query != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Chain to_free = line->body.line.query;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.query = line->body.line.query->next;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe retmem_mb((char *) to_free);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (line->body.line.dependencies != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* build all collected dependencies */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (depe = line->body.line.dependencies;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe != NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe = depe->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe actual_doname = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result = doname_check(depe->name, true, true, depe->automatic);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe actual_doname = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (result == build_failed) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule->being_expanded = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_failed;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (result == build_running) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule->being_expanded = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return build_running;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((depe->name->stat.time > line->body.line.dependency_time) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (debug_level > 1)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext("%*sDate(%s)=%s Date-dependencies(%s)=%s\n"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe->name->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe time_to_string(depe->name->stat.time),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe time_to_string(line->body.line.dependency_time));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.dependency_time =
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe MAX(line->body.line.dependency_time, depe->name->stat.time);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* determine whether this dependency made target out of date */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean out_of_date;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (target->is_member || depe->name->is_member) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe out_of_date = (Boolean) OUT_OF_DATE_SEC(target->stat.time, depe->name->stat.time);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe out_of_date = (Boolean) OUT_OF_DATE(target->stat.time, depe->name->stat.time);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (build_unconditional || out_of_date) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!rechecking) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.is_out_of_date = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe add_target_to_chain(depe->name, &(line->body.line.query));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext("%*sBuilding %s using pattern rule %s:"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule->name->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (pat_depe = pat_rule->dependencies;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_depe != NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_depe = pat_depe->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(" %s", pat_depe->name->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext(" because it is out of date relative to %s\n"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe->name->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((true_target->stat.time <= file_doesnt_exist) ||
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (true_target->stat.time < line->body.line.dependency_time)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(!rechecking) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.is_out_of_date = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (debug_level > 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) printf(gettext("%*sBuilding %s using pattern rule %s: "),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe recursion_level,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe true_target->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule->name->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (target->stat.time > file_doesnt_exist) ?
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe gettext("because it is out of date") :
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe gettext("because it does not exist"));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* enter explicit rule from percent rule */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name lmn_target = true_target;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (true_target->has_long_member_name) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe lmn_target = get_prop(true_target->prop, long_member_name_prop)->body.long_member_name.member_name;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.sccs_command = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.target = true_target;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.command_template = pat_rule->command_template;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.star = GETNAME(percent.buffer.start, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.less = less;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (lmn_target->parenleft) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Wstring lmn_string(lmn_target);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t *left = (wchar_t *) wcschr(lmn_string.get_string(), (int) parenleft_char);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t *right = (wchar_t *) wcschr(lmn_string.get_string(), (int) parenright_char);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((left == NULL) || (right == NULL)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.percent = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.percent = GETNAME(left + 1, right - left - 1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.percent = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule->being_expanded = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return result;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * match_found_with_pattern
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * ( target, pat_rule, percent, percent_buf)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * matches "target->string" with a % pattern.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If pattern contains a MACRO definition, it's expanded first.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * true if a match was found
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target The target we're trying to match
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * pattern
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * percent record that contains "percent_buf" below
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * percent_buf This is where the patched % part of pattern is stored
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic Boolean
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowematch_found_with_pattern(Name target, Percent pat_rule, String percent, wchar_t *percent_buf) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe String_rec string;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t string_buf[STRING_BUFFER_LENGTH];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* construct prefix string and check whether prefix matches */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name prefix = pat_rule->patterns[0];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int prefix_length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Wstring targ_string(target);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Wstring pref_string(prefix);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Wstring suf_string;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (prefix->dollar) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(string, string_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value(prefix, &string, false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe prefix_length = string.text.p - string.buffer.start;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((string.buffer.start[0] == (int) period_char) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (string.buffer.start[1] == (int) slash_char)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe string.buffer.start += 2;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe prefix_length -= 2;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!targ_string.equaln(string.buffer.start, prefix_length)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe prefix_length = prefix->hash.length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!targ_string.equaln(&pref_string, prefix_length)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* do the same with pattern suffix */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name suffix = pat_rule->patterns[pat_rule->patterns_total - 1];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suf_string.init(suffix);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int suffix_length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (suffix->dollar) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(string, string_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value(suffix, &string, false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix_length = string.text.p - string.buffer.start;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(suffix_length > target->hash.length) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!targ_string.equal(string.buffer.start, target->hash.length - suffix_length)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe suffix_length = (int) suffix->hash.length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(suffix_length > target->hash.length) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!targ_string.equal(&suf_string, target->hash.length - suffix_length)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean match_found = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int percent_length = target->hash.length - prefix_length - suffix_length;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while (!match_found && (percent_length >= 0)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* init result string */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(string, string_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* init percent string */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe percent->buffer.start = percent_buf;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe percent->text.p = percent_buf;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe percent->text.end = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe percent->free_after_use = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe percent->buffer.end = percent_buf + STRING_BUFFER_LENGTH;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* construct percent and result strings */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe targ_string.append_to_str(percent, prefix_length, percent_length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe construct_string_from_pattern(pat_rule, percent, &string);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* check for match */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (targ_string.equal(string.buffer.start, 0)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe match_found = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe percent_length--;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* result */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return match_found;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * create_target_group_and_dependencies_list
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * (target, pat_rule, percent)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * constructs dependency list and a target group from pattern.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If we have the lines
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * %/%.a + %/%.b + C%/CC%.c: yyy %.d bb%/BB%.e
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * commands
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and we have matched the pattern xx/xx.a with %/%.a, then we
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * construct a target group that looks like this:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * xx/xx.a + xx/xx.b + Cxx/CCxx.c: dependencies
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and construct dependency list that looks like this:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * yyy xx.d bbxx/BBxx.e + already existed dependencies
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * none
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target The target we are building, in the previous
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * example, this is xx/xx.a
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * pat_rule the % pattern that matched "target", here %/%.a
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * percent string containing matched % part. In the example=xx.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * empty_name
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowecreate_target_group_and_dependencies_list(Name target, Percent pat_rule, String percent) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe String_rec string;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t string_buf[STRING_BUFFER_LENGTH];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Percent pat_depe;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name depe;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Property line = maybe_append_prop(target, line_prop);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Chain new_target_group = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Chain *new_target_group_tail = &new_target_group;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Chain group_member;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* create and append dependencies from rule */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (pat_depe = pat_rule->dependencies; pat_depe != NULL; pat_depe = pat_depe->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (pat_depe->name->percent) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(string, string_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe construct_string_from_pattern(pat_depe, percent, &string);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe = GETNAME(string.buffer.start, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (depe != empty_name) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe enter_dependency(line, depe, false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe = pat_depe->name;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(depe->dollar) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(string, string_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value(depe, &string, false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depe = GETNAME(string.buffer.start, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe enter_dependency(line, depe, false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* if matched pattern is a group member, create new target group */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (group_member = pat_rule->target_group; group_member != NULL; group_member = group_member->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name new_target = group_member->name;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (group_member->name->percent) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(string, string_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe construct_string_from_pattern(group_member->percent_member, percent, &string);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe new_target = GETNAME(string.buffer.start, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (new_target == empty_name) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* check for duplicates */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Chain tgm;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (tgm = new_target_group; tgm != NULL; tgm = tgm->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (new_target == tgm->name) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (tgm != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* insert it into the targets list */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (*new_target_group_tail) = ALLOC(Chain);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (*new_target_group_tail)->name = new_target;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (*new_target_group_tail)->next = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe new_target_group_tail = &(*new_target_group_tail)->next;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* now we gathered all dependencies and created target group */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line->body.line.target_group = new_target_group;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* update properties for group members */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (group_member = new_target_group; group_member != NULL; group_member = group_member->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (group_member->name != target) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe group_member->name->prop = target->prop;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe group_member->name->conditional_cnt = target->conditional_cnt;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * construct_string_from_pattern
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * (pat_rule, percent, result)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * after pattern matched a target this routine is called to construct targets and dependencies
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * strings from this matched pattern rule and a string (percent) with substitutes % sign in pattern.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * none
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * pat_rule matched pattern rule
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * percent string containing matched % sign part.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * result holds the result of string construction.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweconstruct_string_from_pattern(Percent pat_rule, String percent, String result) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (int i = 0; i < pat_rule->patterns_total; i++) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (pat_rule->patterns[i]->dollar) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe expand_value(pat_rule->patterns[i],
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_string(pat_rule->patterns[i]->string_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pat_rule->patterns[i]->hash.length);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (i < pat_rule->patterns_total - 1) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_string(percent->buffer.start,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe percent->text.p - percent->buffer.start);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((result->buffer.start[0] == (int) period_char) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (result->buffer.start[1] == (int) slash_char)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe result->buffer.start += 2;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * dependency_exists(target, line)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Returns true if the target exists in the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * dependency list of the line.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * True if target is on dependency list
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target Target we scan for
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * line We get the dependency list from here
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic Boolean
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowedependency_exists(Name target, Property line)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Dependency dp;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (line == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (dp = line->body.line.dependencies; dp != NULL; dp = dp->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (dp->name == target) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowevoid
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweadd_target_to_chain(Name target, Chain * query)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (target->is_member && (get_prop(target->prop, member_prop) != NULL)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe target = get_prop(target->prop, member_prop)->body.member.member;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Chain *query_tail;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (query_tail = query; *query_tail != NULL; query_tail = &(*query_tail)->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((*query_tail)->name == target) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *query_tail = ALLOC(Chain);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (*query_tail)->name = target;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (*query_tail)->next = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe