| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef VARIABLE_H |
| 18 |
#define VARIABLE_H |
| 19 |
|
| 20 |
#include "gnuremake.h" |
| 21 |
#include "hash.h" |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
enum variable_origin |
| 26 |
{ |
| 27 |
o_default, |
| 28 |
o_env, |
| 29 |
o_file, |
| 30 |
o_env_override, |
| 31 |
o_command, |
| 32 |
o_override, |
| 33 |
o_automatic, |
| 34 |
o_debugger, |
| 35 |
o_invalid |
| 36 |
}; |
| 37 |
|
| 38 |
enum variable_flavor |
| 39 |
{ |
| 40 |
f_bogus, |
| 41 |
f_simple, |
| 42 |
f_recursive, |
| 43 |
f_append, |
| 44 |
f_conditional, |
| 45 |
f_shell, |
| 46 |
f_append_value |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
#define EXP_COUNT_BITS 15 |
| 54 |
#define EXP_COUNT_MAX ((1<<EXP_COUNT_BITS)-1) |
| 55 |
|
| 56 |
struct variable |
| 57 |
{ |
| 58 |
char *name; |
| 59 |
char *value; |
| 60 |
gmk_floc fileinfo; |
| 61 |
unsigned int length; |
| 62 |
unsigned int recursive:1; |
| 63 |
unsigned int append:1; |
| 64 |
|
| 65 |
unsigned int conditional:1; |
| 66 |
unsigned int per_target:1; |
| 67 |
unsigned int special:1; |
| 68 |
unsigned int exportable:1; |
| 69 |
|
| 70 |
unsigned int expanding:1; |
| 71 |
unsigned int private_var:1; |
| 72 |
|
| 73 |
unsigned int exp_count:EXP_COUNT_BITS; |
| 74 |
|
| 75 |
|
| 76 |
enum variable_flavor |
| 77 |
flavor ENUM_BITFIELD (4); |
| 78 |
enum variable_origin |
| 79 |
origin ENUM_BITFIELD (4); |
| 80 |
enum variable_export |
| 81 |
{ |
| 82 |
v_export, |
| 83 |
v_noexport, |
| 84 |
v_ifset, |
| 85 |
v_default |
| 86 |
} export ENUM_BITFIELD (2); |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
struct variable_set |
| 92 |
{ |
| 93 |
struct hash_table table; |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
struct variable_set_list |
| 99 |
{ |
| 100 |
struct variable_set_list *next; |
| 101 |
struct variable_set *set; |
| 102 |
int next_is_parent; |
| 103 |
}; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
struct pattern_var |
| 108 |
{ |
| 109 |
struct pattern_var *next; |
| 110 |
const char *suffix; |
| 111 |
const char *target; |
| 112 |
size_t len; |
| 113 |
struct variable variable; |
| 114 |
}; |
| 115 |
|
| 116 |
extern char *variable_buffer; |
| 117 |
extern struct variable_set_list *current_variable_set_list; |
| 118 |
extern struct variable *default_goal_var; |
| 119 |
extern struct variable shell_var; |
| 120 |
|
| 121 |
|
| 122 |
#ifndef SIZE_MAX |
| 123 |
# define SIZE_MAX ((size_t)~(size_t)0) |
| 124 |
#endif |
| 125 |
|
| 126 |
char *variable_buffer_output (char *ptr, const char *string, size_t length); |
| 127 |
char *variable_expand (const char *line); |
| 128 |
char *variable_expand_for_file (const char *line, struct file *file); |
| 129 |
char *allocated_variable_expand_for_file (const char *line, struct file *file); |
| 130 |
#define allocated_variable_expand(line) \ |
| 131 |
allocated_variable_expand_for_file (line, (struct file *) 0) |
| 132 |
char *expand_argument (const char *str, const char *end); |
| 133 |
char *variable_expand_string (char *line, const char *string, size_t length); |
| 134 |
void install_variable_buffer (char **bufp, size_t *lenp); |
| 135 |
void restore_variable_buffer (char *buf, size_t len); |
| 136 |
|
| 137 |
|
| 138 |
int handle_function (char **op, const char **stringp); |
| 139 |
int pattern_matches (const char *pattern, const char *percent, const char *str); |
| 140 |
char *subst_expand (char *o, const char *text, const char *subst, |
| 141 |
const char *replace, size_t slen, size_t rlen, |
| 142 |
int by_word); |
| 143 |
char *patsubst_expand_pat (char *o, const char *text, const char *pattern, |
| 144 |
const char *replace, const char *pattern_percent, |
| 145 |
const char *replace_percent); |
| 146 |
char *patsubst_expand (char *o, const char *text, char *pattern, char *replace); |
| 147 |
char *func_shell_base (char *o, char **argv, int trim_newlines); |
| 148 |
void shell_completed (int exit_code, int exit_sig); |
| 149 |
|
| 150 |
|
| 151 |
char *recursively_expand_for_file (struct variable *v, struct file *file); |
| 152 |
#define recursively_expand(v) recursively_expand_for_file (v, NULL) |
| 153 |
|
| 154 |
|
| 155 |
struct variable_set_list *create_new_variable_set (void); |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
const char *origin2str(variable_origin_t origin); |
| 161 |
|
| 162 |
void free_variable_set (struct variable_set_list *); |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
struct variable_set_list *push_new_variable_scope (void); |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
void pop_variable_scope (void); |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
void define_automatic_variables (void); |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
void initialize_file_variables (struct file *file, int reading); |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
extern void print_file_variables(const file_t *p_target, bool b_hash_stats); |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
extern void print_variable_data_base (void); |
| 199 |
|
| 200 |
|
| 201 |
extern void print_variable_info (const void *item, void *arg); |
| 202 |
|
| 203 |
void print_target_variables (const struct file *file); |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
void print_variable_set (struct variable_set *set, const char *prefix, int pauto); |
| 210 |
|
| 211 |
void merge_variable_set_lists (struct variable_set_list **to_list, |
| 212 |
struct variable_set_list *from_list); |
| 213 |
struct variable *do_variable_definition (const gmk_floc *flocp, |
| 214 |
const char *name, const char *value, |
| 215 |
enum variable_origin origin, |
| 216 |
enum variable_flavor flavor, |
| 217 |
int target_var); |
| 218 |
char *parse_variable_definition (const char *line, |
| 219 |
struct variable *v); |
| 220 |
struct variable *assign_variable_definition (struct variable *v, const char *line); |
| 221 |
struct variable *try_variable_definition (const gmk_floc *flocp, const char *line, |
| 222 |
enum variable_origin origin, |
| 223 |
int target_var); |
| 224 |
void init_hash_global_variable_set (void); |
| 225 |
void hash_init_function_table (void); |
| 226 |
void define_new_function(const gmk_floc *flocp, const char *name, |
| 227 |
unsigned int min, unsigned int max, unsigned int flags, |
| 228 |
gmk_func_ptr func); |
| 229 |
struct variable *lookup_variable (const char *name, size_t length); |
| 230 |
struct variable *lookup_variable_in_set (const char *name, size_t length, |
| 231 |
const struct variable_set *set); |
| 232 |
|
| 233 |
struct variable *define_variable_in_set (const char *name, size_t length, |
| 234 |
const char *value, |
| 235 |
enum variable_origin origin, |
| 236 |
int recursive, |
| 237 |
struct variable_set *set, |
| 238 |
const gmk_floc *flocp); |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
#define define_variable(n,l,v,o,r) \ |
| 243 |
define_variable_in_set((n),(l),(v),(o),(r),\ |
| 244 |
current_variable_set_list->set,NILF) |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
#define define_variable_cname(n,v,o,r) \ |
| 249 |
define_variable_in_set((n),(sizeof (n) - 1),(v),(o),(r),\ |
| 250 |
current_variable_set_list->set,NILF) |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
#define define_variable_loc(n,l,v,o,r,f) \ |
| 255 |
define_variable_in_set((n),(l),(v),(o),(r),\ |
| 256 |
current_variable_set_list->set,(f)) |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
#define define_variable_global(n,l,v,o,r,f) \ |
| 261 |
define_variable_in_set((n),(l),(v),(o),(r),NULL,(f)) |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
#define define_variable_for_file(n,l,v,o,r,f) \ |
| 266 |
define_variable_in_set((n),(l),(v),(o),(r),(f)->variables->set,NILF) |
| 267 |
|
| 268 |
void undefine_variable_in_set (const char *name, size_t length, |
| 269 |
enum variable_origin origin, |
| 270 |
struct variable_set *set); |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
#define undefine_variable_global(n,l,o) \ |
| 275 |
undefine_variable_in_set((n),(l),(o),NULL) |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
#define warn_undefined(n,l) do{\ |
| 280 |
if (warn_undefined_variables_flag) \ |
| 281 |
error (reading_file, (l), \ |
| 282 |
_("warning: undefined variable '%.*s'"), \ |
| 283 |
(int)(l), (n)); \ |
| 284 |
}while(0) |
| 285 |
|
| 286 |
char **target_environment (struct file *file); |
| 287 |
|
| 288 |
struct pattern_var *create_pattern_var (const char *target, |
| 289 |
const char *suffix); |
| 290 |
|
| 291 |
extern int export_all_variables; |
| 292 |
|
| 293 |
#define MAKELEVEL_NAME "MAKELEVEL" |
| 294 |
#define MAKELEVEL_LENGTH (CSTRLEN (MAKELEVEL_NAME)) |
| 295 |
|
| 296 |
#define MAKEPARENT_PID_NAME "MAKEPARENT_PID" |
| 297 |
#define MAKEPARENT_PID_LENGTH (CSTRLEN (MAKEPARENT_PID_NAME)) |
| 298 |
|
| 299 |
#define MAKEPARENT_TARGET_NAME "MAKEPARENT_TARGET" |
| 300 |
#define MAKEPARENT_TARGET_LENGTH (CSTRLEN (MAKEPARENT_TARGET_NAME)) |
| 301 |
#endif |