xref: /titanic_52/usr/src/cmd/make/bin/depvar.cc (revision 7fd791373689a6af05e27efec3b1ab556e02aa23)
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 <libintl.h>
30 
31 #include <mk/defs.h>
32 #include <mksh/misc.h>		/* getmem() */
33 
34 /*
35  * This file deals with "Dependency Variables".
36  * The "-V var" command line option is used to indicate
37  * that var is a dependency variable.  Used in conjunction with
38  * the -P option the user is asking if the named variables affect
39  * the dependencies of the given target.
40  */
41 
42 struct _Depvar {
43 	Name		name;		/* Name of variable */
44 	struct _Depvar	*next;		/* Linked list */
45 	Boolean		cmdline;	/* Macro defined on the cmdline? */
46 };
47 
48 typedef	struct _Depvar	*Depvar;
49 
50 static	Depvar		depvar_list;
51 static	Depvar		*bpatch = &depvar_list;
52 static	Boolean		variant_deps;
53 
54 /*
55  * Add a name to the list.
56  */
57 
58 void
59 depvar_add_to_list(Name name, Boolean cmdline)
60 {
61 	Depvar		dv;
62 
63 	dv = ALLOC(Depvar);
64 	dv->name = name;
65 	dv->next = NULL;
66 	dv->cmdline = cmdline;
67 	*bpatch = dv;
68 	bpatch = &dv->next;
69 }
70 
71 /*
72  * The macro `name' has been used in either the left-hand or
73  * right-hand side of a dependency.  See if it is in the
74  * list.  Two things are looked for.  Names given as args
75  * to the -V list are checked so as to set the same/differ
76  * output for the -P option.  Names given as macro=value
77  * command-line args are checked and, if found, an NSE
78  * warning is produced.
79  */
80 void
81 depvar_dep_macro_used(Name name)
82 {
83 	Depvar		dv;
84 
85 	for (dv = depvar_list; dv != NULL; dv = dv->next) {
86 		if (name == dv->name) {
87 			variant_deps = true;
88 			break;
89 		}
90 	}
91 }
92 
93 
94 /*
95  * Print the results.  If any of the Dependency Variables
96  * affected the dependencies then the dependencies potentially
97  * differ because of these variables.
98  */
99 void
100 depvar_print_results(void)
101 {
102 	if (variant_deps) {
103 		printf(gettext("differ\n"));
104 	} else {
105 		printf(gettext("same\n"));
106 	}
107 }
108 
109