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 2003 Sun Microsystems, Inc. All rights reserved.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Use is subject to license terms.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * rep.c
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This file handles the .nse_depinfo file
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Included files
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <mk/defs.h>
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <mksh/misc.h> /* retmem() */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <vroot/report.h> /* NSE_DEPINFO */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Static variables
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic Recursive_make recursive_list;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic Recursive_make *bpatch = &recursive_list;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic Boolean changed;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * File table of contents
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * report_recursive_init()
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Read the .nse_depinfo file and make a list of all the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * .RECURSIVE entries.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Static variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * bpatch Points to slot where next cell should be added
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * recursive_name The Name ".RECURSIVE", compared against
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowevoid
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowereport_recursive_init(void)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe char *search_dir;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe char nse_depinfo[MAXPATHLEN];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe FILE *fp;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int line_size, line_index;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t *line;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t *bigger_line;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t *colon;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t *dollar;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Recursive_make rp;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This routine can be called more than once, don't do
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * anything after the first time.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (depinfo_already_read) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depinfo_already_read = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe search_dir = getenv("NSE_DEP");
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (search_dir == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) sprintf(nse_depinfo, "%s/%s", search_dir, NSE_DEPINFO);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fp = fopen(nse_depinfo, "r");
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (fp == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line_size = MAXPATHLEN;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line_index = line_size - 1;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line = ALLOC_WC(line_size);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Wstring rns(recursive_name);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t * wcb = rns.get_string();
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while (fgetws(line, line_size, fp) != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while (wcslen(line) == line_index) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (line[wcslen(line) - 1] == '\n') {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bigger_line = ALLOC_WC(2 * line_size);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wcscpy(bigger_line, line);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe retmem(line);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line = bigger_line;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (fgetws(&line[line_index], line_size, fp) == NULL)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line_index = 2 * line_index;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line_size = 2 * line_size;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe colon = (wchar_t *) wcschr(line, (int) colon_char);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (colon == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe dollar = (wchar_t *) wcschr(line, (int) dollar_char);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line[wcslen(line) - 1] = (int) nul_char;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (IS_WEQUALN(&colon[2], wcb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (int) recursive_name->hash.length)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If this entry is an old entry, ignore it
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe MBSTOWCS(wcs_buffer, DEPINFO_FMT_VERSION);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (dollar == NULL ||
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe !IS_WEQUALN(wcs_buffer, (dollar+1) - VER_LEN, VER_LEN)){
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp = ALLOC(Recursive_make);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) memset((char *) rp, 0, sizeof (Recursive_make_rec));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * set conditional_macro_string if string is present
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->oldline = (wchar_t *) wcsdup(line);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ( dollar != NULL ){
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->cond_macrostring =
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (wchar_t *) wcsdup(dollar - VER_LEN + 1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * get target name into recursive struct
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *colon = (int) nul_char;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->target = (wchar_t *) wcsdup(line);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *bpatch = rp;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bpatch = &rp->next;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) fclose(fp);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * report_recursive_dep(target, line)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Report a target as recursive.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * line Dependency line reported
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Static variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * bpatch Points to slot where next cell should be added
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * changed Written if report set changed
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowevoid
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowereport_recursive_dep(Name target, wchar_t *line)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Recursive_make rp;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t rec_buf[STRING_BUFFER_LENGTH];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe String_rec string;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(string, rec_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe cond_macros_into_string(target, &string);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * find an applicable recursive entry, if there isn't one, create it
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp = find_recursive_target(target);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (rp == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp = ALLOC(Recursive_make);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) memset((char *) rp, 0, sizeof (Recursive_make_rec));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t * wcb = get_wstring(target->string_mb); // XXX Tolik: needs retmem
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->target = wcb;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->newline = (wchar_t *) wcsdup(line);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->cond_macrostring = (wchar_t *) wcsdup(rec_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *bpatch = rp;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bpatch = &rp->next;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe changed = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((rp->oldline != NULL) && !IS_WEQUAL(rp->oldline, line)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->newline = (wchar_t *) wcsdup(line);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe changed = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->removed = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * find_recursive_target(target)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Search the list for a given target.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The target cell
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target The target we need
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * top_level_target more info used to determinde the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target we need
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Static variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * recursive_list The list of targets
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard LoweRecursive_make
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowefind_recursive_target(Name target)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Recursive_make rp;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe String_rec string;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t rec_buf[STRING_BUFFER_LENGTH];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(string, rec_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe cond_macros_into_string(target, &string);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Wstring tstr(target);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t * wcb = tstr.get_string();
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (rp = recursive_list; rp != NULL; rp = rp->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If this entry has already been removed, ignore it.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (rp->removed)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If this target, and the target on the list are the same
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and if one of them contains conditional macro info, while
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the other doesn't, remove this entry from the list of
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * recursive entries. This can only happen if the Makefile
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * has changed to no longer contain conditional macros.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (IS_WEQUAL(rp->target, wcb)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (rp->cond_macrostring[VER_LEN] == '\0' &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe string.buffer.start[VER_LEN] != '\0'){
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->removed = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else if (rp->cond_macrostring[VER_LEN] != '\0' &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe string.buffer.start[VER_LEN] == '\0'){
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->removed = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If this is not a VERS2 entry, only need to match
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the target name. toptarg information from VERS1 entries
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * are ignored.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe MBSTOWCS(wcs_buffer, DEPINFO_FMT_VERSION);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (IS_WEQUALN(wcs_buffer, string.buffer.start, VER_LEN)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (IS_WEQUAL(rp->cond_macrostring,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe string.buffer.start) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe IS_WEQUAL(rp->target, wcb)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return rp;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (IS_WEQUAL(rp->target, wcb)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return rp;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * remove_recursive_dep(target, top_level_target)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Mark a target as no longer recursive.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * target The target we want to remove
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * top_level_target target we want to remove must be built from
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the same top level target
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Static variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * changed Written if report set changed
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowevoid
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweremove_recursive_dep(Name target)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Recursive_make rp;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp = find_recursive_target(target);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ( rp != NULL ) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->removed = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe changed = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(rp->target) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe retmem(rp->target);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->target = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(rp->newline) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe retmem(rp->newline);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->newline = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(rp->oldline) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe retmem(rp->oldline);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->oldline = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if(rp->cond_macrostring) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe retmem(rp->cond_macrostring);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rp->cond_macrostring = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* gather_recursive_deps()
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Create or update list of recursive targets.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowevoid
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowegather_recursive_deps(void)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Name_set::iterator np, e;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe String_rec rec;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe wchar_t rec_buf[STRING_BUFFER_LENGTH];
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe register Property lines;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Boolean has_recursive;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Dependency dp;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe report_recursive_init();
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Go thru all targets and dump recursive dependencies */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (np = hashtab.begin(), e = hashtab.end(); np != e; np++) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (np->has_recursive_dependency){
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe has_recursive = false;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * start .RECURSIVE line with target:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe INIT_STRING_FROM_STACK(rec, rec_buf);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe APPEND_NAME(np, &rec, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_char((int) colon_char, &rec);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_char((int) space_char, &rec);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (lines = get_prop(np->prop,recursive_prop);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe lines != NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe lines = get_prop(lines->next, recursive_prop)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * if entry is already in depinfo
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * file or entry was not built, ignore it
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (lines->body.recursive.in_depinfo)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!lines->body.recursive.has_built)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe has_recursive = true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe lines->body.recursive.in_depinfo=true;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Write the remainder of the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * .RECURSIVE line
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe APPEND_NAME(recursive_name, &rec,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_char((int) space_char, &rec);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe APPEND_NAME(lines->body.recursive.directory,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe &rec, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_char((int) space_char, &rec);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe APPEND_NAME(lines->body.recursive.target,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe &rec, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_char((int) space_char, &rec);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Complete list of makefiles used */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (dp = lines->body.recursive.makefiles;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe dp != NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe dp = dp->next) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe APPEND_NAME(dp->name, &rec, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe append_char((int) space_char, &rec);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * dump list of conditional targets,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and report recursive entry, if needed
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe cond_macros_into_string(np, &rec);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (has_recursive){
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe report_recursive_dep(np, rec.buffer.start);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else if ( np->has_built ) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe remove_recursive_dep(np);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe