|
Line 0
Link Here
|
|
|
1 |
Index: read.c |
| 2 |
=================================================================== |
| 3 |
RCS file: /cvsroot/make/make/read.c,v |
| 4 |
retrieving revision 1.124 |
| 5 |
diff -u -B -b -r1.124 read.c |
| 6 |
--- read.c 14 Oct 2002 21:54:04 -0000 1.124 |
| 7 |
+++ read.c 25 Oct 2002 21:17:42 -0000 |
| 8 |
@@ -272,6 +272,34 @@ |
| 9 |
return read_makefiles; |
| 10 |
} |
| 11 |
|
| 12 |
+/* Install a new conditional and return the previous one. */ |
| 13 |
+ |
| 14 |
+static struct conditionals * |
| 15 |
+install_conditionals (struct conditionals *new) |
| 16 |
+{ |
| 17 |
+ struct conditionals *save = conditionals; |
| 18 |
+ |
| 19 |
+ bzero ((char *) new, sizeof (*new)); |
| 20 |
+ conditionals = new; |
| 21 |
+ |
| 22 |
+ return save; |
| 23 |
+} |
| 24 |
+ |
| 25 |
+/* Free the current conditionals and reinstate a saved one. */ |
| 26 |
+ |
| 27 |
+static void |
| 28 |
+restore_conditionals (struct conditionals *saved) |
| 29 |
+{ |
| 30 |
+ /* Free any space allocated by conditional_line. */ |
| 31 |
+ if (conditionals->ignoring) |
| 32 |
+ free (conditionals->ignoring); |
| 33 |
+ if (conditionals->seen_else) |
| 34 |
+ free (conditionals->seen_else); |
| 35 |
+ |
| 36 |
+ /* Restore state. */ |
| 37 |
+ conditionals = saved; |
| 38 |
+} |
| 39 |
+ |
| 40 |
static int |
| 41 |
eval_makefile (char *filename, int flags) |
| 42 |
{ |
| 43 |
@@ -388,6 +416,8 @@ |
| 44 |
eval_buffer (char *buffer) |
| 45 |
{ |
| 46 |
struct ebuffer ebuf; |
| 47 |
+ struct conditionals *saved; |
| 48 |
+ struct conditionals new; |
| 49 |
const struct floc *curfile; |
| 50 |
int r; |
| 51 |
|
| 52 |
@@ -402,8 +432,12 @@ |
| 53 |
curfile = reading_file; |
| 54 |
reading_file = &ebuf.floc; |
| 55 |
|
| 56 |
+ saved = install_conditionals (&new); |
| 57 |
+ |
| 58 |
r = eval (&ebuf, 1); |
| 59 |
|
| 60 |
+ restore_conditionals (saved); |
| 61 |
+ |
| 62 |
reading_file = curfile; |
| 63 |
|
| 64 |
return r; |
| 65 |
@@ -412,13 +446,8 @@ |
| 66 |
|
| 67 |
/* Read file FILENAME as a makefile and add its contents to the data base. |
| 68 |
|
| 69 |
- SET_DEFAULT is true if we are allowed to set the default goal. |
| 70 |
- |
| 71 |
- FILENAME is added to the `read_makefiles' chain. |
| 72 |
+ SET_DEFAULT is true if we are allowed to set the default goal. */ |
| 73 |
|
| 74 |
- Returns 0 if a file was not found or not read. |
| 75 |
- Returns 1 if FILENAME was found and read. |
| 76 |
- Returns 2 if FILENAME was read, and we kept a reference (don't free it). */ |
| 77 |
|
| 78 |
static int |
| 79 |
eval (struct ebuffer *ebuf, int set_default) |
| 80 |
@@ -782,9 +811,7 @@ |
| 81 |
|
| 82 |
/* Save the state of conditionals and start |
| 83 |
the included makefile with a clean slate. */ |
| 84 |
- save = conditionals; |
| 85 |
- bzero ((char *) &new_conditionals, sizeof new_conditionals); |
| 86 |
- conditionals = &new_conditionals; |
| 87 |
+ save = install_conditionals (&new_conditionals); |
| 88 |
|
| 89 |
/* Record the rules that are waiting so they will determine |
| 90 |
the default goal before those in the included makefile. */ |
| 91 |
@@ -810,14 +837,8 @@ |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
- /* Free any space allocated by conditional_line. */ |
| 96 |
- if (conditionals->ignoring) |
| 97 |
- free (conditionals->ignoring); |
| 98 |
- if (conditionals->seen_else) |
| 99 |
- free (conditionals->seen_else); |
| 100 |
- |
| 101 |
- /* Restore state. */ |
| 102 |
- conditionals = save; |
| 103 |
+ /* Restore conditional state. */ |
| 104 |
+ restore_conditionals (save); |
| 105 |
|
| 106 |
goto rule_complete; |
| 107 |
} |
| 108 |
Index: tests/scripts/functions/eval |
| 109 |
=================================================================== |
| 110 |
RCS file: /cvsroot/make/make/tests/scripts/functions/eval,v |
| 111 |
retrieving revision 1.1 |
| 112 |
diff -u -B -b -r1.1 eval |
| 113 |
--- tests/scripts/functions/eval 8 Jul 2002 02:26:48 -0000 1.1 |
| 114 |
+++ tests/scripts/functions/eval 25 Oct 2002 21:17:42 -0000 |
| 115 |
@@ -57,4 +57,35 @@ |
| 116 |
|
| 117 |
&compare_output($answer,&get_logfile(1)); |
| 118 |
|
| 119 |
+# Test to make sure eval'ing inside conditionals works properly |
| 120 |
+ |
| 121 |
+$makefile3 = &get_tmpfile; |
| 122 |
+ |
| 123 |
+open(MAKEFILE,"> $makefile3"); |
| 124 |
+ |
| 125 |
+print MAKEFILE <<'EOF'; |
| 126 |
+FOO = foo |
| 127 |
+ |
| 128 |
+all:: ; @echo it |
| 129 |
+ |
| 130 |
+define Y |
| 131 |
+ all:: ; @echo worked |
| 132 |
+endef |
| 133 |
+ |
| 134 |
+ifdef BAR |
| 135 |
+$(eval $(Y)) |
| 136 |
+endif |
| 137 |
+ |
| 138 |
+EOF |
| 139 |
+ |
| 140 |
+close(MAKEFILE); |
| 141 |
+ |
| 142 |
+&run_make_with_options($makefile3, "", &get_logfile); |
| 143 |
+$answer = "it\n"; |
| 144 |
+&compare_output($answer,&get_logfile(1)); |
| 145 |
+ |
| 146 |
+&run_make_with_options($makefile3, "BAR=1", &get_logfile); |
| 147 |
+$answer = "it\nworked\n"; |
| 148 |
+&compare_output($answer,&get_logfile(1)); |
| 149 |
+ |
| 150 |
1; |