summaryrefslogtreecommitdiff
blob: f4c1581f316ffb6de5884e4703f8deba1101cce3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
Fix from upstream

https://savannah.gnu.org/bugs/index.php?func=detailitem&item_id=1516
http://bugs.gentoo.org/123317

Index: read.c
===================================================================
RCS file: /cvsroot/make/make/read.c,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -p -r1.124 -r1.125
--- read.c	14 Oct 2002 21:54:04 -0000	1.124
+++ read.c	25 Oct 2002 22:01:47 -0000	1.125
@@ -272,6 +272,34 @@ read_all_makefiles (char **makefiles)
   return read_makefiles;
 }
 
+/* Install a new conditional and return the previous one.  */
+
+static struct conditionals *
+install_conditionals (struct conditionals *new)
+{
+  struct conditionals *save = conditionals;
+
+  bzero ((char *) new, sizeof (*new));
+  conditionals = new;
+
+  return save;
+}
+
+/* Free the current conditionals and reinstate a saved one.  */
+
+static void
+restore_conditionals (struct conditionals *saved)
+{
+  /* Free any space allocated by conditional_line.  */
+  if (conditionals->ignoring)
+    free (conditionals->ignoring);
+  if (conditionals->seen_else)
+    free (conditionals->seen_else);
+
+  /* Restore state.  */
+  conditionals = saved;
+}
+
 static int
 eval_makefile (char *filename, int flags)
 {
@@ -388,6 +416,8 @@ int
 eval_buffer (char *buffer)
 {
   struct ebuffer ebuf;
+  struct conditionals *saved;
+  struct conditionals new;
   const struct floc *curfile;
   int r;
 
@@ -402,8 +432,12 @@ eval_buffer (char *buffer)
   curfile = reading_file;
   reading_file = &ebuf.floc;
 
+  saved = install_conditionals (&new);
+
   r = eval (&ebuf, 1);
 
+  restore_conditionals (saved);
+
   reading_file = curfile;
 
   return r;
@@ -412,13 +446,8 @@ eval_buffer (char *buffer)
 
 /* Read file FILENAME as a makefile and add its contents to the data base.
 
-   SET_DEFAULT is true if we are allowed to set the default goal.
+   SET_DEFAULT is true if we are allowed to set the default goal.  */
 
-   FILENAME is added to the `read_makefiles' chain.
-
-   Returns 0 if a file was not found or not read.
-   Returns 1 if FILENAME was found and read.
-   Returns 2 if FILENAME was read, and we kept a reference (don't free it).  */
 
 static int
 eval (struct ebuffer *ebuf, int set_default)
@@ -782,9 +811,7 @@ eval (struct ebuffer *ebuf, int set_defa
 
 	  /* Save the state of conditionals and start
 	     the included makefile with a clean slate.  */
-	  save = conditionals;
-	  bzero ((char *) &new_conditionals, sizeof new_conditionals);
-	  conditionals = &new_conditionals;
+	  save = install_conditionals (&new_conditionals);
 
 	  /* Record the rules that are waiting so they will determine
 	     the default goal before those in the included makefile.  */
@@ -810,14 +837,8 @@ eval (struct ebuffer *ebuf, int set_defa
                 }
 	    }
 
-	  /* Free any space allocated by conditional_line.  */
-	  if (conditionals->ignoring)
-	    free (conditionals->ignoring);
-	  if (conditionals->seen_else)
-	    free (conditionals->seen_else);
-
-	  /* Restore state.  */
-	  conditionals = save;
+	  /* Restore conditional state.  */
+	  restore_conditionals (save);
 
           goto rule_complete;
 	}
Index: tests/scripts/functions/eval
===================================================================
RCS file: /cvsroot/make/make/tests/scripts/functions/eval,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -p -r1.1 -r1.2
--- tests/scripts/functions/eval	8 Jul 2002 02:26:48 -0000	1.1
+++ tests/scripts/functions/eval	25 Oct 2002 22:01:47 -0000	1.2
@@ -57,4 +57,35 @@ $answer = "A = A B = B\n";
 
 &compare_output($answer,&get_logfile(1));
 
+# Test to make sure eval'ing inside conditionals works properly
+
+$makefile3 = &get_tmpfile;
+
+open(MAKEFILE,"> $makefile3");
+
+print MAKEFILE <<'EOF';
+FOO = foo
+
+all:: ; @echo it
+
+define Y
+  all:: ; @echo worked
+endef
+
+ifdef BAR
+$(eval $(Y))
+endif
+
+EOF
+
+close(MAKEFILE);
+
+&run_make_with_options($makefile3, "", &get_logfile);
+$answer = "it\n";
+&compare_output($answer,&get_logfile(1));
+
+&run_make_with_options($makefile3, "BAR=1", &get_logfile);
+$answer = "it\nworked\n";
+&compare_output($answer,&get_logfile(1));
+
 1;