Replace target_var boolean with enum variable_scope

Replace the target_var boolean with an enum to distinguish between
global, target-specific, and pattern-specific variables when defining.

* src/variable.h (enum variable_scope): Introduce enum variable_scope.
Replace parameter target_var of type int with enum variable_scope.
* src/load.c (load_file): Ditto.
* src/main.c (handle_non_switch_argument): Ditto.
* src/read.c (eval_makefile): Ditto.
(eval): Ditto.
(do_define): Ditto.
(record_target_var): Ditto.
(construct_include_path): Ditto.
* src/variable.c (initialize_file_variables): Ditto.
(shell_result): Ditto.
(try_variable_definition): Ditto.
(do_variable_definition): Ditto.
diff --git a/src/load.c b/src/load.c
index 626c34f..8fb5d3a 100644
--- a/src/load.c
+++ b/src/load.c
@@ -230,7 +230,8 @@
 
   /* If the load didn't fail, add the file to the .LOADED variable.  */
   if (r)
-    do_variable_definition(flocp, ".LOADED", ldname, o_file, f_append_value, 0, 0);
+    do_variable_definition(flocp, ".LOADED", ldname, o_file, f_append_value, 0,
+                           s_global);
 
   return r;
 }
diff --git a/src/main.c b/src/main.c
index d07f561..99011d9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3011,7 +3011,7 @@
       }
   }
 #endif
-  v = try_variable_definition (0, arg, origin, 0);
+  v = try_variable_definition (0, arg, origin, s_global);
   if (v != 0)
     {
       /* It is indeed a variable definition.  If we don't already have this
diff --git a/src/read.c b/src/read.c
index 069f9c3..0fb783a 100644
--- a/src/read.c
+++ b/src/read.c
@@ -413,7 +413,7 @@
 
   /* Add this makefile to the list. */
   do_variable_definition (&ebuf.floc, "MAKEFILE_LIST", filename, o_file,
-                          f_append_value, 0, 0);
+                          f_append_value, 0, s_global);
 
   /* Evaluate the makefile */
 
@@ -740,7 +740,7 @@
           if (vmod.define_v)
             v = do_define (p, origin, ebuf);
           else
-            v = try_variable_definition (fstart, p, origin, 0);
+            v = try_variable_definition (fstart, p, origin, s_global);
 
           assert (v != NULL);
 
@@ -1483,8 +1483,8 @@
   else
     definition[idx - 1] = '\0';
 
-  v = do_variable_definition (&defstart, name, definition,
-                              origin, var.flavor, var.conditional, 0);
+  v = do_variable_definition (&defstart, name, definition, origin, var.flavor,
+                              var.conditional, s_global);
   free (definition);
   free (n);
   return (v);
@@ -1822,7 +1822,7 @@
           initialize_file_variables (f, 1);
 
           current_variable_set_list = f->variables;
-          v = try_variable_definition (flocp, defn, origin, 1);
+          v = try_variable_definition (flocp, defn, origin, s_target);
           if (!v)
             O (fatal, flocp, _("malformed target-specific variable definition"));
           current_variable_set_list = global;
@@ -2957,10 +2957,11 @@
 
   /* Now add each dir to the .INCLUDE_DIRS variable.  */
 
-  do_variable_definition (NILF, ".INCLUDE_DIRS", "", o_default, f_simple, 0, 0);
+  do_variable_definition (NILF, ".INCLUDE_DIRS", "", o_default, f_simple, 0,
+                          s_global);
   for (cpp = dirs; *cpp != 0; ++cpp)
-    do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp,
-                            o_default, f_append, 0, 0);
+    do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp, o_default, f_append,
+                            0, s_global);
 
   free ((void *) include_directories);
   include_directories = dirs;
diff --git a/src/variable.c b/src/variable.c
index 5cd28bf..9d44cd4 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -706,9 +706,9 @@
               else
                 {
                   v = do_variable_definition (
-                    &p->variable.fileinfo, p->variable.name,
-                    p->variable.value, p->variable.origin,
-                    p->variable.flavor, p->variable.conditional, 1);
+                    &p->variable.fileinfo, p->variable.name, p->variable.value,
+                    p->variable.origin, p->variable.flavor,
+                    p->variable.conditional, s_pattern);
                 }
 
               /* Also mark it as a per-target and copy export status. */
@@ -1372,7 +1372,7 @@
 struct variable *
 do_variable_definition (const floc *flocp, const char *varname, const char *value,
                         enum variable_origin origin, enum variable_flavor flavor,
-                        int conditional, int target_var)
+                        int conditional, enum variable_scope scope)
 {
   const char *newval;
   char *alloc_value = NULL;
@@ -1438,7 +1438,7 @@
       {
         /* If we have += but we're in a target variable context, we want to
            append only with other variables in the context of this target.  */
-        if (target_var)
+        if (scope)
           {
             append = 1;
             v = lookup_variable_in_set (varname, strlen (varname),
@@ -1615,7 +1615,7 @@
         {
           v = define_variable_in_set (varname, strlen (varname), default_shell,
                                       origin, flavor == f_recursive,
-                                      (target_var
+                                      (specificity
                                        ? current_variable_set_list->set
                                        : NULL),
                                       flocp);
@@ -1631,7 +1631,7 @@
             {
               v = define_variable_in_set (varname, strlen (varname), newval,
                                           origin, flavor == f_recursive,
-                                          (target_var
+                                          (specificity
                                            ? current_variable_set_list->set
                                            : NULL),
                                           flocp);
@@ -1659,8 +1659,8 @@
 
   v = define_variable_in_set (varname, strlen (varname), newval, origin,
                               flavor == f_recursive || flavor == f_expand,
-                              (target_var
-                               ? current_variable_set_list->set : NULL),
+                              (scope == s_global
+                               ? NULL : current_variable_set_list->set),
                               flocp);
   v->append = append;
   v->conditional = conditional;
@@ -1850,7 +1850,7 @@
 
 struct variable *
 try_variable_definition (const floc *flocp, const char *line,
-                         enum variable_origin origin, int target_var)
+                         enum variable_origin origin, enum variable_scope scope)
 {
   struct variable v;
   struct variable *vp;
@@ -1863,8 +1863,8 @@
   if (!assign_variable_definition (&v, line))
     return 0;
 
-  vp = do_variable_definition (flocp, v.name, v.value,
-                               origin, v.flavor, v.conditional, target_var);
+  vp = do_variable_definition (flocp, v.name, v.value, origin, v.flavor,
+                               v.conditional, scope);
 
   free (v.name);
 
diff --git a/src/variable.h b/src/variable.h
index 0b84c2e..f6f0cb3 100644
--- a/src/variable.h
+++ b/src/variable.h
@@ -51,6 +51,13 @@
     v_ifset             /* Export it if it has a non-default value.  */
 };
 
+enum variable_scope
+{
+    s_global = 0,       /* Global variable.  */
+    s_target,           /* Target-specific variable.  */
+    s_pattern           /* Pattern-specific variable.  */
+};
+
 /* Structure that represents one variable definition.
    Each bucket of the hash table is a chain of these,
    chained through 'next'.  */
@@ -171,13 +178,14 @@
                                          const char *name, const char *value,
                                          enum variable_origin origin,
                                          enum variable_flavor flavor,
-                                         int conditional, int target_var);
+                                         int conditional,
+                                         enum variable_scope scope);
 char *parse_variable_definition (const char *line,
                                  struct variable *v);
 struct variable *assign_variable_definition (struct variable *v, const char *line);
 struct variable *try_variable_definition (const floc *flocp, const char *line,
                                           enum variable_origin origin,
-                                          int target_var);
+                                          enum variable_scope scope);
 void init_hash_global_variable_set (void);
 void hash_init_function_table (void);
 void define_new_function(const floc *flocp, const char *name,