1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 1995 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 /* 26 * @(#)depvar.cc 1.14 06/12/12 27 */ 28 29 #pragma ident "@(#)depvar.cc 1.14 06/12/12" 30 31 /* 32 * Included files 33 */ 34 #include <mk/defs.h> 35 #include <mksh/misc.h> /* getmem() */ 36 37 /* 38 * This file deals with "Dependency Variables". 39 * The "-V var" command line option is used to indicate 40 * that var is a dependency variable. Used in conjunction with 41 * the -P option the user is asking if the named variables affect 42 * the dependencies of the given target. 43 */ 44 45 struct _Depvar { 46 Name name; /* Name of variable */ 47 struct _Depvar *next; /* Linked list */ 48 Boolean cmdline; /* Macro defined on the cmdline? */ 49 }; 50 51 typedef struct _Depvar *Depvar; 52 53 static Depvar depvar_list; 54 static Depvar *bpatch = &depvar_list; 55 static Boolean variant_deps; 56 57 /* 58 * Add a name to the list. 59 */ 60 61 void 62 depvar_add_to_list(Name name, Boolean cmdline) 63 { 64 Depvar dv; 65 66 #ifdef SUNOS4_AND_AFTER 67 dv = ALLOC(Depvar); 68 #else 69 dv = (Depvar) Malloc(sizeof(struct _Depvar)); 70 #endif 71 dv->name = name; 72 dv->next = NULL; 73 dv->cmdline = cmdline; 74 *bpatch = dv; 75 bpatch = &dv->next; 76 } 77 78 /* 79 * The macro `name' has been used in either the left-hand or 80 * right-hand side of a dependency. See if it is in the 81 * list. Two things are looked for. Names given as args 82 * to the -V list are checked so as to set the same/differ 83 * output for the -P option. Names given as macro=value 84 * command-line args are checked and, if found, an NSE 85 * warning is produced. 86 */ 87 void 88 depvar_dep_macro_used(Name name) 89 { 90 Depvar dv; 91 92 for (dv = depvar_list; dv != NULL; dv = dv->next) { 93 if (name == dv->name) { 94 #ifdef NSE 95 #ifdef SUNOS4_AND_AFTER 96 if (dv->cmdline) { 97 #else 98 if (is_true(dv->cmdline)) { 99 #endif 100 nse_dep_cmdmacro(dv->name->string); 101 } 102 #endif 103 variant_deps = true; 104 break; 105 } 106 } 107 } 108 109 #ifdef NSE 110 /* 111 * The macro `name' has been used in either the argument 112 * to a cd before a recursive make. See if it was 113 * defined on the command-line and, if so, complain. 114 */ 115 void 116 depvar_rule_macro_used(Name name) 117 { 118 Depvar dv; 119 120 for (dv = depvar_list; dv != NULL; dv = dv->next) { 121 if (name == dv->name) { 122 #ifdef SUNOS4_AND_AFTER 123 if (dv->cmdline) { 124 #else 125 if (is_true(dv->cmdline)) { 126 #endif 127 nse_rule_cmdmacro(dv->name->string); 128 } 129 break; 130 } 131 } 132 } 133 #endif 134 135 /* 136 * Print the results. If any of the Dependency Variables 137 * affected the dependencies then the dependencies potentially 138 * differ because of these variables. 139 */ 140 void 141 depvar_print_results(void) 142 { 143 if (variant_deps) { 144 printf(catgets(catd, 1, 234, "differ\n")); 145 } else { 146 printf(catgets(catd, 1, 235, "same\n")); 147 } 148 } 149