commit 9186a2894d604260402e2efe4260ed91a6d78874
Author: Dmitry Goncharov <dgoncharov@users.sf.net>
Date:   Sat Jan 20 11:06:06 2024 -0500

    Introduce enum variable_specificity.
    
    variable_specificity will be used in the next commit to tell a
    pattern-specific append apart from a target-specific append in
    do_variable_definition.
    
    * src/variable.h (enum variable_specificity): Introduce enum
    variable_specificity.
    Replace parameter target_var of type int with variable_specificity.
    * 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 ab55feaf..00744d49 100644
--- a/src/load.c
+++ b/src/load.c
@@ -230,7 +230,8 @@ load_file (const floc *flocp, struct file *file, int noerror)
 
   /* 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);
+    do_variable_definition(flocp, ".LOADED", ldname, o_file, f_append_value,
+                           s_global);
 
   return r;
 }
diff --git a/src/main.c b/src/main.c
index 85aa71cf..39be3509 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3084,7 +3084,7 @@ handle_non_switch_argument (const char *arg, enum variable_origin origin)
       }
   }
 #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 6748486e..7c1c64bc 100644
--- a/src/read.c
+++ b/src/read.c
@@ -413,7 +413,7 @@ eval_makefile (const char *filename, unsigned short flags)
 
   /* Add this makefile to the list. */
   do_variable_definition (&ebuf.floc, "MAKEFILE_LIST", filename, o_file,
-                          f_append_value, 0);
+                          f_append_value, s_global);
 
   /* Evaluate the makefile */
 
@@ -740,7 +740,7 @@ eval (struct ebuffer *ebuf, int set_default)
           else 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);
 
@@ -1481,7 +1481,7 @@ do_define (char *name, enum variable_origin origin, struct ebuffer *ebuf)
     definition[idx - 1] = '\0';
 
   v = do_variable_definition (&defstart, name,
-                              definition, origin, var.flavor, 0);
+                              definition, origin, var.flavor, s_global);
   free (definition);
   free (n);
   return (v);
@@ -1828,7 +1828,7 @@ record_target_var (struct nameseq *filenames, char *defn,
           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;
@@ -3048,10 +3048,10 @@ construct_include_path (const char **arg_dirs)
 
   /* Now add each dir to the .INCLUDE_DIRS variable.  */
 
-  do_variable_definition (NILF, ".INCLUDE_DIRS", "", o_default, f_simple, 0);
+  do_variable_definition (NILF, ".INCLUDE_DIRS", "", o_default, f_simple, s_global);
   for (cpp = dirs; *cpp != 0; ++cpp)
     do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp,
-                            o_default, f_append, 0);
+                            o_default, f_append, s_global);
 
   free ((void *) include_directories);
   include_directories = dirs;
diff --git a/src/variable.c b/src/variable.c
index 63a8968b..4274104b 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -708,7 +708,7 @@ initialize_file_variables (struct file *file, int reading)
                   v = do_variable_definition (
                     &p->variable.fileinfo, p->variable.name,
                     p->variable.value, p->variable.origin,
-                    p->variable.flavor, 1);
+                    p->variable.flavor, s_pattern);
                 }
 
               /* Also mark it as a per-target and copy export status. */
@@ -1372,7 +1372,8 @@ shell_result (const char *p)
 struct variable *
 do_variable_definition (const floc *flocp, const char *varname,
                         const char *value, enum variable_origin origin,
-                        enum variable_flavor flavor, int target_var)
+                        enum variable_flavor flavor,
+                        enum variable_specificity specificity)
 {
   const char *newval;
   char *alloc_value = NULL;
@@ -1441,7 +1442,7 @@ do_variable_definition (const floc *flocp, const char *varname,
       {
         /* 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 (specificity)
           {
             append = 1;
             v = lookup_variable_in_set (varname, strlen (varname),
@@ -1618,7 +1619,7 @@ do_variable_definition (const floc *flocp, const char *varname,
         {
           v = define_variable_in_set (varname, strlen (varname), default_shell,
                                       origin, flavor == f_recursive,
-                                      (target_var
+                                      (specificity
                                        ? current_variable_set_list->set
                                        : NULL),
                                       flocp);
@@ -1634,7 +1635,7 @@ do_variable_definition (const floc *flocp, const char *varname,
             {
               v = define_variable_in_set (varname, strlen (varname), newval,
                                           origin, flavor == f_recursive,
-                                          (target_var
+                                          (specificity
                                            ? current_variable_set_list->set
                                            : NULL),
                                           flocp);
@@ -1662,7 +1663,7 @@ do_variable_definition (const floc *flocp, const char *varname,
 
   v = define_variable_in_set (varname, strlen (varname), newval, origin,
                               flavor == f_recursive || flavor == f_expand,
-                              (target_var
+                              (specificity
                                ? current_variable_set_list->set : NULL),
                               flocp);
   v->append = append;
@@ -1874,7 +1875,8 @@ 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_origin origin,
+                         enum variable_specificity specificity)
 {
   struct variable v;
   struct variable *vp;
@@ -1888,7 +1890,7 @@ try_variable_definition (const floc *flocp, const char *line,
     return 0;
 
   vp = do_variable_definition (flocp, v.name, v.value,
-                               origin, v.flavor, target_var);
+                               origin, v.flavor, specificity);
 
   free (v.name);
 
diff --git a/src/variable.h b/src/variable.h
index ade57531..a783152c 100644
--- a/src/variable.h
+++ b/src/variable.h
@@ -52,6 +52,13 @@ enum variable_export
     v_ifset             /* Export it if it has a non-default value.  */
 };
 
+enum variable_specificity
+{
+    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'.  */
@@ -172,13 +179,13 @@ struct variable *do_variable_definition (const floc *flocp,
                                          const char *name, const char *value,
                                          enum variable_origin origin,
                                          enum variable_flavor flavor,
-                                         int target_var);
+                                         enum variable_specificity specificity);
 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_specificity specificity);
 void init_hash_global_variable_set (void);
 void hash_init_function_table (void);
 void define_new_function(const floc *flocp, const char *name,
