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 /*
27 * Included files
28 */
29 #include <mk/defs.h>
30 #include <mksh/misc.h> /* getmem() */
31
32 /*
33 * This file deals with "Dependency Variables".
34 * The "-V var" command line option is used to indicate
35 * that var is a dependency variable. Used in conjunction with
36 * the -P option the user is asking if the named variables affect
37 * the dependencies of the given target.
38 */
39
40 struct _Depvar {
41 Name name; /* Name of variable */
42 struct _Depvar *next; /* Linked list */
43 Boolean cmdline; /* Macro defined on the cmdline? */
44 };
45
46 typedef struct _Depvar *Depvar;
47
48 static Depvar depvar_list;
49 static Depvar *bpatch = &depvar_list;
50 static Boolean variant_deps;
51
52 /*
53 * Add a name to the list.
54 */
55
56 void
57 depvar_add_to_list(Name name, Boolean cmdline)
58 {
59 Depvar dv;
60
61 #ifdef SUNOS4_AND_AFTER
62 dv = ALLOC(Depvar);
63 #else
64 dv = (Depvar) Malloc(sizeof(struct _Depvar));
65 #endif
66 dv->name = name;
67 dv->next = NULL;
68 dv->cmdline = cmdline;
69 *bpatch = dv;
70 bpatch = &dv->next;
71 }
72
73 /*
74 * The macro `name' has been used in either the left-hand or
75 * right-hand side of a dependency. See if it is in the
76 * list. Two things are looked for. Names given as args
77 * to the -V list are checked so as to set the same/differ
78 * output for the -P option. Names given as macro=value
79 * command-line args are checked and, if found, an NSE
80 * warning is produced.
81 */
82 void
83 depvar_dep_macro_used(Name name)
84 {
85 Depvar dv;
86
87 for (dv = depvar_list; dv != NULL; dv = dv->next) {
88 if (name == dv->name) {
89 #ifdef NSE
90 #ifdef SUNOS4_AND_AFTER
91 if (dv->cmdline) {
92 #else
93 if (is_true(dv->cmdline)) {
94 #endif
95 nse_dep_cmdmacro(dv->name->string);
96 }
97 #endif
98 variant_deps = true;
99 break;
100 }
101 }
102 }
103
104 #ifdef NSE
105 /*
106 * The macro `name' has been used in either the argument
107 * to a cd before a recursive make. See if it was
108 * defined on the command-line and, if so, complain.
109 */
110 void
111 depvar_rule_macro_used(Name name)
112 {
113 Depvar dv;
114
115 for (dv = depvar_list; dv != NULL; dv = dv->next) {
116 if (name == dv->name) {
117 #ifdef SUNOS4_AND_AFTER
118 if (dv->cmdline) {
119 #else
120 if (is_true(dv->cmdline)) {
121 #endif
122 nse_rule_cmdmacro(dv->name->string);
123 }
124 break;
125 }
126 }
127 }
128 #endif
129
130 /*
131 * Print the results. If any of the Dependency Variables
132 * affected the dependencies then the dependencies potentially
133 * differ because of these variables.
134 */
135 void
136 depvar_print_results(void)
137 {
138 if (variant_deps) {
139 printf(catgets(catd, 1, 234, "differ\n"));
140 } else {
141 printf(catgets(catd, 1, 235, "same\n"));
142 }
143 }
144