1994-03-23 22:12:55 +08:00
|
|
|
/* Definitions for using variables in GNU Make.
|
2006-02-12 03:02:21 +08:00
|
|
|
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
|
2006-02-12 06:16:04 +08:00
|
|
|
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
|
|
|
|
Foundation, Inc.
|
1991-06-04 05:37:27 +09:00
|
|
|
This file is part of GNU Make.
|
|
|
|
|
2006-02-12 03:02:21 +08:00
|
|
|
GNU Make is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 2, or (at your option) any later version.
|
1991-06-04 05:37:27 +09:00
|
|
|
|
2006-02-12 03:02:21 +08:00
|
|
|
GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
1991-06-04 05:37:27 +09:00
|
|
|
|
2006-02-12 03:02:21 +08:00
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
GNU Make; see the file COPYING. If not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
|
1991-06-04 05:37:27 +09:00
|
|
|
|
2002-07-11 14:38:57 +08:00
|
|
|
#include "hash.h"
|
|
|
|
|
1991-06-04 05:37:27 +09:00
|
|
|
/* Codes in a variable definition saying where the definition came from.
|
|
|
|
Increasing numeric values signify less-overridable definitions. */
|
|
|
|
enum variable_origin
|
|
|
|
{
|
|
|
|
o_default, /* Variable from the default set. */
|
|
|
|
o_env, /* Variable from environment. */
|
|
|
|
o_file, /* Variable given in a makefile. */
|
|
|
|
o_env_override, /* Variable from environment, if -e. */
|
|
|
|
o_command, /* Variable given by user. */
|
|
|
|
o_override, /* Variable from an `override' directive. */
|
|
|
|
o_automatic, /* Automatic variable -- cannot be set. */
|
|
|
|
o_invalid /* Core dump time. */
|
|
|
|
};
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
enum variable_flavor
|
|
|
|
{
|
|
|
|
f_bogus, /* Bogus (error) */
|
|
|
|
f_simple, /* Simple definition (:=) */
|
|
|
|
f_recursive, /* Recursive definition (=) */
|
|
|
|
f_append, /* Appending definition (+=) */
|
|
|
|
f_conditional /* Conditional definition (?=) */
|
|
|
|
};
|
|
|
|
|
1991-06-04 05:37:27 +09:00
|
|
|
/* Structure that represents one variable definition.
|
|
|
|
Each bucket of the hash table is a chain of these,
|
|
|
|
chained through `next'. */
|
|
|
|
|
2002-05-10 11:15:07 +08:00
|
|
|
#define EXP_COUNT_BITS 15 /* This gets all the bitfields into 32 bits */
|
|
|
|
#define EXP_COUNT_MAX ((1<<EXP_COUNT_BITS)-1)
|
|
|
|
|
1991-06-04 05:37:27 +09:00
|
|
|
struct variable
|
|
|
|
{
|
|
|
|
char *name; /* Variable name. */
|
2002-07-11 14:38:57 +08:00
|
|
|
int length; /* strlen (name) */
|
1991-06-04 05:37:27 +09:00
|
|
|
char *value; /* Variable value. */
|
2000-02-05 15:37:40 +08:00
|
|
|
struct floc fileinfo; /* Where the variable was defined. */
|
1991-06-04 05:37:27 +09:00
|
|
|
unsigned int recursive:1; /* Gets recursively re-evaluated. */
|
1999-11-17 15:33:47 +08:00
|
|
|
unsigned int append:1; /* Nonzero if an appending target-specific
|
|
|
|
variable. */
|
2003-05-02 09:44:59 +08:00
|
|
|
unsigned int conditional:1; /* Nonzero if set with a ?=. */
|
|
|
|
unsigned int per_target:1; /* Nonzero if a target-specific variable. */
|
2002-08-08 08:11:19 +08:00
|
|
|
unsigned int special:1; /* Nonzero if this is a special variable. */
|
2003-05-02 09:44:59 +08:00
|
|
|
unsigned int exportable:1; /* Nonzero if the variable _could_ be
|
|
|
|
exported. */
|
2002-08-01 21:16:57 +08:00
|
|
|
unsigned int expanding:1; /* Nonzero if currently being expanded. */
|
|
|
|
unsigned int exp_count:EXP_COUNT_BITS;
|
|
|
|
/* If >1, allow this many self-referential
|
|
|
|
expansions. */
|
2003-05-02 09:44:59 +08:00
|
|
|
enum variable_flavor
|
|
|
|
flavor ENUM_BITFIELD (3); /* Variable flavor. */
|
2002-05-10 11:15:07 +08:00
|
|
|
enum variable_origin
|
|
|
|
origin ENUM_BITFIELD (3); /* Variable origin. */
|
1998-07-31 04:54:47 +08:00
|
|
|
enum variable_export
|
1992-05-04 06:09:16 +08:00
|
|
|
{
|
|
|
|
v_export, /* Export this variable. */
|
|
|
|
v_noexport, /* Don't export this variable. */
|
1992-07-10 12:06:24 +08:00
|
|
|
v_ifset, /* Export it if it has a non-default value. */
|
1992-05-04 06:09:16 +08:00
|
|
|
v_default /* Decide in target_environment. */
|
|
|
|
} export ENUM_BITFIELD (2);
|
1991-06-04 05:37:27 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Structure that represents a variable set. */
|
|
|
|
|
|
|
|
struct variable_set
|
|
|
|
{
|
2002-07-11 14:38:57 +08:00
|
|
|
struct hash_table table; /* Hash table of variables. */
|
1991-06-04 05:37:27 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Structure that represents a list of variable sets. */
|
|
|
|
|
|
|
|
struct variable_set_list
|
|
|
|
{
|
|
|
|
struct variable_set_list *next; /* Link in the chain. */
|
|
|
|
struct variable_set *set; /* Variable set. */
|
|
|
|
};
|
|
|
|
|
2003-05-02 09:44:59 +08:00
|
|
|
/* Structure used for pattern-specific variables. */
|
|
|
|
|
|
|
|
struct pattern_var
|
|
|
|
{
|
|
|
|
struct pattern_var *next;
|
|
|
|
char *target;
|
|
|
|
unsigned int len;
|
|
|
|
char *suffix;
|
|
|
|
struct variable variable;
|
|
|
|
};
|
|
|
|
|
1998-07-31 04:54:47 +08:00
|
|
|
extern char *variable_buffer;
|
1991-06-04 05:37:27 +09:00
|
|
|
extern struct variable_set_list *current_variable_set_list;
|
|
|
|
|
1996-03-20 22:57:41 +08:00
|
|
|
/* expand.c */
|
|
|
|
extern char *variable_buffer_output PARAMS ((char *ptr, char *string, unsigned int length));
|
|
|
|
extern char *variable_expand PARAMS ((char *line));
|
2005-02-28 05:40:23 +08:00
|
|
|
extern char *variable_expand_for_file PARAMS ((char *line, struct file *file));
|
1996-03-20 22:57:41 +08:00
|
|
|
extern char *allocated_variable_expand_for_file PARAMS ((char *line, struct file *file));
|
1992-06-11 10:28:31 +08:00
|
|
|
#define allocated_variable_expand(line) \
|
|
|
|
allocated_variable_expand_for_file (line, (struct file *) 0)
|
2003-01-30 14:21:36 +08:00
|
|
|
extern char *expand_argument PARAMS ((const char *str, const char *end));
|
1998-07-31 04:54:47 +08:00
|
|
|
extern char *variable_expand_string PARAMS ((char *line, char *string,
|
|
|
|
long length));
|
2002-10-26 06:01:47 +08:00
|
|
|
extern void install_variable_buffer PARAMS ((char **bufp, unsigned int *lenp));
|
|
|
|
extern void restore_variable_buffer PARAMS ((char *buf, unsigned int len));
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
|
|
/* function.c */
|
|
|
|
extern int handle_function PARAMS ((char **op, char **stringp));
|
1998-07-31 04:54:47 +08:00
|
|
|
extern int pattern_matches PARAMS ((char *pattern, char *percent, char *str));
|
1996-03-20 22:57:41 +08:00
|
|
|
extern char *subst_expand PARAMS ((char *o, char *text, char *subst, char *replace,
|
2004-09-21 12:00:31 +08:00
|
|
|
unsigned int slen, unsigned int rlen, int by_word));
|
1996-03-20 22:57:41 +08:00
|
|
|
extern char *patsubst_expand PARAMS ((char *o, char *text, char *pattern, char *replace,
|
|
|
|
char *pattern_percent, char *replace_percent));
|
|
|
|
|
|
|
|
/* expand.c */
|
2002-05-10 11:15:07 +08:00
|
|
|
extern char *recursively_expand_for_file PARAMS ((struct variable *v,
|
|
|
|
struct file *file));
|
|
|
|
#define recursively_expand(v) recursively_expand_for_file (v, NULL)
|
1996-03-20 22:57:41 +08:00
|
|
|
|
|
|
|
/* variable.c */
|
1998-07-31 04:54:47 +08:00
|
|
|
extern struct variable_set_list *create_new_variable_set PARAMS ((void));
|
2006-02-14 23:42:17 +08:00
|
|
|
extern void free_variable_set PARAMS ((struct variable_set_list *));
|
1998-07-31 04:54:47 +08:00
|
|
|
extern struct variable_set_list *push_new_variable_scope PARAMS ((void));
|
1996-03-20 22:57:41 +08:00
|
|
|
extern void pop_variable_scope PARAMS ((void));
|
|
|
|
extern void define_automatic_variables PARAMS ((void));
|
2000-02-05 15:37:40 +08:00
|
|
|
extern void initialize_file_variables PARAMS ((struct file *file, int read));
|
1996-03-20 22:57:41 +08:00
|
|
|
extern void print_file_variables PARAMS ((struct file *file));
|
1998-07-31 04:54:47 +08:00
|
|
|
extern void print_variable_set PARAMS ((struct variable_set *set, char *prefix));
|
2003-05-02 09:44:59 +08:00
|
|
|
extern void merge_variable_set_lists PARAMS ((struct variable_set_list **to_list, struct variable_set_list *from_list));
|
2002-07-08 10:26:47 +08:00
|
|
|
extern struct variable *do_variable_definition PARAMS ((const struct floc *flocp, const char *name, char *value, enum variable_origin origin, enum variable_flavor flavor, int target_var));
|
2003-05-02 09:44:59 +08:00
|
|
|
extern struct variable *parse_variable_definition PARAMS ((struct variable *v, char *line));
|
1999-11-17 15:33:47 +08:00
|
|
|
extern struct variable *try_variable_definition PARAMS ((const struct floc *flocp, char *line, enum variable_origin origin, int target_var));
|
2002-07-11 14:38:57 +08:00
|
|
|
extern void init_hash_global_variable_set PARAMS ((void));
|
|
|
|
extern void hash_init_function_table PARAMS ((void));
|
2001-01-21 14:49:11 +08:00
|
|
|
extern struct variable *lookup_variable PARAMS ((const char *name, unsigned int length));
|
|
|
|
extern struct variable *lookup_variable_in_set PARAMS ((const char *name,
|
|
|
|
unsigned int length,
|
|
|
|
const struct variable_set *set));
|
2000-02-05 15:37:40 +08:00
|
|
|
|
|
|
|
extern struct variable *define_variable_in_set
|
2002-07-08 10:26:47 +08:00
|
|
|
PARAMS ((const char *name, unsigned int length, char *value,
|
2000-02-05 15:37:40 +08:00
|
|
|
enum variable_origin origin, int recursive,
|
|
|
|
struct variable_set *set, const struct floc *flocp));
|
|
|
|
|
|
|
|
/* Define a variable in the current variable set. */
|
|
|
|
|
|
|
|
#define define_variable(n,l,v,o,r) \
|
|
|
|
define_variable_in_set((n),(l),(v),(o),(r),\
|
|
|
|
current_variable_set_list->set,NILF)
|
|
|
|
|
|
|
|
/* Define a variable with a location in the current variable set. */
|
|
|
|
|
|
|
|
#define define_variable_loc(n,l,v,o,r,f) \
|
|
|
|
define_variable_in_set((n),(l),(v),(o),(r),\
|
|
|
|
current_variable_set_list->set,(f))
|
|
|
|
|
2002-07-08 10:26:47 +08:00
|
|
|
/* Define a variable with a location in the global variable set. */
|
|
|
|
|
|
|
|
#define define_variable_global(n,l,v,o,r,f) \
|
|
|
|
define_variable_in_set((n),(l),(v),(o),(r),NULL,(f))
|
|
|
|
|
2000-02-05 15:37:40 +08:00
|
|
|
/* Define a variable in FILE's variable set. */
|
|
|
|
|
|
|
|
#define define_variable_for_file(n,l,v,o,r,f) \
|
|
|
|
define_variable_in_set((n),(l),(v),(o),(r),(f)->variables->set,NILF)
|
|
|
|
|
2002-05-10 11:15:07 +08:00
|
|
|
/* Warn that NAME is an undefined variable. */
|
|
|
|
|
|
|
|
#define warn_undefined(n,l) do{\
|
|
|
|
if (warn_undefined_variables_flag) \
|
|
|
|
error (reading_file, \
|
|
|
|
_("warning: undefined variable `%.*s'"), \
|
|
|
|
(int)(l), (n)); \
|
|
|
|
}while(0)
|
|
|
|
|
1996-03-20 22:57:41 +08:00
|
|
|
extern char **target_environment PARAMS ((struct file *file));
|
1991-06-04 05:37:27 +09:00
|
|
|
|
2003-05-02 09:44:59 +08:00
|
|
|
extern struct pattern_var *create_pattern_var PARAMS ((char *target, char *suffix));
|
|
|
|
|
1992-05-05 06:33:57 +08:00
|
|
|
extern int export_all_variables;
|
2002-07-11 14:38:57 +08:00
|
|
|
|
|
|
|
#define MAKELEVEL_NAME "MAKELEVEL"
|
|
|
|
#define MAKELEVEL_LENGTH (sizeof (MAKELEVEL_NAME) - 1)
|