make-3.80-conditional-eval.patch 4.0 KB

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