From 6ff61909a91edf3f31adc608dcafd3f5f8e642d0 Mon Sep 17 00:00:00 2001 From: David Griffith Date: Sun, 20 Oct 2019 17:14:48 -0700 Subject: [PATCH] Deal with Makefile conditional assignment operators. Ordinarily variable assignments in Makefiles are done simply with an unconditional assignment: the equals sign. There are variants of this: FOO := $(BAR) Avoid recursively expand variables. FOO ?= bar Assign only if $(FOO) is not already set. FOO += bar Add more to a variable. FOO != bar Execute a shell script and assign result to $(FOO). See also https://www.gnu.org/software/make/manual/html_node/Conditional-Example.html https://www.gnu.org/software/make/manual/html_node/Flavors.html --- Library/Homebrew/extend/string.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb index 32588be9a2780..e25367c92699c 100644 --- a/Library/Homebrew/extend/string.rb +++ b/Library/Homebrew/extend/string.rb @@ -41,7 +41,7 @@ def gsub!(before, after, audit_result = true) # Looks for Makefile style variable definitions and replaces the # value with "new_value", or removes the definition entirely. def change_make_var!(flag, new_value) - return if gsub!(/^#{Regexp.escape(flag)}[ \t]*=[ \t]*(.*)$/, "#{flag}=#{new_value}", false) + return if gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?\+\:\!]?=[ \t]*(.*)$/, "#{flag}=#{new_value}", false) errors << "expected to change #{flag.inspect} to #{new_value.inspect}" end @@ -50,12 +50,14 @@ def change_make_var!(flag, new_value) def remove_make_var!(flags) Array(flags).each do |flag| # Also remove trailing \n, if present. - errors << "expected to remove #{flag.inspect}" unless gsub!(/^#{Regexp.escape(flag)}[ \t]*=.*$\n?/, "", false) + if gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?\+\:\!]?=.*$\n?/, "", false) + errors << "expected to remove #{flag.inspect}" + end end end # Finds the specified variable def get_make_var(flag) - self[/^#{Regexp.escape(flag)}[ \t]*=[ \t]*(.*)$/, 1] + self[/^#{Regexp.escape(flag)}[ \t]*[\\?\+\:\!]?=[ \t]*(.*)$/, 1] end end