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