You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gentoo-overlay/sys-devel/make/files/make-3.80-conditional-eval....

158 lines
4.0 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

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;