#include "make.h"
#include "dep.h"
#include "filedef.h"
#include "job.h"
#include "commands.h"
#include "variable.h"
#include "rule.h"
#ifdef WINDOWS32
#include "pathstuff.h"
#endif
#ifndef VARIABLE_BUCKETS
#define VARIABLE_BUCKETS 523
#endif
#ifndef PERFILE_VARIABLE_BUCKETS
#define PERFILE_VARIABLE_BUCKETS 23
#endif
#ifndef SMALL_SCOPE_VARIABLE_BUCKETS
#define SMALL_SCOPE_VARIABLE_BUCKETS 13
#endif
static struct variable *variable_table[VARIABLE_BUCKETS];
static struct variable_set global_variable_set
= { variable_table, VARIABLE_BUCKETS };
static struct variable_set_list global_setlist
= { 0, &global_variable_set };
struct variable_set_list *current_variable_set_list = &global_setlist;
static struct variable *lookup_variable_in_set PARAMS ((char *name,
unsigned int length, struct variable_set *set));
#if defined(__APPLE__) || defined(NeXT) || defined(NeXT_PDO)
static void check_apple_pb_support (name, length, value)
char *name;
unsigned int length;
char *value;
{
char *p;
if (length == 20 && !strncmp (name, "USE_APPLE_PB_SUPPORT", length)) {
for (p = value; *p != '\0'; p++) {
if (isspace (*p)) {
continue;
}
if (!strncmp (p, "all", 3)) {
p += 3;
next_flag |= NEXT_ALL_FLAGS;
} else if (!strncmp (p, "vpath", 5)) {
p += 5;
next_flag |= NEXT_VPATH_FLAG;
} else if (!strncmp (p, "quiet", 5)) {
p += 5;
next_flag |= NEXT_QUIET_FLAG;
} else if (!strncmp (p, "makefiles", 9)) {
p += 9;
next_flag |= NEXT_MAKEFILES_FLAG;
} else if (!strncmp (p, "errexit", 7)) {
p += 7;
next_flag |= NEXT_ERREXIT_FLAG;
}
}
}
}
#endif
struct variable *
define_variable_in_set (name, length, value, origin, recursive, set, flocp)
char *name;
unsigned int length;
char *value;
enum variable_origin origin;
int recursive;
struct variable_set *set;
const struct floc *flocp;
{
register unsigned int i;
register unsigned int hashval;
register struct variable *v;
#if defined(__APPLE__) || defined(NeXT) || defined(NeXT_PDO)
check_apple_pb_support (name, length, value);
#endif
hashval = 0;
for (i = 0; i < length; ++i)
HASH (hashval, name[i]);
hashval %= set->buckets;
for (v = set->table[hashval]; v != 0; v = v->next)
if (*v->name == *name
&& strneq (v->name + 1, name + 1, length - 1)
&& v->name[length] == '\0')
break;
if (env_overrides && origin == o_env)
origin = o_env_override;
if (v != 0)
{
if (env_overrides && v->origin == o_env)
v->origin = o_env_override;
if ((int) origin >= (int) v->origin)
{
if (v->value != 0)
free (v->value);
v->value = xstrdup (value);
if (flocp != 0)
v->fileinfo = *flocp;
else
v->fileinfo.filenm = 0;
v->origin = origin;
v->recursive = recursive;
}
return v;
}
v = (struct variable *) xmalloc (sizeof (struct variable));
v->name = savestring (name, length);
v->value = xstrdup (value);
if (flocp != 0)
v->fileinfo = *flocp;
else
v->fileinfo.filenm = 0;
v->origin = origin;
v->recursive = recursive;
v->expanding = 0;
v->per_target = 0;
v->append = 0;
v->export = v_default;
v->next = set->table[hashval];
set->table[hashval] = v;
return v;
}
struct variable *
lookup_variable (name, length)
char *name;
unsigned int length;
{
register struct variable_set_list *setlist;
struct variable *firstv = 0;
register unsigned int i;
register unsigned int rawhash = 0;
for (i = 0; i < length; ++i)
HASH (rawhash, name[i]);
for (setlist = current_variable_set_list;
setlist != 0; setlist = setlist->next)
{
register struct variable_set *set = setlist->set;
register unsigned int hashval = rawhash % set->buckets;
register struct variable *v;
for (v = set->table[hashval]; v != 0; v = v->next)
if (*v->name == *name
&& strneq (v->name + 1, name + 1, length - 1)
&& v->name[length] == '\0')
break;
if (!v)
continue;
if (!v->expanding)
return v;
if (!firstv)
firstv = v;
}
#ifdef VMS
if (!firstv)
{
char *vname = alloca (length + 1);
char *value;
strncpy (vname, name, length);
vname[length] = 0;
value = getenv (vname);
if (value != 0)
{
char *sptr;
int scnt;
sptr = value;
scnt = 0;
if (listp)
*listp = current_variable_set_list;
while ((sptr = strchr (sptr, '$')))
{
scnt++;
sptr++;
}
if (scnt > 0)
{
char *nvalue;
char *nptr;
nvalue = alloca (length + scnt + 1);
sptr = value;
nptr = nvalue;
while (*sptr)
{
if (*sptr == '$')
{
*nptr++ = '$';
*nptr++ = '$';
}
else
{
*nptr++ = *sptr;
}
sptr++;
}
return define_variable (vname, length, nvalue, o_env, 1);
}
return define_variable (vname, length, value, o_env, 1);
}
}
#endif
return firstv;
}
static struct variable *
lookup_variable_in_set (name, length, set)
char *name;
unsigned int length;
struct variable_set *set;
{
register unsigned int i;
register unsigned int hash = 0;
register struct variable *v;
for (i = 0; i < length; ++i)
HASH (hash, name[i]);
hash %= set->buckets;
for (v = set->table[hash]; v != 0; v = v->next)
if (*v->name == *name
&& strneq (v->name + 1, name + 1, length - 1)
&& v->name[length] == 0)
return v;
return 0;
}
void
initialize_file_variables (file, reading)
struct file *file;
int reading;
{
register struct variable_set_list *l = file->variables;
if (l == 0)
{
l = (struct variable_set_list *)
xmalloc (sizeof (struct variable_set_list));
l->set = (struct variable_set *) xmalloc (sizeof (struct variable_set));
l->set->buckets = PERFILE_VARIABLE_BUCKETS;
l->set->table = (struct variable **)
xmalloc (l->set->buckets * sizeof (struct variable *));
bzero ((char *) l->set->table,
l->set->buckets * sizeof (struct variable *));
file->variables = l;
}
if (file->parent == 0)
l->next = &global_setlist;
else
{
initialize_file_variables (file->parent, reading);
l->next = file->parent->variables;
}
if (!reading && !file->pat_searched)
{
struct pattern_var *p = lookup_pattern_var (file->name);
file->pat_searched = 1;
if (p != 0)
{
file->pat_variables = (struct variable_set_list *)
xmalloc (sizeof (struct variable_set_list));
file->pat_variables->set = p->vars->set;
}
}
if (file->pat_variables != 0)
{
file->pat_variables->next = l->next;
l->next = file->pat_variables;
}
}
void
pop_variable_scope ()
{
register struct variable_set_list *setlist = current_variable_set_list;
register struct variable_set *set = setlist->set;
register unsigned int i;
current_variable_set_list = setlist->next;
free ((char *) setlist);
for (i = 0; i < set->buckets; ++i)
{
register struct variable *next = set->table[i];
while (next != 0)
{
register struct variable *v = next;
next = v->next;
free (v->name);
if (v->value)
free (v->value);
free ((char *) v);
}
}
free ((char *) set->table);
free ((char *) set);
}
struct variable_set_list *
create_new_variable_set ()
{
register struct variable_set_list *setlist;
register struct variable_set *set;
set = (struct variable_set *) xmalloc (sizeof (struct variable_set));
set->buckets = SMALL_SCOPE_VARIABLE_BUCKETS;
set->table = (struct variable **)
xmalloc (set->buckets * sizeof (struct variable *));
bzero ((char *) set->table, set->buckets * sizeof (struct variable *));
setlist = (struct variable_set_list *)
xmalloc (sizeof (struct variable_set_list));
setlist->set = set;
setlist->next = current_variable_set_list;
return setlist;
}
struct variable_set_list *
push_new_variable_scope ()
{
return (current_variable_set_list = create_new_variable_set());
}
static void
merge_variable_sets (set0, set1)
struct variable_set *set0, *set1;
{
register unsigned int bucket1;
for (bucket1 = 0; bucket1 < set1->buckets; ++bucket1)
{
register struct variable *v1 = set1->table[bucket1];
while (v1 != 0)
{
struct variable *next = v1->next;
unsigned int bucket0;
register struct variable *v0;
if (set1->buckets >= set0->buckets)
bucket0 = bucket1;
else
{
register char *n;
bucket0 = 0;
for (n = v1->name; *n != '\0'; ++n)
HASH (bucket0, *n);
}
bucket0 %= set0->buckets;
for (v0 = set0->table[bucket0]; v0 != 0; v0 = v0->next)
if (streq (v0->name, v1->name))
break;
if (v0 == 0)
{
v1->next = set0->table[bucket0];
set0->table[bucket0] = v1;
}
else
{
free (v1->value);
free ((char *) v1);
}
v1 = next;
}
}
}
void
merge_variable_set_lists (setlist0, setlist1)
struct variable_set_list **setlist0, *setlist1;
{
register struct variable_set_list *list0 = *setlist0;
struct variable_set_list *last0 = 0;
while (setlist1 != 0 && list0 != 0)
{
struct variable_set_list *next = setlist1;
setlist1 = setlist1->next;
merge_variable_sets (list0->set, next->set);
last0 = list0;
list0 = list0->next;
}
if (setlist1 != 0)
{
if (last0 == 0)
*setlist0 = setlist1;
else
last0->next = setlist1;
}
}
void
define_automatic_variables ()
{
#ifdef WINDOWS32
extern char* default_shell;
#else
extern char default_shell[];
#endif
register struct variable *v;
char buf[200];
sprintf (buf, "%u", makelevel);
(void) define_variable ("MAKELEVEL", 9, buf, o_env, 0);
sprintf (buf, "%s%s%s",
version_string,
(remote_description == 0 || remote_description[0] == '\0')
? "" : "-",
(remote_description == 0 || remote_description[0] == '\0')
? "" : remote_description);
(void) define_variable ("MAKE_VERSION", 12, buf, o_default, 0);
#ifdef __MSDOS__
{
static char shell_str[] = "SHELL";
const int shlen = sizeof (shell_str) - 1;
struct variable *mshp = lookup_variable ("MAKESHELL", 9);
struct variable *comp = lookup_variable ("COMSPEC", 7);
if (mshp)
(void) define_variable (shell_str, shlen,
mshp->value, o_env_override, 0);
else if (comp)
{
struct variable *shp = lookup_variable (shell_str, shlen);
if (!shp)
(void) define_variable (shell_str, shlen, comp->value, o_env, 0);
}
}
#endif
v = define_variable ("SHELL", 5, default_shell, o_default, 0);
v->export = v_export;
#ifndef __MSDOS__
if (*v->value == '\0' || v->origin == o_env || v->origin == o_env_override)
{
free (v->value);
v->origin = o_file;
v->value = xstrdup (default_shell);
}
#endif
v = define_variable ("MAKEFILES", 9, "", o_default, 0);
v->export = v_ifset;
#ifdef VMS
define_variable ("@D", 2, "$(dir $@)", o_automatic, 1);
define_variable ("%D", 2, "$(dir $%)", o_automatic, 1);
define_variable ("*D", 2, "$(dir $*)", o_automatic, 1);
define_variable ("<D", 2, "$(dir $<)", o_automatic, 1);
define_variable ("?D", 2, "$(dir $?)", o_automatic, 1);
define_variable ("^D", 2, "$(dir $^)", o_automatic, 1);
define_variable ("+D", 2, "$(dir $+)", o_automatic, 1);
#else
define_variable ("@D", 2, "$(patsubst %/,%,$(dir $@))", o_automatic, 1);
define_variable ("%D", 2, "$(patsubst %/,%,$(dir $%))", o_automatic, 1);
define_variable ("*D", 2, "$(patsubst %/,%,$(dir $*))", o_automatic, 1);
define_variable ("<D", 2, "$(patsubst %/,%,$(dir $<))", o_automatic, 1);
define_variable ("?D", 2, "$(patsubst %/,%,$(dir $?))", o_automatic, 1);
define_variable ("^D", 2, "$(patsubst %/,%,$(dir $^))", o_automatic, 1);
define_variable ("+D", 2, "$(patsubst %/,%,$(dir $+))", o_automatic, 1);
#endif
define_variable ("@F", 2, "$(notdir $@)", o_automatic, 1);
define_variable ("%F", 2, "$(notdir $%)", o_automatic, 1);
define_variable ("*F", 2, "$(notdir $*)", o_automatic, 1);
define_variable ("<F", 2, "$(notdir $<)", o_automatic, 1);
define_variable ("?F", 2, "$(notdir $?)", o_automatic, 1);
define_variable ("^F", 2, "$(notdir $^)", o_automatic, 1);
define_variable ("+F", 2, "$(notdir $+)", o_automatic, 1);
}
int export_all_variables;
char **
target_environment (file)
struct file *file;
{
struct variable_set_list *set_list;
register struct variable_set_list *s;
struct variable_bucket
{
struct variable_bucket *next;
struct variable *variable;
};
struct variable_bucket **table;
unsigned int buckets;
register unsigned int i;
register unsigned nvariables;
char **result;
unsigned int mklev_hash;
if (file == 0)
set_list = current_variable_set_list;
else
set_list = file->variables;
s = set_list;
buckets = s->set->buckets;
for (s = s->next; s != 0; s = s->next)
if (s->set->buckets < buckets)
buckets = s->set->buckets;
{
char *p = "MAKELEVEL";
mklev_hash = 0;
while (*p != '\0')
HASH (mklev_hash, *p++);
}
table = (struct variable_bucket **)
alloca (buckets * sizeof (struct variable_bucket *));
bzero ((char *) table, buckets * sizeof (struct variable_bucket *));
nvariables = 0;
for (s = set_list; s != 0; s = s->next)
{
register struct variable_set *set = s->set;
for (i = 0; i < set->buckets; ++i)
{
register struct variable *v;
for (v = set->table[i]; v != 0; v = v->next)
{
unsigned int j = i % buckets;
register struct variable_bucket *ov;
register char *p = v->name;
if (i == mklev_hash % set->buckets
&& streq (v->name, "MAKELEVEL"))
continue;
if (v->per_target && v->export == v_default)
{
struct variable *gv;
gv = lookup_variable_in_set(v->name, strlen(v->name),
&global_variable_set);
if (gv)
v->export = gv->export;
}
switch (v->export)
{
case v_default:
if (v->origin == o_default || v->origin == o_automatic)
continue;
if (! export_all_variables
&& v->origin != o_command
&& v->origin != o_env && v->origin != o_env_override)
continue;
if (*p != '_' && (*p < 'A' || *p > 'Z')
&& (*p < 'a' || *p > 'z'))
continue;
for (++p; *p != '\0'; ++p)
if (*p != '_' && (*p < 'a' || *p > 'z')
&& (*p < 'A' || *p > 'Z') && (*p < '0' || *p > '9'))
continue;
if (*p != '\0')
continue;
break;
case v_export:
break;
case v_noexport:
continue;
case v_ifset:
if (v->origin == o_default)
continue;
break;
}
if (set->buckets != buckets)
{
register char *np;
j = 0;
for (np = v->name; *np != '\0'; ++np)
HASH (j, *np);
j %= buckets;
}
for (ov = table[j]; ov != 0; ov = ov->next)
if (streq (v->name, ov->variable->name))
break;
if (ov == 0)
{
register struct variable_bucket *entry;
entry = (struct variable_bucket *)
alloca (sizeof (struct variable_bucket));
entry->next = table[j];
entry->variable = v;
table[j] = entry;
++nvariables;
}
}
}
}
result = (char **) xmalloc ((nvariables + 2) * sizeof (char *));
nvariables = 0;
for (i = 0; i < buckets; ++i)
{
register struct variable_bucket *b;
for (b = table[i]; b != 0; b = b->next)
{
register struct variable *v = b->variable;
if (v->recursive
&& v->origin != o_env && v->origin != o_env_override)
{
char *value = recursively_expand (v);
#ifdef WINDOWS32
if (strcmp(v->name, "Path") == 0 ||
strcmp(v->name, "PATH") == 0)
convert_Path_to_windows32(value, ';');
#endif
result[nvariables++] = concat (v->name, "=", value);
free (value);
}
else
#ifdef WINDOWS32
{
if (strcmp(v->name, "Path") == 0 ||
strcmp(v->name, "PATH") == 0)
convert_Path_to_windows32(v->value, ';');
result[nvariables++] = concat (v->name, "=", v->value);
}
#else
result[nvariables++] = concat (v->name, "=", v->value);
#endif
}
}
result[nvariables] = (char *) xmalloc (100);
(void) sprintf (result[nvariables], "MAKELEVEL=%u", makelevel + 1);
result[++nvariables] = 0;
return result;
}
struct variable *
try_variable_definition (flocp, line, origin, target_var)
const struct floc *flocp;
char *line;
enum variable_origin origin;
int target_var;
{
register int c;
register char *p = line;
register char *beg;
register char *end;
enum { f_bogus,
f_simple, f_recursive, f_append, f_conditional } flavor = f_bogus;
char *name, *expanded_name, *value, *alloc_value=NULL;
struct variable *v;
int append = 0;
while (1)
{
c = *p++;
if (c == '\0' || c == '#')
return 0;
if (c == '=')
{
end = p - 1;
flavor = f_recursive;
break;
}
else if (c == ':')
if (*p == '=')
{
end = p++ - 1;
flavor = f_simple;
break;
}
else
return 0;
else if (c == '+' && *p == '=')
{
end = p++ - 1;
flavor = f_append;
break;
}
else if (c == '?' && *p == '=')
{
end = p++ - 1;
flavor = f_conditional;
break;
}
else if (c == '$')
{
char closeparen;
int count;
c = *p++;
if (c == '(')
closeparen = ')';
else if (c == '{')
closeparen = '}';
else
continue;
count = 0;
for (; *p != '\0'; ++p)
{
if (*p == c)
++count;
else if (*p == closeparen && --count < 0)
{
++p;
break;
}
}
}
}
beg = next_token (line);
while (end > beg && isblank (end[-1]))
--end;
p = next_token (p);
name = (char *) alloca (end - beg + 1);
bcopy (beg, name, end - beg);
name[end - beg] = '\0';
expanded_name = allocated_variable_expand (name);
if (expanded_name[0] == '\0')
fatal (flocp, _("empty variable name"));
switch (flavor)
{
case f_bogus:
abort ();
case f_simple:
value = alloc_value = allocated_variable_expand (p);
break;
case f_conditional:
v = lookup_variable(expanded_name, strlen(expanded_name));
if (v)
{
free(expanded_name);
return v;
}
flavor = f_recursive;
case f_recursive:
value = p;
break;
case f_append:
if (target_var)
{
append = 1;
flavor = f_recursive;
value = p;
break;
}
v = lookup_variable (expanded_name, strlen (expanded_name));
if (v == 0)
{
value = p;
flavor = f_recursive;
}
else
{
unsigned int oldlen, newlen;
if (v->recursive)
flavor = f_recursive;
else
p = alloc_value = allocated_variable_expand (p);
oldlen = strlen (v->value);
newlen = strlen (p);
value = (char *) alloca (oldlen + 1 + newlen + 1);
bcopy (v->value, value, oldlen);
value[oldlen] = ' ';
bcopy (p, &value[oldlen + 1], newlen + 1);
}
}
#ifdef __MSDOS__
if ((origin == o_file || origin == o_override)
&& strcmp (expanded_name, "SHELL") == 0)
{
char shellpath[PATH_MAX];
extern char * __dosexec_find_on_path (const char *, char *[], char *);
if (__dosexec_find_on_path (value, (char **)0, shellpath))
{
char *p;
for (p = shellpath; *p; p++)
{
if (*p == '\\')
*p = '/';
}
v = define_variable_loc (expanded_name, strlen (expanded_name),
shellpath, origin, flavor == f_recursive,
flocp);
}
else
{
char *shellbase, *bslash;
struct variable *pathv = lookup_variable ("PATH", 4);
char *path_string;
char *fake_env[2];
size_t pathlen = 0;
shellbase = strrchr (value, '/');
bslash = strrchr (value, '\\');
if (!shellbase || bslash > shellbase)
shellbase = bslash;
if (!shellbase && value[1] == ':')
shellbase = value + 1;
if (shellbase)
shellbase++;
else
shellbase = value;
if (pathv)
pathlen = strlen (pathv->value);
path_string = (char *)xmalloc (5 + pathlen + 2 + 1);
sprintf (path_string, "PATH=.;%s", pathv ? pathv->value : "");
fake_env[0] = path_string;
fake_env[1] = (char *)0;
if (__dosexec_find_on_path (shellbase, fake_env, shellpath))
{
char *p;
for (p = shellpath; *p; p++)
{
if (*p == '\\')
*p = '/';
}
v = define_variable_loc (expanded_name, strlen (expanded_name),
shellpath, origin,
flavor == f_recursive, flocp);
}
else
v = lookup_variable (expanded_name, strlen (expanded_name));
free (path_string);
}
}
else
#endif
#ifdef WINDOWS32
if ((origin == o_file || origin == o_override)
&& strcmp (expanded_name, "SHELL") == 0) {
extern char* default_shell;
if (find_and_set_default_shell(value)) {
v = define_variable_loc (expanded_name, strlen (expanded_name),
default_shell, origin, flavor == f_recursive,
flocp);
no_default_sh_exe = 0;
}
} else
#endif
v = define_variable_loc (expanded_name, strlen (expanded_name), value,
origin, flavor == f_recursive, flocp);
v->append = append;
if (alloc_value)
free (alloc_value);
free (expanded_name);
return v;
}
static void
print_variable (v, prefix)
register struct variable *v;
char *prefix;
{
const char *origin;
switch (v->origin)
{
case o_default:
origin = _("default");
break;
case o_env:
origin = _("environment");
break;
case o_file:
origin = _("makefile");
break;
case o_env_override:
origin = _("environment under -e");
break;
case o_command:
origin = _("command line");
break;
case o_override:
origin = _("`override' directive");
break;
case o_automatic:
origin = _("automatic");
break;
case o_invalid:
default:
abort ();
}
fputs ("# ", stdout);
fputs (origin, stdout);
if (v->fileinfo.filenm)
printf (" (from `%s', line %lu)", v->fileinfo.filenm, v->fileinfo.lineno);
putchar ('\n');
fputs (prefix, stdout);
if (v->recursive && strchr (v->value, '\n') != 0)
printf ("define %s\n%s\nendef\n", v->name, v->value);
else
{
register char *p;
printf ("%s %s= ", v->name, v->recursive ? v->append ? "+" : "" : ":");
p = next_token (v->value);
if (p != v->value && *p == '\0')
printf ("$(subst ,,%s)", v->value);
else if (v->recursive)
fputs (v->value, stdout);
else
for (p = v->value; *p != '\0'; ++p)
{
if (*p == '$')
putchar ('$');
putchar (*p);
}
putchar ('\n');
}
}
void
print_variable_set (set, prefix)
register struct variable_set *set;
char *prefix;
{
register unsigned int i, nvariables, per_bucket;
register struct variable *v;
per_bucket = nvariables = 0;
for (i = 0; i < set->buckets; ++i)
{
register unsigned int this_bucket = 0;
for (v = set->table[i]; v != 0; v = v->next)
{
++this_bucket;
print_variable (v, prefix);
}
nvariables += this_bucket;
if (this_bucket > per_bucket)
per_bucket = this_bucket;
}
if (nvariables == 0)
puts (_("# No variables."));
else
{
printf (_("# %u variables in %u hash buckets.\n"),
nvariables, set->buckets);
#ifndef NO_FLOAT
printf (_("# average of %.1f variables per bucket, \
max %u in one bucket.\n"),
(double) nvariables / (double) set->buckets,
per_bucket);
#else
{
int f = (nvariables * 1000 + 5) / set->buckets;
printf (_("# average of %d.%d variables per bucket, \
max %u in one bucket.\n"),
f/10, f%10,
per_bucket);
}
#endif
}
}
void
print_variable_data_base ()
{
puts (_("\n# Variables\n"));
print_variable_set (&global_variable_set, "");
}
void
print_file_variables (file)
struct file *file;
{
if (file->variables != 0)
print_variable_set (file->variables->set, "# ");
}
#ifdef WINDOWS32
void
sync_Path_environment(void)
{
char* path = allocated_variable_expand("$(Path)");
static char* environ_path = NULL;
if (!path)
return;
if (environ_path)
free(environ_path);
convert_Path_to_windows32(path, ';');
environ_path = concat("Path", "=", path);
putenv(environ_path);
free(path);
}
#endif