VirtualBox

source: kBuild/vendor/gnumake/2008-10-28/variable.h

Last change on this file was 1989, checked in by bird, 16 years ago

Load gnumake-2008-10-28-CVS into vendor/gnumake/current.

  • Property svn:eol-style set to native
File size: 8.7 KB
Line 
1/* Definitions for using variables in GNU Make.
2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
4Foundation, Inc.
5This file is part of GNU Make.
6
7GNU Make is free software; you can redistribute it and/or modify it under the
8terms of the GNU General Public License as published by the Free Software
9Foundation; either version 3 of the License, or (at your option) any later
10version.
11
12GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License along with
17this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#include "hash.h"
20
21/* Codes in a variable definition saying where the definition came from.
22 Increasing numeric values signify less-overridable definitions. */
23enum variable_origin
24 {
25 o_default, /* Variable from the default set. */
26 o_env, /* Variable from environment. */
27 o_file, /* Variable given in a makefile. */
28 o_env_override, /* Variable from environment, if -e. */
29 o_command, /* Variable given by user. */
30 o_override, /* Variable from an `override' directive. */
31 o_automatic, /* Automatic variable -- cannot be set. */
32 o_invalid /* Core dump time. */
33 };
34
35enum variable_flavor
36 {
37 f_bogus, /* Bogus (error) */
38 f_simple, /* Simple definition (:=) */
39 f_recursive, /* Recursive definition (=) */
40 f_append, /* Appending definition (+=) */
41 f_conditional /* Conditional definition (?=) */
42 };
43
44/* Structure that represents one variable definition.
45 Each bucket of the hash table is a chain of these,
46 chained through `next'. */
47
48#define EXP_COUNT_BITS 15 /* This gets all the bitfields into 32 bits */
49#define EXP_COUNT_MAX ((1<<EXP_COUNT_BITS)-1)
50
51struct variable
52 {
53 char *name; /* Variable name. */
54 int length; /* strlen (name) */
55 char *value; /* Variable value. */
56 struct floc fileinfo; /* Where the variable was defined. */
57 unsigned int recursive:1; /* Gets recursively re-evaluated. */
58 unsigned int append:1; /* Nonzero if an appending target-specific
59 variable. */
60 unsigned int conditional:1; /* Nonzero if set with a ?=. */
61 unsigned int per_target:1; /* Nonzero if a target-specific variable. */
62 unsigned int special:1; /* Nonzero if this is a special variable. */
63 unsigned int exportable:1; /* Nonzero if the variable _could_ be
64 exported. */
65 unsigned int expanding:1; /* Nonzero if currently being expanded. */
66 unsigned int exp_count:EXP_COUNT_BITS;
67 /* If >1, allow this many self-referential
68 expansions. */
69 enum variable_flavor
70 flavor ENUM_BITFIELD (3); /* Variable flavor. */
71 enum variable_origin
72 origin ENUM_BITFIELD (3); /* Variable origin. */
73 enum variable_export
74 {
75 v_export, /* Export this variable. */
76 v_noexport, /* Don't export this variable. */
77 v_ifset, /* Export it if it has a non-default value. */
78 v_default /* Decide in target_environment. */
79 } export ENUM_BITFIELD (2);
80 };
81
82/* Structure that represents a variable set. */
83
84struct variable_set
85 {
86 struct hash_table table; /* Hash table of variables. */
87 };
88
89/* Structure that represents a list of variable sets. */
90
91struct variable_set_list
92 {
93 struct variable_set_list *next; /* Link in the chain. */
94 struct variable_set *set; /* Variable set. */
95 };
96
97/* Structure used for pattern-specific variables. */
98
99struct pattern_var
100 {
101 struct pattern_var *next;
102 const char *suffix;
103 const char *target;
104 unsigned int len;
105 struct variable variable;
106 };
107
108extern char *variable_buffer;
109extern struct variable_set_list *current_variable_set_list;
110
111/* expand.c */
112char *variable_buffer_output (char *ptr, const char *string, unsigned int length);
113char *variable_expand (const char *line);
114char *variable_expand_for_file (const char *line, struct file *file);
115char *allocated_variable_expand_for_file (const char *line, struct file *file);
116#define allocated_variable_expand(line) \
117 allocated_variable_expand_for_file (line, (struct file *) 0)
118char *expand_argument (const char *str, const char *end);
119char *variable_expand_string (char *line, const char *string, long length);
120void install_variable_buffer (char **bufp, unsigned int *lenp);
121void restore_variable_buffer (char *buf, unsigned int len);
122
123/* function.c */
124int handle_function (char **op, const char **stringp);
125int pattern_matches (const char *pattern, const char *percent, const char *str);
126char *subst_expand (char *o, const char *text, const char *subst,
127 const char *replace, unsigned int slen, unsigned int rlen,
128 int by_word);
129char *patsubst_expand_pat (char *o, const char *text, const char *pattern,
130 const char *replace, const char *pattern_percent,
131 const char *replace_percent);
132char *patsubst_expand (char *o, const char *text, char *pattern, char *replace);
133
134/* expand.c */
135char *recursively_expand_for_file (struct variable *v, struct file *file);
136#define recursively_expand(v) recursively_expand_for_file (v, NULL)
137
138/* variable.c */
139struct variable_set_list *create_new_variable_set (void);
140void free_variable_set (struct variable_set_list *);
141struct variable_set_list *push_new_variable_scope (void);
142void pop_variable_scope (void);
143void define_automatic_variables (void);
144void initialize_file_variables (struct file *file, int reading);
145void print_file_variables (const struct file *file);
146void print_variable_set (struct variable_set *set, char *prefix);
147void merge_variable_set_lists (struct variable_set_list **to_list,
148 struct variable_set_list *from_list);
149struct variable *do_variable_definition (const struct floc *flocp,
150 const char *name, const char *value,
151 enum variable_origin origin,
152 enum variable_flavor flavor,
153 int target_var);
154struct variable *parse_variable_definition (struct variable *v, char *line);
155struct variable *try_variable_definition (const struct floc *flocp, char *line,
156 enum variable_origin origin,
157 int target_var);
158void init_hash_global_variable_set (void);
159void hash_init_function_table (void);
160struct variable *lookup_variable (const char *name, unsigned int length);
161struct variable *lookup_variable_in_set (const char *name, unsigned int length,
162 const struct variable_set *set);
163
164struct variable *define_variable_in_set (const char *name, unsigned int length,
165 const char *value,
166 enum variable_origin origin,
167 int recursive,
168 struct variable_set *set,
169 const struct floc *flocp);
170
171/* Define a variable in the current variable set. */
172
173#define define_variable(n,l,v,o,r) \
174 define_variable_in_set((n),(l),(v),(o),(r),\
175 current_variable_set_list->set,NILF)
176
177/* Define a variable with a location in the current variable set. */
178
179#define define_variable_loc(n,l,v,o,r,f) \
180 define_variable_in_set((n),(l),(v),(o),(r),\
181 current_variable_set_list->set,(f))
182
183/* Define a variable with a location in the global variable set. */
184
185#define define_variable_global(n,l,v,o,r,f) \
186 define_variable_in_set((n),(l),(v),(o),(r),NULL,(f))
187
188/* Define a variable in FILE's variable set. */
189
190#define define_variable_for_file(n,l,v,o,r,f) \
191 define_variable_in_set((n),(l),(v),(o),(r),(f)->variables->set,NILF)
192
193/* Warn that NAME is an undefined variable. */
194
195#define warn_undefined(n,l) do{\
196 if (warn_undefined_variables_flag) \
197 error (reading_file, \
198 _("warning: undefined variable `%.*s'"), \
199 (int)(l), (n)); \
200 }while(0)
201
202char **target_environment (struct file *file);
203
204struct pattern_var *create_pattern_var (const char *target,
205 const char *suffix);
206
207extern int export_all_variables;
208
209#define MAKELEVEL_NAME "MAKELEVEL"
210#define MAKELEVEL_LENGTH (sizeof (MAKELEVEL_NAME) - 1)
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette